Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dba13606 authored by Alistair Delva's avatar Alistair Delva
Browse files

Revert "um: remove uses of variable length arrays"



This reverts commit 0d4e5ac7.

Reason: Broke UML used by kernel_tests

Bug: 139897923
Change-Id: Ibf57c1f535e60caaef32dd14c4abbe253d8e185d
Signed-off-by: default avatarAlistair Delva <adelva@google.com>
parent ea22c348
Loading
Loading
Loading
Loading
+9 −27
Original line number Diff line number Diff line
@@ -135,18 +135,12 @@ static int remove_files_and_dir(char *dir)
 */
static inline int is_umdir_used(char *dir)
{
	char pid[sizeof("nnnnn\0")], *end, *file;
	char file[strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")];
	char pid[sizeof("nnnnn\0")], *end;
	int dead, fd, p, n, err;
	size_t filelen;

	err = asprintf(&file, "%s/pid", dir);
	if (err < 0)
		return 0;

	filelen = strlen(file);

	n = snprintf(file, filelen, "%s/pid", dir);
	if (n >= filelen) {
	n = snprintf(file, sizeof(file), "%s/pid", dir);
	if (n >= sizeof(file)) {
		printk(UM_KERN_ERR "is_umdir_used - pid filename too long\n");
		err = -E2BIG;
		goto out;
@@ -191,7 +185,6 @@ static inline int is_umdir_used(char *dir)
out_close:
	close(fd);
out:
	free(file);
	return 0;
}

@@ -217,21 +210,18 @@ static int umdir_take_if_dead(char *dir)

static void __init create_pid_file(void)
{
	char pid[sizeof("nnnnn\0")], *file;
	char file[strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")];
	char pid[sizeof("nnnnn\0")];
	int fd, n;

	file = malloc(strlen(uml_dir) + UMID_LEN + sizeof("/pid\0"));
	if (!file)
		return;

	if (umid_file_name("pid", file, sizeof(file)))
		goto out;
		return;

	fd = open(file, O_RDWR | O_CREAT | O_EXCL, 0644);
	if (fd < 0) {
		printk(UM_KERN_ERR "Open of machine pid file \"%s\" failed: "
		       "%s\n", file, strerror(errno));
		goto out;
		return;
	}

	snprintf(pid, sizeof(pid), "%d\n", getpid());
@@ -241,8 +231,6 @@ static void __init create_pid_file(void)
		       errno);

	close(fd);
out:
	free(file);
}

int __init set_umid(char *name)
@@ -397,19 +385,13 @@ __uml_setup("uml_dir=", set_uml_dir,

static void remove_umid_dir(void)
{
	char *dir, err;

	dir = malloc(strlen(uml_dir) + UMID_LEN + 1);
	if (!dir)
		return;
	char dir[strlen(uml_dir) + UMID_LEN + 1], err;

	sprintf(dir, "%s%s", uml_dir, umid);
	err = remove_files_and_dir(dir);
	if (err)
		os_warn("%s - remove_files_and_dir failed with err = %d\n",
			__func__, err);

	free(dir);
}

__uml_exitcall(remove_umid_dir);