/** Allocate and initialize CT handler. * * @param veid CT ID. * @return handler or NULL on error. */ vps_handler *vz_open(envid_t veid) { int vzfd, stdfd; vps_handler *h = NULL; stdfd = reset_std(); if ((vzfd = open(VZCTLDEV, O_RDWR)) < 0) { logger(-1, errno, "Unable to open %s", VZCTLDEV); logger(-1, 0, "Please check that vzdev kernel module is loaded" " and you have sufficient permissions" " to access the file."); goto err; } h = calloc(1, sizeof(*h)); if (h == NULL) goto err; h->vzfd = vzfd; h->stdfd = stdfd; if (vz_env_create_ioctl(h, 0, 0) < 0 && (errno == ENOSYS || errno == EPERM)) { logger(-1, 0, "Your kernel lacks support for virtual" " environments or modules not loaded"); goto err; } return h; err: free(h); if (vzfd != -1) close(vzfd); if (stdfd != -1) close(stdfd); return NULL; }
/** Allocate and initialize CT handler. * * @param veid CT ID. * @param param CT parameters. * @return handler or NULL on error. */ vps_handler *vz_open(envid_t veid, vps_param *param) { vps_handler *h = NULL; int ret = -1; h = calloc(1, sizeof(*h)); if (h == NULL) return NULL; h->stdfd = reset_std(); #ifdef VZ_KERNEL_SUPPORTED /* Find out if we are under OpenVZ or upstream kernel */ if (stat_file("/proc/vz") == 1) ret = vz_do_open(h, param); else #endif { logger(0, 0, "Directory /proc/vz not found, assuming " "non-OpenVZ kernel"); h->vzfd = -1; #ifdef HAVE_UPSTREAM ret = ct_do_open(h, param); #else logger(-1, 0, "No suitable kernel support compiled in"); #endif } if (!ret) return h; if (h->stdfd != -1) close(h->stdfd); free(h); return NULL; }