aboutsummaryrefslogtreecommitdiff
path: root/libbb/vfork_daemon_rexec.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/vfork_daemon_rexec.c')
-rw-r--r--libbb/vfork_daemon_rexec.c52
1 files changed, 2 insertions, 50 deletions
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index 08d9199c1..2b6ee9e74 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -70,40 +70,6 @@ pid_t FAST_FUNC xspawn(char **argv)
70 return pid; 70 return pid;
71} 71}
72 72
73pid_t FAST_FUNC safe_waitpid(pid_t pid, int *wstat, int options)
74{
75 pid_t r;
76
77 do
78 r = waitpid(pid, wstat, options);
79 while ((r == -1) && (errno == EINTR));
80 return r;
81}
82
83pid_t FAST_FUNC wait_any_nohang(int *wstat)
84{
85 return safe_waitpid(-1, wstat, WNOHANG);
86}
87
88// Wait for the specified child PID to exit, returning child's error return.
89int FAST_FUNC wait4pid(pid_t pid)
90{
91 int status;
92
93 if (pid <= 0) {
94 /*errno = ECHILD; -- wrong. */
95 /* we expect errno to be already set from failed [v]fork/exec */
96 return -1;
97 }
98 if (safe_waitpid(pid, &status, 0) == -1)
99 return -1;
100 if (WIFEXITED(status))
101 return WEXITSTATUS(status);
102 if (WIFSIGNALED(status))
103 return WTERMSIG(status) + 0x180;
104 return 0;
105}
106
107#if ENABLE_FEATURE_PREFER_APPLETS 73#if ENABLE_FEATURE_PREFER_APPLETS
108void FAST_FUNC save_nofork_data(struct nofork_save_area *save) 74void FAST_FUNC save_nofork_data(struct nofork_save_area *save)
109{ 75{
@@ -252,7 +218,7 @@ void FAST_FUNC re_exec(char **argv)
252 * "we have (already) re-execed, don't do it again" flag */ 218 * "we have (already) re-execed, don't do it again" flag */
253 argv[0][0] |= 0x80; 219 argv[0][0] |= 0x80;
254 execv(bb_busybox_exec_path, argv); 220 execv(bb_busybox_exec_path, argv);
255 bb_perror_msg_and_die("exec %s", bb_busybox_exec_path); 221 bb_perror_msg_and_die("can't execute '%s'", bb_busybox_exec_path);
256} 222}
257 223
258pid_t FAST_FUNC fork_or_rexec(char **argv) 224pid_t FAST_FUNC fork_or_rexec(char **argv)
@@ -261,26 +227,12 @@ pid_t FAST_FUNC fork_or_rexec(char **argv)
261 /* Maybe we are already re-execed and come here again? */ 227 /* Maybe we are already re-execed and come here again? */
262 if (re_execed) 228 if (re_execed)
263 return 0; 229 return 0;
264 pid = vfork(); 230 pid = xvfork();
265 if (pid < 0) /* wtf? */
266 bb_perror_msg_and_die("vfork");
267 if (pid) /* parent */ 231 if (pid) /* parent */
268 return pid; 232 return pid;
269 /* child - re-exec ourself */ 233 /* child - re-exec ourself */
270 re_exec(argv); 234 re_exec(argv);
271} 235}
272#else
273/* Dance around (void)...*/
274#undef fork_or_rexec
275pid_t FAST_FUNC fork_or_rexec(void)
276{
277 pid_t pid;
278 pid = fork();
279 if (pid < 0) /* wtf? */
280 bb_perror_msg_and_die("fork");
281 return pid;
282}
283#define fork_or_rexec(argv) fork_or_rexec()
284#endif 236#endif
285 237
286/* Due to a #define in libbb.h on MMU systems we actually have 1 argument - 238/* Due to a #define in libbb.h on MMU systems we actually have 1 argument -