aboutsummaryrefslogtreecommitdiff
path: root/lib/xwrap.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-09-27 09:03:41 -0500
committerRob Landley <rob@landley.net>2015-09-27 09:03:41 -0500
commit3b51a07e478d64a84e40b3a7c026b2f8566b194b (patch)
treed9cd3570367e49ef7d51f527bdf68984bf2643c7 /lib/xwrap.c
parent0593b32337b48d60a521922e2355c78750e635d2 (diff)
downloadtoybox-3b51a07e478d64a84e40b3a7c026b2f8566b194b.tar.gz
Another chunk of nommu support, replacing toys.recursion with toys.stacktop.
Diffstat (limited to 'lib/xwrap.c')
-rw-r--r--lib/xwrap.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/xwrap.c b/lib/xwrap.c
index 80862828..e5dc4826 100644
--- a/lib/xwrap.c
+++ b/lib/xwrap.c
@@ -133,7 +133,8 @@ void xflush(void)
// with a path isn't a builtin, so /bin/sh won't match the builtin sh.
void xexec(char **argv)
{
- if (CFG_TOYBOX && !CFG_TOYBOX_NORECURSE) toy_exec(argv);
+ // Only recurse to builtin when we have multiplexer and !vfork context.
+ if (CFG_TOYBOX && !CFG_TOYBOX_NORECURSE && toys.stacktop) toy_exec(argv);
execvp(argv[0], argv);
perror_msg("exec %s", argv[0]);
@@ -198,17 +199,24 @@ pid_t xpopen_both(char **argv, int *pipes)
return pid;
}
-int xpclose_both(pid_t pid, int *pipes)
+// Wait for child process to exit, then return adjusted exit code.
+int xwaitpid(pid_t pid)
{
- int rc = 127;
+ int status;
+
+ while (-1 == waitpid(pid, &status, 0) && errno == EINTR);
+
+ return WIFEXITED(status) ? WEXITSTATUS(status) : WTERMSIG(status)+127;
+}
+int xpclose_both(pid_t pid, int *pipes)
+{
if (pipes) {
close(pipes[0]);
close(pipes[1]);
}
- waitpid(pid, &rc, 0);
- return WIFEXITED(rc) ? WEXITSTATUS(rc) : WTERMSIG(rc) + 127;
+ return xwaitpid(pid);
}
// Wrapper to xpopen with a pipe for just one of stdin/stdout