LOSKIDRV_API int loski_createprocess(loski_Process *proc, const char *binpath, const char *runpath, char *const argvals[], char *const envlist[], FILE *stdin, FILE *stdout, FILE *stderr) { proc->pid = fork(); proc->status = 0; if (proc->pid == -1) return errno; else if (proc->pid > 0) { loski_proctabput(&table, proc); return 0; } /* child process */ int res = 0; if (res == 0 && stdin ) res = stdfile(0, stdin); if (res == 0 && stdout ) res = stdfile(1, stdout); if (res == 0 && stderr ) res = stdfile(2, stderr); if (res == 0 && runpath) res = chdir(runpath); if (res == 0) { int max = sysconf(_SC_OPEN_MAX); if (max > 0) { int i; for (i=3; i<max; ++i) close(i); /* close all open file descriptors */ if (envlist) execvep(binpath, argvals, envlist); else execvp(binpath, argvals); } } _exit(errno); }
static int real_env_stop(vps_handler *h, envid_t veid, const char *vps_root, int stop_mode) { int ret; if ((ret = vz_chroot(vps_root))) return ret; if ((ret = vz_setluid(veid))) return ret; close_fds(1, h->vzfd, -1); if ((ret = vz_env_create_ioctl(h, veid, VE_ENTER)) < 0) { if (errno == ESRCH) return 0; logger(-1, errno, "Container enter failed"); return ret; } close(h->vzfd); switch (stop_mode) { case M_REBOOT: { char *argv[] = {"reboot", NULL}; execvep(argv[0], argv, NULL); break; } case M_HALT: { char *argv[] = {"halt", NULL}; execvep(argv[0], argv, NULL); break; } case M_KILL: { syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_POWER_OFF, NULL); break; } } return 0; }
void pathexec_run (char const *file, char const *const *argv, char const *const *envp) { register char const *path = env_get("PATH") ; if (!path) path = SKALIBS_DEFAULTPATH ; execvep(file, argv, envp, path) ; }
int execlp(const char * file, char * arg0, ...) { return execvep(file,&arg0,environ); }