aboutsummaryrefslogtreecommitdiff
path: root/libbb/vfork_daemon_rexec.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-03-20 22:17:13 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-03-20 22:17:13 +0000
commit83518d18a34a3ddfcaac1739930d8469f5bc2442 (patch)
tree2af665365a69f2689288cc13bb65efbb59e7d520 /libbb/vfork_daemon_rexec.c
parent0b28103cc774eb1ee62362cf61d52c32d44ec2cf (diff)
downloadbusybox-w32-83518d18a34a3ddfcaac1739930d8469f5bc2442.tar.gz
busybox-w32-83518d18a34a3ddfcaac1739930d8469f5bc2442.tar.bz2
busybox-w32-83518d18a34a3ddfcaac1739930d8469f5bc2442.zip
Compatibility fixes:
grep: support -z find: support --mindepth together +45 bytes cpio: support -p (configurable, +230 bytes) libbb: tweaks for cpio
Diffstat (limited to 'libbb/vfork_daemon_rexec.c')
-rw-r--r--libbb/vfork_daemon_rexec.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index 50dc3affe..f64239a96 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -251,35 +251,33 @@ void FAST_FUNC re_exec(char **argv)
251 bb_perror_msg_and_die("exec %s", bb_busybox_exec_path); 251 bb_perror_msg_and_die("exec %s", bb_busybox_exec_path);
252} 252}
253 253
254void FAST_FUNC forkexit_or_rexec(char **argv) 254pid_t FAST_FUNC fork_or_rexec(char **argv)
255{ 255{
256 pid_t pid; 256 pid_t pid;
257 /* Maybe we are already re-execed and come here again? */ 257 /* Maybe we are already re-execed and come here again? */
258 if (re_execed) 258 if (re_execed)
259 return; 259 return 0; /* child */
260 260
261 pid = vfork(); 261 pid = vfork();
262 if (pid < 0) /* wtf? */ 262 if (pid < 0) /* wtf? */
263 bb_perror_msg_and_die("vfork"); 263 bb_perror_msg_and_die("vfork");
264 if (pid) /* parent */ 264 if (pid) /* parent */
265 exit(EXIT_SUCCESS); 265 return pid;
266 /* child - re-exec ourself */ 266 /* child - re-exec ourself */
267 re_exec(argv); 267 re_exec(argv);
268} 268}
269#else 269#else
270/* Dance around (void)...*/ 270/* Dance around (void)...*/
271#undef forkexit_or_rexec 271#undef fork_or_rexec
272void FAST_FUNC forkexit_or_rexec(void) 272pid_t FAST_FUNC fork_or_rexec(void)
273{ 273{
274 pid_t pid; 274 pid_t pid;
275 pid = fork(); 275 pid = fork();
276 if (pid < 0) /* wtf? */ 276 if (pid < 0) /* wtf? */
277 bb_perror_msg_and_die("fork"); 277 bb_perror_msg_and_die("fork");
278 if (pid) /* parent */ 278 return pid;
279 exit(EXIT_SUCCESS);
280 /* child */
281} 279}
282#define forkexit_or_rexec(argv) forkexit_or_rexec() 280#define fork_or_rexec(argv) fork_or_rexec()
283#endif 281#endif
284 282
285/* Due to a #define in libbb.h on MMU systems we actually have 1 argument - 283/* Due to a #define in libbb.h on MMU systems we actually have 1 argument -
@@ -310,7 +308,8 @@ void FAST_FUNC bb_daemonize_or_rexec(int flags, char **argv)
310 fd = dup(fd); /* have 0,1,2 open at least to /dev/null */ 308 fd = dup(fd); /* have 0,1,2 open at least to /dev/null */
311 309
312 if (!(flags & DAEMON_ONLY_SANITIZE)) { 310 if (!(flags & DAEMON_ONLY_SANITIZE)) {
313 forkexit_or_rexec(argv); 311 if (fork_or_rexec(argv))
312 exit(EXIT_SUCCESS); /* parent */
314 /* if daemonizing, make sure we detach from stdio & ctty */ 313 /* if daemonizing, make sure we detach from stdio & ctty */
315 setsid(); 314 setsid();
316 dup2(fd, 0); 315 dup2(fd, 0);