Exemplo n.º 1
0
static int execute_start(struct lxc_handler *handler, void* data)
{
	int j, i = 0;
	struct execute_args *my_args = data;
	char **argv;
	int argc = 0, argc_add;
	char *initpath;

	while (my_args->argv[argc++]);

	argc_add = 4;
	if (my_args->quiet)
		argc_add++;
	if (!handler->conf->rootfs.path) {
		argc_add += 4;
		if (lxc_log_has_valid_level())
			argc_add += 2;
	}

	argv = malloc((argc + argc_add) * sizeof(*argv));
	if (!argv)
		goto out1;

	initpath = choose_init();
	if (!initpath) {
		ERROR("Failed to find an lxc-init");
		goto out2;
	}
	argv[i++] = initpath;
	if (my_args->quiet)
		argv[i++] = "--quiet";
	if (!handler->conf->rootfs.path) {
		argv[i++] = "--name";
		argv[i++] = (char *)handler->name;
		argv[i++] = "--lxcpath";
		argv[i++] = (char *)handler->lxcpath;

		if (lxc_log_has_valid_level()) {
			argv[i++] = "--logpriority";
			argv[i++] = (char *)
				lxc_log_priority_to_string(lxc_log_get_level());
		}
	}
	argv[i++] = "--";
	for (j = 0; j < argc; j++)
		argv[i++] = my_args->argv[j];
	argv[i++] = NULL;

	NOTICE("exec'ing '%s'", my_args->argv[0]);

	execvp(argv[0], argv);
	SYSERROR("failed to exec %s", argv[0]);
	free(initpath);
out2:
	free(argv);
out1:
	return 1;
}
Exemplo n.º 2
0
Arquivo: execute.c Projeto: hallyn/lxc
static int execute_start(struct lxc_handler *handler, void* data)
{
	int j, i = 0;
	struct execute_args *my_args = data;
	char **argv;
	int argc = 0, argc_add;
	char *initpath;

	while (my_args->argv[argc++]);

	/* lxc-init -n name -- [argc] NULL -> 5 */
	argc_add = 5;
	if (my_args->quiet)
		argc_add++;
	if (!handler->conf->rootfs.path)
		argc_add += 2;
	if (lxc_log_has_valid_level())
		argc_add += 2;

	argv = malloc((argc + argc_add) * sizeof(*argv));
	if (!argv)
		goto out1;

	initpath = choose_init(NULL);
	if (!initpath) {
		ERROR("Failed to find an init.lxc or init.lxc.static");
		goto out2;
	}
	argv[i++] = initpath;

	argv[i++] = "-n";
	argv[i++] = (char *)handler->name;

	if (lxc_log_has_valid_level()) {
		argv[i++] = "-l";
		argv[i++] = (char *)lxc_log_priority_to_string(lxc_log_get_level());
	}

	if (handler->conf->logfile) {
		argv[i++] = "-o";
		argv[i++] = (char *)handler->conf->logfile;
	}

	if (my_args->quiet)
		argv[i++] = "--quiet";

	if (!handler->conf->rootfs.path) {
		argv[i++] = "-P";
		argv[i++] = (char *)handler->lxcpath;
	}

	argv[i++] = "--";
	for (j = 0; j < argc; j++)
		argv[i++] = my_args->argv[j];
	argv[i++] = NULL;

	NOTICE("Exec'ing \"%s\"", my_args->argv[0]);

	execvp(argv[0], argv);
	SYSERROR("Failed to exec %s", argv[0]);
	free(initpath);
out2:
	free(argv);
out1:
	return 1;
}