aboutsummaryrefslogtreecommitdiff
path: root/libbb/vfork_daemon_rexec.c
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-03-24 12:11:17 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-03-24 12:11:17 +0000
commitcf473990ea606ca68613166bdba5ce3f7fdd8e58 (patch)
treeff0a10f5f81fa0e1e719691c147309a9cc9bef46 /libbb/vfork_daemon_rexec.c
parent7c9d2e8b765aed4fe6a5aac5388f14f1133d6da2 (diff)
downloadbusybox-w32-cf473990ea606ca68613166bdba5ce3f7fdd8e58.tar.gz
busybox-w32-cf473990ea606ca68613166bdba5ce3f7fdd8e58.tar.bz2
busybox-w32-cf473990ea606ca68613166bdba5ce3f7fdd8e58.zip
NOMMU re-exec trick shuld not depend on existence of "don't daemonize"
option for every affected applet (and dnsd, for example, don't have one). Thus rework re-exec support to not require it. Code got smaller too. git-svn-id: svn://busybox.net/trunk/busybox@18219 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb/vfork_daemon_rexec.c')
-rw-r--r--libbb/vfork_daemon_rexec.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index 26d1826e0..3185f2d39 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -19,19 +19,18 @@
19#include "libbb.h" 19#include "libbb.h"
20 20
21#ifdef BB_NOMMU 21#ifdef BB_NOMMU
22void vfork_daemon_rexec(int nochdir, int noclose, 22void vfork_daemon_rexec(int nochdir, int noclose, char **argv)
23 int argc, char **argv, char *foreground_opt)
24{ 23{
25 int fd; 24 int fd;
26 char **vfork_args;
27 int a = 0;
28 25
29 setsid(); 26 setsid();
30 27
31 if (!nochdir) 28 if (!nochdir)
32 xchdir("/"); 29 xchdir("/");
33 30
34 if (!noclose && (fd = open(bb_dev_null, O_RDWR, 0)) != -1) { 31 if (!noclose) {
32 /* if "/dev/null" doesn't exist, bail out! */
33 fd = xopen(bb_dev_null, O_RDWR);
35 dup2(fd, STDIN_FILENO); 34 dup2(fd, STDIN_FILENO);
36 dup2(fd, STDOUT_FILENO); 35 dup2(fd, STDOUT_FILENO);
37 dup2(fd, STDERR_FILENO); 36 dup2(fd, STDERR_FILENO);
@@ -39,21 +38,17 @@ void vfork_daemon_rexec(int nochdir, int noclose,
39 close(fd--); 38 close(fd--);
40 } 39 }
41 40
42 vfork_args = xzalloc(sizeof(char *) * (argc + 3));
43 vfork_args[a++] = CONFIG_BUSYBOX_EXEC_PATH;
44 while (*argv) {
45 vfork_args[a++] = *argv;
46 argv++;
47 }
48 vfork_args[a] = foreground_opt;
49 switch (vfork()) { 41 switch (vfork()) {
50 case 0: /* child */ 42 case 0: /* child */
51 /* Make certain we are not a session leader, or else we 43 /* Make certain we are not a session leader, or else we
52 * might reacquire a controlling terminal */ 44 * might reacquire a controlling terminal */
53 if (vfork()) 45 if (vfork())
54 _exit(0); 46 _exit(0);
55 execv(vfork_args[0], vfork_args); 47 /* High-order bit of first char in argv[0] is a hidden
56 bb_perror_msg_and_die("execv %s", vfork_args[0]); 48 * "we have (alrealy) re-execed, don't do it again" flag */
49 argv[0][0] |= 0x80;
50 execv(CONFIG_BUSYBOX_EXEC_PATH, argv);
51 bb_perror_msg_and_die("exec %s", CONFIG_BUSYBOX_EXEC_PATH);
57 case -1: /* error */ 52 case -1: /* error */
58 bb_perror_msg_and_die("vfork"); 53 bb_perror_msg_and_die("vfork");
59 default: /* parent */ 54 default: /* parent */