本文整理汇总了C++中posix_spawnp函数的典型用法代码示例。如果您正苦于以下问题:C++ posix_spawnp函数的具体用法?C++ posix_spawnp怎么用?C++ posix_spawnp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了posix_spawnp函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: launch_thread
void launch_thread(jobtype ptype, pkgstate* state, pkg_exec* item, pkgdata* data) {
char* arr[2];
create_script(ptype, state, item, data);
log_timestamp(1);
log_putspace(1);
if(ptype == JT_DOWNLOAD) {
log_puts(1, SPL("downloading "));
} else
log_puts(1, SPL("building "));
log_put(1, VARIS(item->name), VARISL("("), VARIS(item->scripts.filename), VARISL(") -> "), VARIS(item->scripts.stdoutfn), NULL);
arr[0] = item->scripts.filename->ptr;
arr[1] = NULL;
posix_spawn_file_actions_init(&item->fa);
posix_spawn_file_actions_addclose(&item->fa, 0);
posix_spawn_file_actions_addclose(&item->fa, 1);
posix_spawn_file_actions_addclose(&item->fa, 2);
posix_spawn_file_actions_addopen(&item->fa, 0, "/dev/null", O_RDONLY, 0);
posix_spawn_file_actions_addopen(&item->fa, 1, item->scripts.stdoutfn->ptr, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
posix_spawn_file_actions_adddup2(&item->fa, 1, 2);
int ret = posix_spawnp(&item->pid, arr[0], &item->fa, NULL, arr, environ);
if(ret == -1) {
log_perror("posix_spawn");
die(SPL(""));
}
}
开发者ID:yasar11732,项目名称:butch,代码行数:28,代码来源:butch.c
示例2: main
int main(int argc, char **argv, char **envp) {
aslclient aslc;
pid_t child;
int pstat;
if(argc < 2 || strcmp(argv[1], "--help") == 0) {
fprintf(stderr, "Usage: %s prog [args...]\n", argv[0]);
exit(EXIT_FAILURE);
}
aslc = asl_open(BUNDLE_ID_PREFIX".startx", BUNDLE_ID_PREFIX, ASL_OPT_NO_DELAY);
xi_asl_capture_fd(aslc, NULL, ASL_LEVEL_INFO, STDOUT_FILENO);
xi_asl_capture_fd(aslc, NULL, ASL_LEVEL_NOTICE, STDERR_FILENO);
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
assert(posix_spawnp(&child, argv[1], NULL, NULL, &argv[1], envp) == 0);
#else
switch(child = fork()) {
case -1:
perror("fork");
return errno;
case 0:
return execvp(argv[1], &argv[1]);
default:
break;
}
#endif
wait4(child, &pstat, 0, (struct rusage *)0);
return pstat;
}
开发者ID:Jubei-Mitsuyoshi,项目名称:aaa-stage-1,代码行数:33,代码来源:launchd_startx.c
示例3: TEST
TEST(spawn, posix_spawnp) {
ExecTestHelper eth;
eth.SetArgs({"true", nullptr});
pid_t pid;
ASSERT_EQ(0, posix_spawnp(&pid, eth.GetArg0(), nullptr, nullptr, eth.GetArgs(), nullptr));
AssertChildExited(pid, 0);
}
开发者ID:android,项目名称:platform_bionic,代码行数:7,代码来源:spawn_test.cpp
示例4: spawn_win32
static void spawn_win32(void) {
char module_name[WATCHMAN_NAME_MAX];
GetModuleFileName(NULL, module_name, sizeof(module_name));
char *argv[MAX_DAEMON_ARGS] = {
module_name,
"--foreground",
NULL
};
posix_spawn_file_actions_t actions;
posix_spawnattr_t attr;
pid_t pid;
int i;
for (i = 0; daemon_argv[i]; i++) {
append_argv(argv, daemon_argv[i]);
}
posix_spawnattr_init(&attr);
posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETPGROUP);
posix_spawn_file_actions_init(&actions);
posix_spawn_file_actions_addopen(&actions,
STDIN_FILENO, "/dev/null", O_RDONLY, 0);
posix_spawn_file_actions_addopen(&actions,
STDOUT_FILENO, log_name, O_WRONLY|O_CREAT|O_APPEND, 0600);
posix_spawn_file_actions_adddup2(&actions,
STDOUT_FILENO, STDERR_FILENO);
posix_spawnp(&pid, argv[0], &actions, &attr, argv, environ);
posix_spawnattr_destroy(&attr);
posix_spawn_file_actions_destroy(&actions);
}
开发者ID:Jerry-goodboy,项目名称:watchman,代码行数:30,代码来源:main.c
示例5: spawn_via_gimli
static void spawn_via_gimli(void)
{
char *argv[MAX_DAEMON_ARGS] = {
GIMLI_MONITOR_PATH,
#ifdef WATCHMAN_STATE_DIR
"--trace-dir=" WATCHMAN_STATE_DIR "/traces",
#endif
"--pidfile", pid_file,
"watchman",
"--foreground",
NULL
};
posix_spawn_file_actions_t actions;
posix_spawnattr_t attr;
pid_t pid;
int i;
for (i = 0; daemon_argv[i]; i++) {
append_argv(argv, daemon_argv[i]);
}
close_random_fds();
posix_spawnattr_init(&attr);
posix_spawn_file_actions_init(&actions);
posix_spawn_file_actions_addopen(&actions,
STDOUT_FILENO, log_name, O_WRONLY|O_CREAT|O_APPEND, 0600);
posix_spawn_file_actions_adddup2(&actions,
STDOUT_FILENO, STDERR_FILENO);
posix_spawnp(&pid, argv[0], &actions, &attr, argv, environ);
posix_spawnattr_destroy(&attr);
posix_spawn_file_actions_destroy(&actions);
}
开发者ID:Jerry-goodboy,项目名称:watchman,代码行数:33,代码来源:main.c
示例6: pipeline
void pipeline(const char *const *argv, struct pipeline *pl)
{
posix_spawn_file_actions_t file_acts;
int pipefds[2];
if (pipe(pipefds)) {
die_errno(errno, "pipe");
}
die_errno(posix_spawn_file_actions_init(&file_acts),
"posix_spawn_file_actions_init");
die_errno(posix_spawn_file_actions_adddup2(&file_acts, pipefds[0], 0),
"posix_spawn_file_actions_adddup2");
die_errno(posix_spawn_file_actions_addclose(&file_acts, pipefds[0]),
"posix_spawn_file_actions_addclose");
die_errno(posix_spawn_file_actions_addclose(&file_acts, pipefds[1]),
"posix_spawn_file_actions_addclose");
die_errno(posix_spawnp(&pl->pid, argv[0], &file_acts, NULL,
(char * const *)argv, environ),
"posix_spawnp: %s", argv[0]);
die_errno(posix_spawn_file_actions_destroy(&file_acts),
"posix_spawn_file_actions_destroy");
if (close(pipefds[0])) {
die_errno(errno, "close");
}
pl->infd = pipefds[1];
}
开发者ID:2600hz-archive,项目名称:rabbitmq-c,代码行数:31,代码来源:process.c
示例7: b_run_loop_exec_basic
B_WUR B_EXPORT_FUNC bool
b_run_loop_exec_basic(
B_BORROW struct B_RunLoop *run_loop,
B_BORROW char const *const *command_args,
B_RunLoopProcessFunction *callback,
B_RunLoopFunction *cancel_callback,
B_BORROW void const *callback_data,
size_t callback_data_size,
B_OUT struct B_Error *e) {
B_PRECONDITION(run_loop);
B_PRECONDITION(command_args);
B_PRECONDITION(command_args[0]);
B_PRECONDITION(callback);
B_PRECONDITION(cancel_callback);
B_OUT_PARAMETER(e);
#if B_CONFIG_POSIX_SPAWN
pid_t pid;
int rc = posix_spawnp(
&pid,
command_args[0],
NULL,
NULL,
// FIXME(strager): This cast looks like a bug.
(char *const *) command_args,
b_environ_());
if (rc != 0) {
*e = (struct B_Error) {.posix_error = rc};
return false;
}
开发者ID:strager,项目名称:b-cc,代码行数:30,代码来源:RunLoop.c
示例8: test_stop_after_delay
void
test_stop_after_delay(void *delay) {
#if HAVE_LEAKS
int res;
pid_t pid;
char pidstr[10];
#endif
if (delay != NULL) {
Sleep((DWORD)(SIZE_T)delay * 1000);
}
#if HAVE_LEAKS
if (getenv("NOLEAKS")) _exit(EXIT_SUCCESS);
/* leaks doesn't work against debug variant malloc */
if (getenv("DYLD_IMAGE_SUFFIX")) _exit(EXIT_SUCCESS);
snprintf(pidstr, sizeof(pidstr), "%d", getpid());
char* args[] = { "./leaks-wrapper", pidstr, NULL };
res = posix_spawnp(&pid, args[0], NULL, NULL, args, environ);
if (res == 0 && pid > 0) {
int status;
waitpid(pid, &status, 0);
test_long("Leaks", status, 0);
} else {
perror(args[0]);
}
#endif
_exit(EXIT_SUCCESS);
}
开发者ID:DrPizza,项目名称:libdispatch,代码行数:31,代码来源:dispatch_test.c
示例9: Launch_posixSpawnSuspended
/*
* Static function implementations
*/
pid_t Launch_posixSpawnSuspended(cpu_type_t cpuType, const char *path, char** argv) {
pid_t retVal = -1;
if (path == NULL || argv == NULL) {
Log_invalidArgument("path: %p, argv: %p", path, argv);
} else {
posix_spawnattr_t attr = 0;
int ret = posix_spawnattr_init(&attr);
if (ret != 0) {
Log_errorPosix(ret, "posix_spawnattr_init");
} else {
sigset_t no_signals = 0;
sigset_t all_signals = 0;
sigemptyset(&no_signals);
sigfillset(&all_signals);
posix_spawnattr_setsigmask(&attr, &no_signals);
posix_spawnattr_setsigdefault(&attr, &all_signals);
if (cpuType != CPU_TYPE_ANY) {
size_t ocount = 0;
// if specified choose the arch from the fat binary to run
ret = posix_spawnattr_setbinpref_np(&attr, 1, &cpuType, &ocount);
if (ret != 0) {
Log_errorPosix(ret, "posix_spawnattr_setbinpref_np");
}
}
if (ret == 0) {
ret = posix_spawnattr_setflags(&attr,
POSIX_SPAWN_START_SUSPENDED
| _POSIX_SPAWN_DISABLE_ASLR
| POSIX_SPAWN_SETSIGDEF
| POSIX_SPAWN_SETSIGMASK);
if (ret != 0) {
Log_errorPosix(ret, "posix_spawnattr_setflags");
} else {
pid_t pid = -1;
ret = posix_spawnp(&pid,
path,
NULL,
&attr,
(char * const*)argv,
(char * const*)NULL);
if (ret != 0) {
Log_errorPosix(ret, "posix_spawnp");
} else {
retVal = pid;
}
}
}
posix_spawnattr_destroy(&attr);
}
}
return retVal;
}
开发者ID:mountainstorm,项目名称:Flow,代码行数:62,代码来源:Launch.c
示例10: SHVDir_system
int SHVDir_system(const char* cmd)
{
pid_t pid;
int retVal;
const char* argv[] = { "sh", "-c", NULL, NULL }; argv[2] = cmd;
posix_spawnp(&pid,argv[0],NULL,NULL,(char*const*)argv,environ);
return waitpid(pid,&retVal,0);
}
开发者ID:ElmerFuddDK,项目名称:libshiva,代码行数:8,代码来源:shvdir.cpp
示例11: main
int main(int argc, char* argv[])
{
char** newargv;
int status;
argv0 = argv[0];
argc--; argv++;
if(!argc)
{
usage(1);
}
struct child {
int in[2];
int out[2];
} child;
if(pipe(child.in) < 0)
perror("pipe");
if(pipe(child.out) < 0)
perror("pipe");
pid_t pid;
posix_spawn_file_actions_t action;
posix_spawn_file_actions_init(&action);
posix_spawn_file_actions_adddup2(&action, child.in[0], STDIN_FILENO);
posix_spawn_file_actions_addclose(&action, child.in[0]);
posix_spawn_file_actions_adddup2(&action, child.out[1], STDOUT_FILENO);
posix_spawn_file_actions_addclose(&action, child.out[1]);
if(posix_spawnp(&pid, argv[0], &action, NULL, argv, NULL) < 0)
{
// TODO: manage errors here.
}
int i;
char c[2];
c[1] = '\0';
for(i = 0; i < 5; i++)
{
c[0] = '0' + i;
write(child.in[1], "echo ", 5);
write(child.in[1], c, 1);
write(child.in[1], "\n", 1);
c[0] = '\0';
read(child.out[0], c, 1);
printf("Output was: %s\n", c);
read(child.out[0], c, 1); // read the newline
}
write(child.in[1], "exit\n", 5);
waitpid(pid, &status, 0);
printf("%s exited with status %d\n", argv[0], status);
return 0;
}
开发者ID:Rant-and-Dev,项目名称:maestro,代码行数:58,代码来源:maestro-apply.c
示例12: sta_ioctl
int sta_ioctl(struct sta_link_info *link_info, int cmd)
{
int err = 0;
pid_t pid = 0;
int status = 0;
int exit_flag = 0;
char *spawn_env[] = {NULL};
char *spawn_args[] = {"list_ap.sh", NULL,
link_info->interface, NULL};
switch (cmd) {
case CONNECT:
case RESTART:
err = connect_ap(link_info);
break;
case CHKSTATUS:
spawn_args[1] = "-c";
break;
case DISCONNECT:
spawn_args[1] = "-d";
break;
case RECONNECT:
spawn_args[1] = "-r";
break;
default:
break;
}
if(cmd == CONNECT || cmd == RESTART) {
if(-1 == err)
return -1;
else
return 0;
}
err = posix_spawnp(&pid, spawn_args[0], NULL, NULL,
spawn_args, spawn_env);
if (0 != err) {
FPRINTF_CA(stderr, "posix_spawnp() error=%d\n", err);
return -1;
}
err = waitpid(pid, &status, 0);
if (-1 == err) {
perror("waitpid");
return -1;
}
if (!strcmp(spawn_args[1], "-c")) {
exit_flag = WEXITSTATUS(status);
if (8 == exit_flag)
return -1;
}
return 0;
}
开发者ID:andyvand,项目名称:ST_wifi_7601U,代码行数:56,代码来源:sta_inf.c
示例13: do_test_setsid
static void
do_test_setsid (bool test_setsid)
{
pid_t sid, child_sid;
int res;
/* Current session ID. */
sid = getsid(0);
if (sid == (pid_t) -1)
FAIL_EXIT1 ("getsid (0): %m");
posix_spawnattr_t attrp;
/* posix_spawnattr_init should not fail (it basically memset the
attribute). */
posix_spawnattr_init (&attrp);
if (test_setsid)
{
res = posix_spawnattr_setflags (&attrp, POSIX_SPAWN_SETSID);
if (res != 0)
{
errno = res;
FAIL_EXIT1 ("posix_spawnattr_setflags: %m");
}
}
/* Program to run. */
char *args[2] = { (char *) "true", NULL };
pid_t child;
res = posix_spawnp (&child, "true", NULL, &attrp, args, environ);
/* posix_spawnattr_destroy is noop. */
posix_spawnattr_destroy (&attrp);
if (res != 0)
{
errno = res;
FAIL_EXIT1 ("posix_spawnp: %m");
}
/* Child should have a different session ID than parent. */
child_sid = getsid (child);
if (child_sid == (pid_t) -1)
FAIL_EXIT1 ("getsid (%i): %m", child);
if (test_setsid)
{
if (child_sid == sid)
FAIL_EXIT1 ("child session ID matched parent one");
}
else
{
if (child_sid != sid)
FAIL_EXIT1 ("child session ID did not match parent one");
}
}
开发者ID:riscv,项目名称:riscv-glibc,代码行数:56,代码来源:tst-posix_spawn-setsid.c
示例14: h2o_read_command
int h2o_read_command(const char *cmd, char **argv, h2o_buffer_t **resp, int *child_status)
{
int respfds[2] = {-1, -1};
posix_spawn_file_actions_t file_actions;
pid_t pid = -1;
int ret = -1;
extern char **environ;
h2o_buffer_init(resp, &h2o_socket_buffer_prototype);
/* create pipe for reading the result */
if (pipe(respfds) != 0)
goto Exit;
/* spawn */
posix_spawn_file_actions_init(&file_actions);
posix_spawn_file_actions_adddup2(&file_actions, respfds[1], 1);
if ((errno = posix_spawnp(&pid, cmd, &file_actions, NULL, argv, environ)) != 0) {
pid = -1;
goto Exit;
}
close(respfds[1]);
respfds[1] = -1;
/* read the response from pipe */
while (1) {
h2o_iovec_t buf = h2o_buffer_reserve(resp, 8192);
ssize_t r;
while ((r = read(respfds[0], buf.base, buf.len)) == -1 && errno == EINTR)
;
if (r <= 0)
break;
(*resp)->size += r;
}
Exit:
if (pid != -1) {
/* wait for the child to complete */
pid_t r;
while ((r = waitpid(pid, child_status, 0)) == -1 && errno == EINTR)
;
if (r == pid) {
/* success */
ret = 0;
}
}
if (respfds[0] != -1)
close(respfds[0]);
if (respfds[1] != -1)
close(respfds[1]);
if (ret != 0)
h2o_buffer_dispose(resp);
return ret;
}
开发者ID:zhangjinde,项目名称:h2o,代码行数:55,代码来源:serverutil.c
示例15: cat_logfile
void cat_logfile()
{
static int cnt;
char *argv_child[] = {"cat", file_log, NULL};
printf("%d={", cnt++);
fflush(stdout);
posix_spawnp(NULL, argv_child[0], NULL, NULL, argv_child, NULL);
wait(NULL);
printf("}\n");
fflush(stdout);
}
开发者ID:h9379203,项目名称:linet,代码行数:11,代码来源:ind_ch.c
示例16: test_proc
void
test_proc(pid_t bad_pid)
{
dispatch_source_t proc_s[PID_CNT], proc;
int res;
pid_t pid, monitor_pid;
event_cnt = 0;
// Creates a process and register multiple observers. Send a signal,
// exit the process, etc., and verify all observers were notified.
posix_spawnattr_t attr;
res = posix_spawnattr_init(&attr);
assert(res == 0);
#if HAVE_DECL_POSIX_SPAWN_START_SUSPENDED
res = posix_spawnattr_setflags(&attr, POSIX_SPAWN_START_SUSPENDED);
assert(res == 0);
#endif
char* args[] = {
"/bin/sleep", "2", NULL
};
res = posix_spawnp(&pid, args[0], NULL, &attr, args, NULL);
if (res < 0) {
perror(args[0]);
exit(127);
}
res = posix_spawnattr_destroy(&attr);
assert(res == 0);
dispatch_group_t group = dispatch_group_create();
assert(pid > 0);
monitor_pid = bad_pid ? bad_pid : pid; // rdar://problem/8090801
int i;
for (i = 0; i < PID_CNT; ++i) {
dispatch_group_enter(group);
proc = proc_s[i] = dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC,
monitor_pid, DISPATCH_PROC_EXIT, dispatch_get_global_queue(0, 0));
test_ptr_notnull("dispatch_source_proc_create", proc);
dispatch_source_set_event_handler(proc, ^{
long flags = dispatch_source_get_data(proc);
test_long("DISPATCH_PROC_EXIT", flags, DISPATCH_PROC_EXIT);
event_cnt++;
dispatch_source_cancel(proc);
});
dispatch_source_set_cancel_handler(proc, ^{
dispatch_group_leave(group);
});
开发者ID:2php,项目名称:libdispatch,代码行数:52,代码来源:dispatch_proc.c
示例17: spawn_site_specific
// Spawn watchman via a site-specific spawn helper program.
// We'll pass along any daemon-appropriate arguments that
// we noticed during argument parsing.
static void spawn_site_specific(const char *spawner)
{
char *argv[MAX_DAEMON_ARGS] = {
(char*)spawner,
NULL
};
posix_spawn_file_actions_t actions;
posix_spawnattr_t attr;
pid_t pid;
int i;
int res, err;
for (i = 0; daemon_argv[i]; i++) {
append_argv(argv, daemon_argv[i]);
}
close_random_fds();
posix_spawnattr_init(&attr);
posix_spawn_file_actions_init(&actions);
posix_spawn_file_actions_addopen(&actions,
STDOUT_FILENO, log_name, O_WRONLY|O_CREAT|O_APPEND, 0600);
posix_spawn_file_actions_adddup2(&actions,
STDOUT_FILENO, STDERR_FILENO);
res = posix_spawnp(&pid, argv[0], &actions, &attr, argv, environ);
err = errno;
posix_spawnattr_destroy(&attr);
posix_spawn_file_actions_destroy(&actions);
if (res) {
w_log(W_LOG_FATAL, "Failed to spawn watchman via `%s': %s\n", spawner,
strerror(err));
}
if (waitpid(pid, &res, 0) == -1) {
w_log(W_LOG_FATAL, "Failed waiting for %s: %s\n", spawner, strerror(errno));
}
if (WIFEXITED(res) && WEXITSTATUS(res) == 0) {
return;
}
if (WIFEXITED(res)) {
w_log(W_LOG_FATAL, "%s: exited with status %d\n", spawner,
WEXITSTATUS(res));
} else if (WIFSIGNALED(res)) {
w_log(W_LOG_FATAL, "%s: signaled with %d\n", spawner, WTERMSIG(res));
}
w_log(W_LOG_ERR, "%s: failed to start, exit status %d\n", spawner, res);
}
开发者ID:Jerry-goodboy,项目名称:watchman,代码行数:54,代码来源:main.c
示例18: shell_spawn_pipecmd
/*
* Spawn a sh(1) command. Writes the resulting process ID to the pid_t pointed
* at by `pid'. Returns a file descriptor (int) suitable for writing data to
* the spawned command (data written to file descriptor is seen as standard-in
* by the spawned sh(1) command). Returns `-1' if unable to spawn command.
*
* If cmd contains a single "%s" sequence, replace it with label if non-NULL.
*/
int
shell_spawn_pipecmd(const char *cmd, const char *label, pid_t *pid)
{
int error;
int len;
posix_spawn_file_actions_t action;
#if SHELL_SPAWN_DEBUG
unsigned int i;
#endif
int stdin_pipe[2] = { -1, -1 };
/* Populate argument array */
if (label != NULL && fmtcheck(cmd, "%s") == cmd)
len = snprintf(cmdbuf, CMDBUFMAX, cmd, label);
else
len = snprintf(cmdbuf, CMDBUFMAX, "%s", cmd);
if (len >= CMDBUFMAX) {
warnx("%s:%d:%s: cmdbuf[%u] too small to hold cmd argument",
__FILE__, __LINE__, __func__, CMDBUFMAX);
return (-1);
}
/* Open a pipe to communicate with [X]dialog(1) */
if (pipe(stdin_pipe) < 0)
err(EXIT_FAILURE, "%s: pipe(2)", __func__);
/* Fork sh(1) process */
#if SHELL_SPAWN_DEBUG
fprintf(stderr, "%s: spawning `", __func__);
for (i = 0; shellcmd_argv[i] != NULL; i++) {
if (i == 0)
fprintf(stderr, "%s", shellcmd_argv[i]);
else if (i == 2)
fprintf(stderr, " '%s'", shellcmd_argv[i]);
else
fprintf(stderr, " %s", shellcmd_argv[i]);
}
fprintf(stderr, "'\n");
#endif
posix_spawn_file_actions_init(&action);
posix_spawn_file_actions_adddup2(&action, stdin_pipe[0], STDIN_FILENO);
posix_spawn_file_actions_addclose(&action, stdin_pipe[1]);
error = posix_spawnp(pid, shellcmd, &action,
(const posix_spawnattr_t *)NULL, shellcmd_argv, environ);
if (error != 0)
err(EXIT_FAILURE, "%s: posix_spawnp(3)", __func__);
return stdin_pipe[1];
}
开发者ID:coyizumi,项目名称:cs111,代码行数:57,代码来源:util.c
示例19: cleanup
cleanup(int status)
{
// Mask signals, so if called from non-signal context, we
// won't get a reentry (especially for SIGCHLD).
unsigned i;
sigset_t mask;
sigemptyset (&mask);
for (i = 0; i < sizeof(signals) / sizeof(*signals); ++i)
sigaddset (&mask, signals[i]);
sigprocmask(SIG_BLOCK, &mask, 0);
if (staprun_pid > 0)
{
int rc, ret;
kill(staprun_pid, SIGHUP);
ret = waitpid(staprun_pid, &rc, 0);
if (status == 0)
{
if (ret == staprun_pid)
status = WIFEXITED(rc) ? WEXITSTATUS(rc) : 128 + WTERMSIG(rc);
else
status = 2;
}
}
if (tmpdir[0])
{
pid_t pid = 0;
const char* argv[] = {"rm", "-rf", "--", tmpdir, NULL};
if (chdir("/")) {} // ignore failure, rm will probably work anyway
if (!posix_spawnp(&pid, argv[0], NULL, NULL,
(char* const*)argv, environ))
waitpid(pid, NULL, 0);
}
// Announce we're quitting if prefixing is on. Schemes that use the "data"
// option (e.g. unix and libvirt) are not able to detect when stapsh exits and
// thus need this announcement to close the connection.
if (prefix_data)
reply("quit\n");
if (listening_port)
{
fclose(stapsh_in);
fclose(stapsh_out);
}
exit(status);
}
开发者ID:rth7680,项目名称:systemtap,代码行数:49,代码来源:stapsh.c
示例20: child_spawn1_internal
pid_t child_spawn1_internal (char const *prog, char const *const *argv, char const *const *envp, int *p, int to)
{
posix_spawn_file_actions_t actions ;
posix_spawnattr_t attr ;
int e ;
pid_t pid ;
int haspath = !!env_get("PATH") ;
if (coe(p[!(to & 1)]) < 0) { e = errno ; goto err ; }
e = posix_spawnattr_init(&attr) ;
if (e) goto err ;
{
sigset_t set ;
sigemptyset(&set) ;
e = posix_spawnattr_setsigmask(&attr, &set) ;
if (e) goto errattr ;
e = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK) ;
if (e) goto errattr ;
}
e = posix_spawn_file_actions_init(&actions) ;
if (e) goto errattr ;
e = posix_spawn_file_actions_adddup2(&actions, p[to & 1], to & 1) ;
if (e) goto erractions ;
e = posix_spawn_file_actions_addclose(&actions, p[to & 1]) ;
if (e) goto erractions ;
if (to & 2)
{
e = posix_spawn_file_actions_adddup2(&actions, to & 1, !(to & 1)) ;
if (e) goto erractions ;
}
if (!haspath && (setenv("PATH", SKALIBS_DEFAULTPATH, 0) < 0)) { e = errno ; goto erractions ; }
e = posix_spawnp(&pid, prog, &actions, &attr, (char *const *)argv, (char *const *)envp) ;
if (!haspath) unsetenv("PATH") ;
posix_spawn_file_actions_destroy(&actions) ;
posix_spawnattr_destroy(&attr) ;
fd_close(p[to & 1]) ;
if (e) goto errp ;
return pid ;
erractions:
posix_spawn_file_actions_destroy(&actions) ;
errattr:
posix_spawnattr_destroy(&attr) ;
err:
fd_close(p[to & 1]) ;
errp:
fd_close(p[!(to & 1)]) ;
errno = e ;
return 0 ;
}
开发者ID:fvigotti,项目名称:skalibs,代码行数:49,代码来源:child_spawn1_internal.c
注:本文中的posix_spawnp函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论