aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-04-09 13:21:33 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-04-09 13:21:33 +0000
commit53d445aa7571c780b8f2410afb4f326e45f851e4 (patch)
tree6e07b3c0349e876a6c3aee11f6a64690307d2f0b
parent7e754f12d304704d44e10fd4d2fdb8710526656e (diff)
downloadbusybox-53d445aa7571c780b8f2410afb4f326e45f851e4.tar.gz
wait4pid: if passed with pid < 0, do not set errno - it is already set by exec!
-rw-r--r--libbb/vfork_daemon_rexec.c34
-rw-r--r--libbb/xfuncs.c33
2 files changed, 33 insertions, 34 deletions
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index 11dbb24fc..ff2b0bceb 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -61,11 +61,43 @@ pid_t spawn(char **argv)
pid_t xspawn(char **argv)
{
pid_t pid = spawn(argv);
- if (pid < 0) bb_perror_msg_and_die("%s", *argv);
+ if (pid < 0)
+ bb_perror_msg_and_die("%s", *argv);
return pid;
}
+// Wait for the specified child PID to exit, returning child's error return.
+int wait4pid(int pid)
+{
+ int status;
+
+ if (pid <= 0) {
+ /*errno = ECHILD; -- wrong. we expect errno to be set from failed exec */
+ return -1;
+ }
+ if (waitpid(pid, &status, 0) == -1)
+ return -1;
+ if (WIFEXITED(status))
+ return WEXITSTATUS(status);
+ if (WIFSIGNALED(status))
+ return WTERMSIG(status) + 10000;
+ return 0;
+}
+int wait_nohang(int *wstat)
+{
+ return waitpid(-1, wstat, WNOHANG);
+}
+
+int wait_pid(int *wstat, int pid)
+{
+ int r;
+
+ do
+ r = waitpid(pid, wstat, 0);
+ while ((r == -1) && (errno == EINTR));
+ return r;
+}
#if 0 //ndef BB_NOMMU
// Die with an error message if we can't daemonize.
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index c18a1d998..0cf2005ac 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -193,39 +193,6 @@ void xfflush_stdout(void)
}
}
-// Wait for the specified child PID to exit, returning child's error return.
-int wait4pid(int pid)
-{
- int status;
-
- if (pid <= 0) {
- errno = ECHILD;
- return -1;
- }
- if (waitpid(pid, &status, 0) == -1)
- return -1;
- if (WIFEXITED(status))
- return WEXITSTATUS(status);
- if (WIFSIGNALED(status))
- return WTERMSIG(status) + 10000;
- return 0;
-}
-
-int wait_nohang(int *wstat)
-{
- return waitpid(-1, wstat, WNOHANG);
-}
-
-int wait_pid(int *wstat, int pid)
-{
- int r;
-
- do
- r = waitpid(pid, wstat, 0);
- while ((r == -1) && (errno == EINTR));
- return r;
-}
-
void sig_block(int sig)
{
sigset_t ss;