svn commit: trunk/busybox/libbb
vda at busybox.net
vda at busybox.net
Mon Apr 9 13:21:35 UTC 2007
Author: vda
Date: 2007-04-09 06:21:33 -0700 (Mon, 09 Apr 2007)
New Revision: 18373
Log:
wait4pid: if passed with pid < 0, do not set errno - it is already set by exec!
Modified:
trunk/busybox/libbb/vfork_daemon_rexec.c
trunk/busybox/libbb/xfuncs.c
Changeset:
Modified: trunk/busybox/libbb/vfork_daemon_rexec.c
===================================================================
--- trunk/busybox/libbb/vfork_daemon_rexec.c 2007-04-09 13:04:50 UTC (rev 18372)
+++ trunk/busybox/libbb/vfork_daemon_rexec.c 2007-04-09 13:21:33 UTC (rev 18373)
@@ -61,12 +61,44 @@
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.
void xdaemon(int nochdir, int noclose)
Modified: trunk/busybox/libbb/xfuncs.c
===================================================================
--- trunk/busybox/libbb/xfuncs.c 2007-04-09 13:04:50 UTC (rev 18372)
+++ trunk/busybox/libbb/xfuncs.c 2007-04-09 13:21:33 UTC (rev 18373)
@@ -193,39 +193,6 @@
}
}
-// 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;
More information about the busybox-cvs
mailing list