Example #1
0
File: env.c Project: funtoo/vzctl
static int vz_env_create_data_ioctl(vps_handler *h,
                                    struct vzctl_env_create_data *data)
{
    int errcode;
    int retry = 0;

    do {
        if (retry)
            sleep(1);
        errcode = ioctl(h->vzfd, VZCTL_ENV_CREATE_DATA, data);
    } while (errcode < 0 && errno == EBUSY && retry++ < ENVRETRY);

    if (errcode >= 0) {
        /* Clear supplementary group IDs */
        setgroups(0, NULL);
#ifdef  __x86_64__
        /* Set personality PER_LINUX32 for i386 based CTs */
        set_personality32();
#endif
    }
    return errcode;
}
Example #2
0
int vz_env_create_ioctl(int vzfd, envid_t veid, int flags)
{
	struct vzctl_env_create env_create;
	int errcode;
	int retry = 0;

	memset(&env_create, 0, sizeof(env_create));
	env_create.veid = veid;
	env_create.flags = flags;
	do {
		if (retry)
			sleep(1);
		errcode = ioctl(vzfd, VZCTL_ENV_CREATE, &env_create);
	} while (errcode < 0 && errno == EBUSY && retry++ < ENVRETRY);
	if (errcode >= 0 && (flags & VE_ENTER)) {
		/* Clear supplementary group IDs */
		setgroups(0, NULL);
#ifdef  __x86_64__
		/* Set personality PER_LINUX32 for i386 based CTs */
		set_personality32();
#endif
	}
	return errcode;
}
Example #3
0
int exec_container_init(struct arg_start *arg,
			struct env_create_param3 *create_param)
{
	int fd, ret;
	char *argv[] = {"init", "-z", "      ", NULL};
	char *envp[] = {"HOME=/", "TERM=linux", NULL};
	struct statfs sfs;

	/* Clear supplementary group IDs */
	setgroups(0, NULL);
	/* for 32-bit userspace running over 64-bit kernels */
	set_personality32();

	/* Create /fastboot to skip run fsck */
	fd = open("/fastboot", O_CREAT | O_RDONLY, 0644);
	if (fd >= 0)
		close(fd);

	if (arg->res->misc.wait == YES) {
		if (add_reach_runlevel_mark()) {
			ret = VZ_WAIT_FAILED;
			return -1;
		}
	}

	if (mkdir("/proc", 0555) && errno != EEXIST)
		return vzctl_err(VZ_SYSTEM_ERROR, errno,
				"Can't mkdir /proc");

	if (statfs("/proc", &sfs))
		return vzctl_err(VZ_SYSTEM_ERROR, errno,
				"statfs on /proc failed");

	if (sfs.f_type != PROC_SUPER_MAGIC &&
	    mount("proc", "/proc", "proc", 0, 0))
		return vzctl_err(VZ_SYSTEM_ERROR, errno,
				"Failed to mount /proc");

	if (stat_file("/sys") == 1)
		mount("sysfs", "/sys", "sysfs", 0, 0);

	if (create_param->feature_mask & VE_FEATURE_NFSD) {
		mount("nfsd", "/proc/fs/nfsd", "nfsd", 0, 0);
		make_dir("/var/lib/nfs/rpc_pipefs", 1);
		mount("sunrpc", "/var/lib/nfs/rpc_pipefs", "rpc_pipefs", 0, 0);
	}
	write_val("/proc/sys/net/ipv6/conf/all/forwarding", "0");

	/* Close status descriptor to report that
	 * environment is created.
	*/
	close(STDIN_FILENO);
	/* Now we wait until CT setup will be done
	   If no error, then start init, otherwise exit.
	*/

	if (read(arg->wait_p, &ret, sizeof(ret)) == 0)
		return -1;

	if ((fd = open("/dev/null", O_RDWR)) != -1) {
		dup2(fd, 0);
		dup2(fd, 1);
		dup2(fd, 2);
		close(fd);
	}

	logger(10, 0, "Starting init");

	close_fds(0, arg->err_p, -1);

	execve("/sbin/init", argv, envp);
	execve("/etc/init", argv, envp);
	execve("/bin/init", argv, envp);
	ret = VZ_FS_BAD_TMPL;
	write(arg->err_p, &ret, sizeof(ret));
	return ret;
}