summaryrefslogtreecommitdiff
path: root/src/libstddjb/child_spawn2.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstddjb/child_spawn2.c')
-rw-r--r--src/libstddjb/child_spawn2.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/libstddjb/child_spawn2.c b/src/libstddjb/child_spawn2.c
index d69764d..4e7d0a5 100644
--- a/src/libstddjb/child_spawn2.c
+++ b/src/libstddjb/child_spawn2.c
@@ -56,14 +56,20 @@ pid_t child_spawn2 (char const *prog, char const *const *argv, char const *const
}
e = posix_spawn_file_actions_init(&actions) ;
if (e) goto errattr ;
- e = posix_spawn_file_actions_adddup2(&actions, p[1][0], fds[0]) ;
- if (e) goto erractions ;
- e = posix_spawn_file_actions_addclose(&actions, p[1][0]) ;
- if (e) goto erractions ;
- e = posix_spawn_file_actions_adddup2(&actions, p[0][1], fds[1]) ;
- if (e) goto erractions ;
- e = posix_spawn_file_actions_addclose(&actions, p[0][1]) ;
- if (e) goto erractions ;
+ if (p[1][0] != fds[0])
+ {
+ e = posix_spawn_file_actions_adddup2(&actions, p[1][0], fds[0]) ;
+ if (e) goto erractions ;
+ e = posix_spawn_file_actions_addclose(&actions, p[1][0]) ;
+ if (e) goto erractions ;
+ }
+ if (p[0][1] != fds[1])
+ {
+ e = posix_spawn_file_actions_adddup2(&actions, p[0][1], fds[1]) ;
+ if (e) goto erractions ;
+ e = posix_spawn_file_actions_addclose(&actions, p[0][1]) ;
+ if (e) goto erractions ;
+ }
{
int haspath = !!getenv("PATH") ;
if (!haspath && (setenv("PATH", SKALIBS_DEFAULTPATH, 0) < 0))