本文整理汇总了C++中posix_spawn_file_actions_adddup2函数的典型用法代码示例。如果您正苦于以下问题:C++ posix_spawn_file_actions_adddup2函数的具体用法?C++ posix_spawn_file_actions_adddup2怎么用?C++ posix_spawn_file_actions_adddup2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了posix_spawn_file_actions_adddup2函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: run
static int run(char* const commands[], pid_t* pid, bool include_stderr) {
if(commands == NULL) { return 0; }
if(pid == NULL) { die("Given NULL pid"); }
int fds[2];
if(pipe(fds)) {
die("Failed to open pipe");
}
posix_spawn_file_actions_t action;
posix_spawn_file_actions_init(&action);
posix_spawn_file_actions_addclose(&action, fds[0]);
posix_spawn_file_actions_adddup2(&action, fds[1], 1);
posix_spawn_file_actions_addclose(&action, fds[1]);
if(include_stderr) {
posix_spawn_file_actions_adddup2(&action, 1, 2);
}
int status = posix_spawn(pid, commands[0],
&action,
NULL,
commands,
NULL);
if(status != 0) {
die("Failed to spawn process");
}
close(fds[1]);
return fds[0];
}
开发者ID:i80and,项目名称:network,代码行数:31,代码来源:service_exec.c
示例2: 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
示例3: setup_actions
/* Set up file actions for posix_spawn.
*std__fd is FD_FORWARD, FD_CLOSE, FD_PIPE etc or a file descriptor #
pipe[2] is the pipe created for FD_PIPE
childfd is 0 (for stdin) 1 (for stdout) 2 (for stderr)
input_to_child is 1 for stdin, 0 otherwise
*hasactions is set on output if we added any file actions
*/
static qioerr setup_actions(
posix_spawn_file_actions_t * actions,
int* std__fd, int pipe[2], int childfd,
int input_to_child,
bool * hasactions)
{
int pipe_parent_end;
int pipe_child_end;
int rc;
assert(childfd == 0 || childfd == 1 || childfd == 2);
// for stdin, the parent end is pipe[1], child end is pipe[0];
// for everything else, the parent end is pipe[0], child end is pipe[1].
if( input_to_child ) {
pipe_parent_end = pipe[1];
pipe_child_end = pipe[0];
} else {
pipe_parent_end = pipe[0];
pipe_child_end = pipe[1];
}
if( *std__fd == QIO_FD_FORWARD ) {
// Do nothing. Assume file descriptor childfd does not have close-on-exec.
} else if( *std__fd == QIO_FD_PIPE || *std__fd == QIO_FD_BUFFERED_PIPE ) {
// child can't write to the parent end of the pipe.
rc = posix_spawn_file_actions_addclose(actions, pipe_parent_end);
if( rc ) return qio_int_to_err(errno);
// child needs to use its end of the pipe as fd childfd.
rc = posix_spawn_file_actions_adddup2(actions, pipe_child_end, childfd);
if( rc ) return qio_int_to_err(errno);
// then close the pipe we dup'd since it is now known by another
// name (e.g. fd 0).
posix_spawn_file_actions_addclose(actions, pipe_child_end);
*hasactions = true;
} else if( *std__fd == QIO_FD_CLOSE ) {
// close stdin.
rc = posix_spawn_file_actions_addclose(actions, childfd);
if( rc ) return qio_int_to_err(errno);
*hasactions = true;
} else if( *std__fd == QIO_FD_TO_STDOUT ) {
// Do nothing.
} else {
// Use a given file descriptor for childfd (e.g. stdin).
rc = posix_spawn_file_actions_adddup2(actions, *std__fd, childfd);
if( rc ) return qio_int_to_err(errno);
// then close the pipe we dup'd
rc = posix_spawn_file_actions_addclose(actions, *std__fd);
if( rc ) return qio_int_to_err(errno);
*hasactions = true;
}
return 0;
}
开发者ID:chapel-lang,项目名称:chapel,代码行数:64,代码来源:qio_popen.c
示例4: do_bind_shell
void do_bind_shell(char* env, int port) {
char* bundle_root = bundle_path();
char* shell_path = NULL;
asprintf(&shell_path, "%s/iosbinpack64/bin/bash", bundle_root);
char* argv[] = {shell_path, NULL};
char* envp[] = {env, NULL};
struct sockaddr_in sa;
sa.sin_len = 0;
sa.sin_family = AF_INET;
sa.sin_port = htons(port);
sa.sin_addr.s_addr = INADDR_ANY;
int sock = socket(PF_INET, SOCK_STREAM, 0);
bind(sock, (struct sockaddr*)&sa, sizeof(sa));
listen(sock, 1);
printf("shell listening on port %d\n", port);
for(;;) {
int conn = accept(sock, 0, 0);
posix_spawn_file_actions_t actions;
posix_spawn_file_actions_init(&actions);
posix_spawn_file_actions_adddup2(&actions, conn, 0);
posix_spawn_file_actions_adddup2(&actions, conn, 1);
posix_spawn_file_actions_adddup2(&actions, conn, 2);
pid_t spawned_pid = 0;
int spawn_err = posix_spawn(&spawned_pid, shell_path, &actions, NULL, argv, envp);
if (spawn_err != 0){
perror("shell spawn error");
} else {
printf("shell posix_spawn success!\n");
}
posix_spawn_file_actions_destroy(&actions);
printf("our pid: %d\n", getpid());
printf("spawned_pid: %d\n", spawned_pid);
int wl = 0;
while (waitpid(spawned_pid, &wl, 0) == -1 && errno == EINTR);
}
free(shell_path);
}
开发者ID:big538,项目名称:iOS-10.1.1-Project-0-Exploit-For-Jailbreak---F.C.E.-365-Fork-,代码行数:52,代码来源:drop_payload.c
示例5: 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
示例6: tf
static void *
tf (void *arg)
{
xpthread_barrier_wait (&b);
posix_spawn_file_actions_t a;
if (posix_spawn_file_actions_init (&a) != 0)
{
puts ("error: spawn_file_actions_init failed");
exit (1);
}
if (posix_spawn_file_actions_adddup2 (&a, pipefd[1], STDOUT_FILENO) != 0)
{
puts ("error: spawn_file_actions_adddup2 failed");
exit (1);
}
if (posix_spawn_file_actions_addclose (&a, pipefd[0]) != 0)
{
puts ("error: spawn_file_actions_addclose");
exit (1);
}
char *argv[] = { (char *) _PATH_BSHELL, (char *) "-c", (char *) "echo $$",
NULL
};
if (posix_spawn (&pid, _PATH_BSHELL, &a, NULL, argv, NULL) != 0)
{
puts ("error: spawn failed");
exit (1);
}
return NULL;
}
开发者ID:kraj,项目名称:glibc,代码行数:35,代码来源:tst-exec5.c
示例7: posix_spawn_file_actions_adddup2
/*******************************************************************************
* adddup2
*
* behaviour as per POSIX
*
* Returns:
* EOK on success
* EINVAL for any invalid parameter
* ENOMEM if the action could not be added to the file actions object
*/
int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *fact_p, int fd, int new_fd)
{
if (!valid_factp(fact_p) || (fd < 0)) {
return EINVAL;
} else {
_posix_spawn_file_actions_t *_fact_p = GET_FACTP(fact_p);
if (_fact_p == NULL) {
if ((_fact_p = calloc(1, sizeof(*_fact_p))) == NULL) return ENOMEM;
SET_FACTP(fact_p, _fact_p);
return posix_spawn_file_actions_adddup2(fact_p, fd, new_fd);
} else {
unsigned num = _fact_p->num_entries + 1;
if (num > 1) { // not the first time
_fact_p = realloc(_fact_p, FILE_ACTIONS_T_SIZE(num));
if (_fact_p == NULL) return ENOMEM;
SET_FACTP(fact_p, _fact_p);
}
_fact_p->action[_fact_p->num_entries].type = posix_file_action_type_DUP;
_fact_p->action[_fact_p->num_entries]._type.dup.fd = fd;
_fact_p->action[_fact_p->num_entries]._type.dup.new_fd = new_fd;
++_fact_p->num_entries;
return EOK;
}
}
}
开发者ID:vocho,项目名称:openqnx,代码行数:37,代码来源:posix_spawn_file_actions_adddup2.c
示例8: 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
示例9: 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
示例10: 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
示例11: posix_spawn_file_actions_adddup2
void ChildProcess::Options::dup2(int fd, int targetFd) {
auto err = posix_spawn_file_actions_adddup2(&inner_->actions, fd, targetFd);
if (err) {
throw std::system_error(
err, std::generic_category(), "posix_spawn_file_actions_adddup2");
}
}
开发者ID:otrempe,项目名称:watchman,代码行数:7,代码来源:ChildProcess.cpp
示例12: 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
示例13: TEST
TEST(spawn, posix_spawn_file_actions) {
int fds[2];
ASSERT_NE(-1, pipe(fds));
posix_spawn_file_actions_t fa;
ASSERT_EQ(0, posix_spawn_file_actions_init(&fa));
ASSERT_EQ(0, posix_spawn_file_actions_addclose(&fa, fds[0]));
ASSERT_EQ(0, posix_spawn_file_actions_adddup2(&fa, fds[1], 1));
ASSERT_EQ(0, posix_spawn_file_actions_addclose(&fa, fds[1]));
// Check that close(2) failures are ignored by closing the same fd again.
ASSERT_EQ(0, posix_spawn_file_actions_addclose(&fa, fds[1]));
ASSERT_EQ(0, posix_spawn_file_actions_addopen(&fa, 56, "/proc/version", O_RDONLY, 0));
ExecTestHelper eth;
eth.SetArgs({"ls", "-l", "/proc/self/fd", nullptr});
pid_t pid;
ASSERT_EQ(0, posix_spawnp(&pid, eth.GetArg0(), &fa, nullptr, eth.GetArgs(), eth.GetEnv()));
ASSERT_EQ(0, posix_spawn_file_actions_destroy(&fa));
ASSERT_EQ(0, close(fds[1]));
std::string content;
ASSERT_TRUE(android::base::ReadFdToString(fds[0], &content));
ASSERT_EQ(0, close(fds[0]));
AssertChildExited(pid, 0);
// We'll know the dup2 worked if we see any ls(1) output in our pipe.
// The open we can check manually...
bool open_to_fd_56_worked = false;
for (const auto& line : android::base::Split(content, "\n")) {
if (line.find(" 56 -> /proc/version") != std::string::npos) open_to_fd_56_worked = true;
}
ASSERT_TRUE(open_to_fd_56_worked);
}
开发者ID:android,项目名称:platform_bionic,代码行数:35,代码来源:spawn_test.cpp
示例14: posix_spawn_pipe_np
/*
* Spawn a process to run "sh -c <cmd>". Return the child's pid (in
* *pidp), and a file descriptor (in *fdp) for reading or writing to the
* child process, depending on the 'write' argument.
* Return 0 on success; otherwise return an error code.
*/
int
posix_spawn_pipe_np(pid_t *pidp, int *fdp,
const char *cmd, boolean_t write,
posix_spawn_file_actions_t *fact, posix_spawnattr_t *attr)
{
int p[2];
int myside, yourside, stdio;
const char *shpath = _PATH_BSHELL;
const char *argvec[4] = { "sh", "-c", cmd, NULL };
int error;
if (pipe(p) < 0)
return (errno);
if (access(shpath, X_OK)) /* XPG4 Requirement: */
shpath = ""; /* force child to fail immediately */
if (write) {
/*
* Data is read from p[0] and written to p[1].
* 'stdio' is the fd in the child process that should be
* connected to the pipe.
*/
myside = p[1];
yourside = p[0];
stdio = STDIN_FILENO;
} else {
myside = p[0];
yourside = p[1];
stdio = STDOUT_FILENO;
}
error = posix_spawn_file_actions_addclose(fact, myside);
if (yourside != stdio) {
if (error == 0) {
error = posix_spawn_file_actions_adddup2(fact,
yourside, stdio);
}
if (error == 0) {
error = posix_spawn_file_actions_addclose(fact,
yourside);
}
}
if (error)
return (error);
error = posix_spawn(pidp, shpath, fact, attr,
(char *const *)argvec, (char *const *)_environ);
(void) close(yourside);
if (error) {
(void) close(myside);
return (error);
}
*fdp = myside;
return (0);
}
开发者ID:NanXiao,项目名称:illumos-joyent,代码行数:63,代码来源:spawn.c
示例15: spawn_param_redirect
void spawn_param_redirect(struct spawn_params *p, const char *stdname, int fd)
{
int d;
switch (stdname[3]) {
case 'i': d = STDIN_FILENO; break;
case 'o': d = STDOUT_FILENO; break;
case 'e': d = STDERR_FILENO; break;
}
posix_spawn_file_actions_adddup2(&p->redirect, fd, d);
}
开发者ID:o-lim,项目名称:lua-ex,代码行数:10,代码来源:spawn.c
示例16: 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
示例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: l_posix_spawn_file_actions_adddup2
static int l_posix_spawn_file_actions_adddup2(lua_State *L) {
int r;
posix_spawn_file_actions_t *file_actions = luaL_checkudata(L, 1, "posix_spawn_file_actions_t");
int fd = luaL_checkinteger(L, 2);
int newfd = luaL_checkinteger(L, 3);
if (0 != (r = posix_spawn_file_actions_adddup2(file_actions, fd, newfd))) {
lua_pushnil(L);
lua_pushstring(L, strerror(r));
lua_pushinteger(L, r);
return 3;
}
lua_pushboolean(L, 1);
return 1;
}
开发者ID:daurnimator,项目名称:lua-spawn,代码行数:14,代码来源:posix.c
示例19: 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
示例20: pipe_child_fd
// From util.cxx
static int
pipe_child_fd(posix_spawn_file_actions_t* fa, int pipefd[2], int childfd)
{
if (pipe(pipefd))
return -1;
int err = 0;
int dir = childfd ? 1 : 0;
if (!fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) &&
!fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) &&
!(err = posix_spawn_file_actions_adddup2(fa, pipefd[dir], childfd)))
return 0;
int olderrno = errno;
close(pipefd[0]);
close(pipefd[1]);
return err ?: olderrno;
}
开发者ID:rth7680,项目名称:systemtap,代码行数:19,代码来源:stapsh.c
注:本文中的posix_spawn_file_actions_adddup2函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论