int lxc_execute(const char *name, char *const argv[], int quiet, struct lxc_handler *handler, const char *lxcpath, bool backgrounded) { struct execute_args args = {.argv = argv, .quiet = quiet}; if (lxc_check_inherited(handler->conf, false, &handler->conf->maincmd_fd, 1)) return -1; handler->conf->is_execute = 1; return __lxc_start(name, handler, &execute_start_ops, &args, lxcpath, backgrounded); }
int lxc_execute(const char *name, char *const argv[], int quiet, struct lxc_conf *conf, const char *lxcpath) { struct execute_args args = { .argv = argv, .quiet = quiet }; if (lxc_check_inherited(conf, -1)) return -1; conf->is_execute = 1; return __lxc_start(name, conf, &execute_start_ops, &args, lxcpath); }
/* used to spawn a monitord either on startup of a daemon container, or when * lxc-monitor starts */ int lxc_monitord_spawn(const char *lxcpath) { pid_t pid1,pid2; int pipefd[2]; char pipefd_str[11]; char * const args[] = { LXC_MONITORD_PATH, (char *)lxcpath, pipefd_str, NULL, }; /* double fork to avoid zombies when monitord exits */ pid1 = fork(); if (pid1 < 0) { SYSERROR("failed to fork"); return -1; } if (pid1) { if (waitpid(pid1, NULL, 0) != pid1) return -1; return 0; } if (pipe(pipefd) < 0) { SYSERROR("failed to create pipe"); exit(EXIT_FAILURE); } pid2 = fork(); if (pid2 < 0) { SYSERROR("failed to fork"); exit(EXIT_FAILURE); } if (pid2) { char c; /* wait for daemon to create socket */ close(pipefd[1]); /* sync with child, we're ignoring the return from read * because regardless if it works or not, either way we've * synced with the child process. the if-empty-statement * construct is to quiet the warn-unused-result warning. */ if (read(pipefd[0], &c, 1)) ; close(pipefd[0]); exit(EXIT_SUCCESS); } if (setsid() < 0) { SYSERROR("failed to setsid"); exit(EXIT_FAILURE); } lxc_check_inherited(NULL, pipefd[1]); close(0); close(1); close(2); open("/dev/null", O_RDONLY); open("/dev/null", O_RDWR); open("/dev/null", O_RDWR); close(pipefd[0]); sprintf(pipefd_str, "%d", pipefd[1]); execvp(args[0], args); exit(EXIT_FAILURE); }