diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-09 13:21:33 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-09 13:21:33 +0000 |
commit | 53d445aa7571c780b8f2410afb4f326e45f851e4 (patch) | |
tree | 6e07b3c0349e876a6c3aee11f6a64690307d2f0b | |
parent | 7e754f12d304704d44e10fd4d2fdb8710526656e (diff) | |
download | busybox-w32-53d445aa7571c780b8f2410afb4f326e45f851e4.tar.gz busybox-w32-53d445aa7571c780b8f2410afb4f326e45f851e4.tar.bz2 busybox-w32-53d445aa7571c780b8f2410afb4f326e45f851e4.zip |
wait4pid: if passed with pid < 0, do not set errno - it is already set by exec!
-rw-r--r-- | libbb/vfork_daemon_rexec.c | 34 | ||||
-rw-r--r-- | libbb/xfuncs.c | 33 |
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) | |||
61 | pid_t xspawn(char **argv) | 61 | pid_t xspawn(char **argv) |
62 | { | 62 | { |
63 | pid_t pid = spawn(argv); | 63 | pid_t pid = spawn(argv); |
64 | if (pid < 0) bb_perror_msg_and_die("%s", *argv); | 64 | if (pid < 0) |
65 | bb_perror_msg_and_die("%s", *argv); | ||
65 | return pid; | 66 | return pid; |
66 | } | 67 | } |
67 | 68 | ||
69 | // Wait for the specified child PID to exit, returning child's error return. | ||
70 | int wait4pid(int pid) | ||
71 | { | ||
72 | int status; | ||
73 | |||
74 | if (pid <= 0) { | ||
75 | /*errno = ECHILD; -- wrong. we expect errno to be set from failed exec */ | ||
76 | return -1; | ||
77 | } | ||
78 | if (waitpid(pid, &status, 0) == -1) | ||
79 | return -1; | ||
80 | if (WIFEXITED(status)) | ||
81 | return WEXITSTATUS(status); | ||
82 | if (WIFSIGNALED(status)) | ||
83 | return WTERMSIG(status) + 10000; | ||
84 | return 0; | ||
85 | } | ||
68 | 86 | ||
87 | int wait_nohang(int *wstat) | ||
88 | { | ||
89 | return waitpid(-1, wstat, WNOHANG); | ||
90 | } | ||
91 | |||
92 | int wait_pid(int *wstat, int pid) | ||
93 | { | ||
94 | int r; | ||
95 | |||
96 | do | ||
97 | r = waitpid(pid, wstat, 0); | ||
98 | while ((r == -1) && (errno == EINTR)); | ||
99 | return r; | ||
100 | } | ||
69 | 101 | ||
70 | #if 0 //ndef BB_NOMMU | 102 | #if 0 //ndef BB_NOMMU |
71 | // Die with an error message if we can't daemonize. | 103 | // 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) | |||
193 | } | 193 | } |
194 | } | 194 | } |
195 | 195 | ||
196 | // Wait for the specified child PID to exit, returning child's error return. | ||
197 | int wait4pid(int pid) | ||
198 | { | ||
199 | int status; | ||
200 | |||
201 | if (pid <= 0) { | ||
202 | errno = ECHILD; | ||
203 | return -1; | ||
204 | } | ||
205 | if (waitpid(pid, &status, 0) == -1) | ||
206 | return -1; | ||
207 | if (WIFEXITED(status)) | ||
208 | return WEXITSTATUS(status); | ||
209 | if (WIFSIGNALED(status)) | ||
210 | return WTERMSIG(status) + 10000; | ||
211 | return 0; | ||
212 | } | ||
213 | |||
214 | int wait_nohang(int *wstat) | ||
215 | { | ||
216 | return waitpid(-1, wstat, WNOHANG); | ||
217 | } | ||
218 | |||
219 | int wait_pid(int *wstat, int pid) | ||
220 | { | ||
221 | int r; | ||
222 | |||
223 | do | ||
224 | r = waitpid(pid, wstat, 0); | ||
225 | while ((r == -1) && (errno == EINTR)); | ||
226 | return r; | ||
227 | } | ||
228 | |||
229 | void sig_block(int sig) | 196 | void sig_block(int sig) |
230 | { | 197 | { |
231 | sigset_t ss; | 198 | sigset_t ss; |