From 51cf178616eebbb76e595d6abe0ffdaa83d2aec5 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 5 Dec 2014 16:18:10 +0000 Subject: Simplify child_spawn: remove syncpipe in the posix_spawn() case --- src/libstddjb/child_spawn.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/libstddjb/child_spawn.c b/src/libstddjb/child_spawn.c index aa937fd..867f800 100644 --- a/src/libstddjb/child_spawn.c +++ b/src/libstddjb/child_spawn.c @@ -46,9 +46,10 @@ pid_t child_spawn (char const *prog, char const *const *argv, char const *const #ifdef SKALIBS_HASPOSIXSPAWN posix_spawn_file_actions_t actions ; posix_spawnattr_t attr ; +#else + int syncpipe[2] ; #endif int p[n ? n : 1][2] ; - int syncpipe[2] ; pid_t pid ; int e ; unsigned int m = sizeof(NOFDVAR) ; @@ -63,8 +64,6 @@ pid_t child_spawn (char const *prog, char const *const *argv, char const *const { for (i = 0 ; i < n ; i++) if (pipe(p[i]) < 0) { e = errno ; goto errp ; } } - if (pipe(syncpipe) < 0) { e = errno ; goto errp ; } - if (coe(syncpipe[1]) < 0) { e = errno ; goto errsp ; } for (i = 0 ; i < n ; i++) if ((ndelay_on(p[i][i & 1]) < 0) || (coe(p[i][i & 1]) < 0)) { @@ -89,8 +88,6 @@ pid_t child_spawn (char const *prog, char const *const *argv, char const *const if (e) goto errattr ; e = posix_spawn_file_actions_init(&actions) ; if (e) goto errattr ; - e = posix_spawn_file_actions_addclose(&actions, syncpipe[0]) ; - if (e) goto erractions ; switch (n) { case 0 : @@ -132,6 +129,8 @@ pid_t child_spawn (char const *prog, char const *const *argv, char const *const posix_spawnattr_destroy(&attr) ; #else + if (pipe(syncpipe) < 0) { e = errno ; goto errp ; } + if (coe(syncpipe[1]) < 0) { e = errno ; goto errsp ; } pid = fork() ; if (pid < 0) { e = errno ; goto errsp ; } @@ -174,8 +173,6 @@ pid_t child_spawn (char const *prog, char const *const *argv, char const *const _exit(127) ; } -#endif - fd_close(syncpipe[1]) ; { char c ; @@ -192,14 +189,10 @@ pid_t child_spawn (char const *prog, char const *const *argv, char const *const goto errsp0 ; } } - if (waitpid_nointr(pid, &e, WNOHANG)) - { - e = WEXITSTATUS(e) == 127 ? EIO : 0 ; - goto errsp0 ; - } - fd_close(syncpipe[0]) ; - for (i = n ; i ; i--) +#endif + + for (; i ; i--) { fd_close(p[i-1][i & 1]) ; fds[i-1] = p[i-1][!(i & 1)] ; @@ -213,9 +206,11 @@ pid_t child_spawn (char const *prog, char const *const *argv, char const *const posix_spawnattr_destroy(&attr) ; #endif errsp: +#ifndef SKALIBS_HASPOSIXSPAWN fd_close(syncpipe[1]) ; errsp0: fd_close(syncpipe[0]) ; +#endif i = n ; errp: while (i--) -- cgit v1.2.3