aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-03-26 13:20:54 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-03-26 13:20:54 +0000
commit25780f7e6377a2d827e5ffad7a8701c0f14fe1aa (patch)
tree19d222f7d7040945cf92e239055dfdd00b8656bc
parent922db9aa31d3d21cbfa631ee88b7159f34319cc2 (diff)
downloadbusybox-w32-25780f7e6377a2d827e5ffad7a8701c0f14fe1aa.tar.gz
busybox-w32-25780f7e6377a2d827e5ffad7a8701c0f14fe1aa.tar.bz2
busybox-w32-25780f7e6377a2d827e5ffad7a8701c0f14fe1aa.zip
move everything to new NOMMU helpers, except udhcp
git-svn-id: svn://busybox.net/trunk/busybox@18242 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--debianutils/start_stop_daemon.c3
-rw-r--r--miscutils/crond.c64
-rw-r--r--miscutils/watchdog.c15
-rw-r--r--networking/dnsd.c7
-rw-r--r--networking/httpd.c2
-rw-r--r--networking/inetd.c28
-rw-r--r--networking/isrv_identd.c4
-rw-r--r--networking/telnetd.c2
-rw-r--r--networking/zcip.c3
-rw-r--r--sysklogd/klogd.c7
-rw-r--r--sysklogd/syslogd.c7
11 files changed, 40 insertions, 102 deletions
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c
index 1862f113d..60a78793e 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/start_stop_daemon.c
@@ -299,8 +299,7 @@ int start_stop_daemon_main(int argc, char **argv)
299 } 299 }
300 *--argv = startas; 300 *--argv = startas;
301 if (opt & OPT_BACKGROUND) { 301 if (opt & OPT_BACKGROUND) {
302 setsid(); 302 bb_daemonize(0);
303 bb_daemonize();
304 } 303 }
305 if (opt & OPT_MAKEPID) { 304 if (opt & OPT_MAKEPID) {
306 /* user wants _us_ to make the pidfile */ 305 /* user wants _us_ to make the pidfile */
diff --git a/miscutils/crond.c b/miscutils/crond.c
index 1ab0038e0..9d511f960 100644
--- a/miscutils/crond.c
+++ b/miscutils/crond.c
@@ -136,75 +136,43 @@ int crond_main(int ac, char **av)
136{ 136{
137 unsigned opt; 137 unsigned opt;
138 char *lopt, *Lopt, *copt; 138 char *lopt, *Lopt, *copt;
139 USE_DEBUG_CROND_OPTION(char *dopt;)
139 140
140#if ENABLE_DEBUG_CROND_OPTION 141 opt_complementary = "f-b:b-f:S-L:L-S" USE_DEBUG_CROND_OPTION(":d-l");
141 char *dopt;
142
143 opt_complementary = "f-b:b-f:S-L:L-S:d-l";
144#else
145 opt_complementary = "f-b:b-f:S-L:L-S";
146#endif
147
148 opterr = 0; /* disable getopt 'errors' message. */ 142 opterr = 0; /* disable getopt 'errors' message. */
149 opt = getopt32(ac, av, "l:L:fbSc:" 143 opt = getopt32(ac, av, "l:L:fbSc:" USE_DEBUG_CROND_OPTION("d:"),
150#if ENABLE_DEBUG_CROND_OPTION 144 &lopt, &Lopt, &copt USE_DEBUG_CROND_OPTION(, &dopt));
151 "d:" 145 if (opt & 1) /* -l */
152#endif
153 , &lopt, &Lopt, &copt
154#if ENABLE_DEBUG_CROND_OPTION
155 , &dopt
156#endif
157 );
158 if (opt & 1) {
159 LogLevel = xatou(lopt); 146 LogLevel = xatou(lopt);
160 } 147 if (opt & 2) /* -L */
161 if (opt & 2) { 148 if (*Lopt)
162 if (*Lopt != 0) {
163 LogFile = Lopt; 149 LogFile = Lopt;
164 } 150 if (opt & 32) /* -c */
165 } 151 if (*copt)
166 if (opt & 32) {
167 if (*copt != 0) {
168 CDir = copt; 152 CDir = copt;
169 }
170 }
171#if ENABLE_DEBUG_CROND_OPTION 153#if ENABLE_DEBUG_CROND_OPTION
172 if (opt & 64) { 154 if (opt & 64) { /* -d */
173 DebugOpt = xatou(dopt); 155 DebugOpt = xatou(dopt);
174 LogLevel = 0; 156 LogLevel = 0;
175 } 157 }
176#endif 158#endif
177 159
178 /* 160 /* close stdin and stdout, stderr.
179 * change directory
180 */
181
182 xchdir(CDir);
183 signal(SIGHUP, SIG_IGN); /* hmm.. but, if kill -HUP original
184 * version - his died. ;(
185 */
186 /*
187 * close stdin and stdout, stderr.
188 * close unused descriptors - don't need. 161 * close unused descriptors - don't need.
189 * optional detach from controlling terminal 162 * optional detach from controlling terminal
190 */ 163 */
164 if (!(opt & 4))
165 bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, av);
191 166
192 if (!(opt & 4)) { 167 xchdir(CDir);
193#ifdef BB_NOMMU 168 signal(SIGHUP, SIG_IGN); /* ? original crond dies on HUP... */
194 if (!re_execed)
195 vfork_daemon_rexec(1, 0, av);
196#else
197 xdaemon(1, 0);
198#endif
199 }
200 169
201 (void) startlogger(); /* need if syslog mode selected */ 170 startlogger(); /* need if syslog mode selected */
202 171
203 /* 172 /*
204 * main loop - synchronize to 1 second after the minute, minimum sleep 173 * main loop - synchronize to 1 second after the minute, minimum sleep
205 * of 1 second. 174 * of 1 second.
206 */ 175 */
207
208 crondlog("\011%s " VERSION " dillon, started, log level %d\n", 176 crondlog("\011%s " VERSION " dillon, started, log level %d\n",
209 applet_name, LogLevel); 177 applet_name, LogLevel);
210 178
diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c
index e3d77d17e..28ae9bdb0 100644
--- a/miscutils/watchdog.c
+++ b/miscutils/watchdog.c
@@ -29,29 +29,21 @@ int watchdog_main(int argc, char **argv)
29 unsigned timer_duration = 30; /* Userspace timer duration, in seconds */ 29 unsigned timer_duration = 30; /* Userspace timer duration, in seconds */
30 char *t_arg; 30 char *t_arg;
31 31
32 opt_complementary = "=1"; /* must have 1 argument */
32 opts = getopt32(argc, argv, "Ft:", &t_arg); 33 opts = getopt32(argc, argv, "Ft:", &t_arg);
33 34
34 if (opts & OPT_TIMER) 35 if (opts & OPT_TIMER)
35 timer_duration = xatou(t_arg); 36 timer_duration = xatou(t_arg);
36 37
37 /* We're only interested in the watchdog device .. */
38 if (optind < argc - 1 || argc == 1)
39 bb_show_usage();
40
41 if (!(opts & OPT_FOREGROUND)) { 38 if (!(opts & OPT_FOREGROUND)) {
42#ifdef BB_NOMMU 39 bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
43 if (!re_execed)
44 vfork_daemon_rexec(0, 1, argv);
45#else
46 xdaemon(0, 1);
47#endif
48 } 40 }
49 41
50 signal(SIGHUP, watchdog_shutdown); 42 signal(SIGHUP, watchdog_shutdown);
51 signal(SIGINT, watchdog_shutdown); 43 signal(SIGINT, watchdog_shutdown);
52 44
53 /* Use known fd # - avoid needing global 'int fd' */ 45 /* Use known fd # - avoid needing global 'int fd' */
54 dup2(xopen(argv[argc - 1], O_WRONLY), 3); 46 xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3);
55 47
56 while (1) { 48 while (1) {
57 /* 49 /*
@@ -63,6 +55,5 @@ int watchdog_main(int argc, char **argv)
63 } 55 }
64 56
65 watchdog_shutdown(0); 57 watchdog_shutdown(0);
66
67 /* return EXIT_SUCCESS; */ 58 /* return EXIT_SUCCESS; */
68} 59}
diff --git a/networking/dnsd.c b/networking/dnsd.c
index c9c7b3a7c..8807bbedc 100644
--- a/networking/dnsd.c
+++ b/networking/dnsd.c
@@ -353,12 +353,7 @@ int dnsd_main(int argc, char **argv)
353 } 353 }
354 354
355 if (OPT_daemon) { 355 if (OPT_daemon) {
356#ifdef BB_NOMMU 356 bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv);
357 if (!re_execed)
358 vfork_daemon_rexec(1, 0, argv);
359#else
360 xdaemon(1, 0);
361#endif
362 openlog(applet_name, LOG_PID, LOG_DAEMON); 357 openlog(applet_name, LOG_PID, LOG_DAEMON);
363 logmode = LOGMODE_SYSLOG; 358 logmode = LOGMODE_SYSLOG;
364 } 359 }
diff --git a/networking/httpd.c b/networking/httpd.c
index 72b03de79..b8d9b6b6f 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -2044,6 +2044,6 @@ int httpd_main(int argc, char *argv[])
2044 return miniHttpd_inetd(); 2044 return miniHttpd_inetd();
2045 2045
2046 if (!(opt & OPT_FOREGROUND)) 2046 if (!(opt & OPT_FOREGROUND))
2047 xdaemon(1, 0); /* don't change current directory */ 2047 bb_daemonize(0); /* don't change current directory */
2048 return miniHttpd(config->server_socket); 2048 return miniHttpd(config->server_socket);
2049} 2049}
diff --git a/networking/inetd.c b/networking/inetd.c
index 83123463f..4faa4203a 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -1274,30 +1274,24 @@ int inetd_main(int argc, char *argv[])
1274 LastArg = envp[-1] + strlen(envp[-1]); 1274 LastArg = envp[-1] + strlen(envp[-1]);
1275#endif 1275#endif
1276 1276
1277 opt = getopt32(argc, argv, "R:f", &stoomany);
1278 if(opt & 1) {
1279 toomany = xatoi_u(stoomany);
1280 }
1281 argc -= optind;
1282 argv += optind;
1283
1284 uid = getuid(); 1277 uid = getuid();
1285 if (uid != 0) 1278 if (uid != 0)
1286 config_filename = NULL; 1279 config_filename = NULL;
1287 if (argc > 0) 1280
1281 opt = getopt32(argc, argv, "R:f", &stoomany);
1282 if (opt & 1)
1283 toomany = xatoi_u(stoomany);
1284 argv += optind;
1285 argc -= optind;
1286 if (argc)
1288 config_filename = argv[0]; 1287 config_filename = argv[0];
1289 if (config_filename == NULL) 1288 if (config_filename == NULL)
1290 bb_error_msg_and_die("non-root must specify a config file"); 1289 bb_error_msg_and_die("non-root must specify a config file");
1291 1290
1292#ifdef BB_NOMMU 1291 if (!(opt & 2))
1293 if (!(opt & 2)) { 1292 bb_daemonize_or_rexec(0, argv - optind);
1294 if (!re_execed) 1293 else
1295 vfork_daemon_rexec(0, 0, argv); 1294 bb_sanitize_stdio();
1296 }
1297 bb_sanitize_stdio();
1298#else
1299 bb_sanitize_stdio_maybe_daemonize(!(opt & 2));
1300#endif
1301 openlog(applet_name, LOG_PID | LOG_NOWAIT, LOG_DAEMON); 1295 openlog(applet_name, LOG_PID | LOG_NOWAIT, LOG_DAEMON);
1302 logmode = LOGMODE_SYSLOG; 1296 logmode = LOGMODE_SYSLOG;
1303 1297
diff --git a/networking/isrv_identd.c b/networking/isrv_identd.c
index f9ab0b2c0..c230c7ec3 100644
--- a/networking/isrv_identd.c
+++ b/networking/isrv_identd.c
@@ -112,7 +112,9 @@ int fakeidentd_main(int argc, char **argv)
112 bogouser = argv[optind]; 112 bogouser = argv[optind];
113 113
114 /* Daemonize if no -f and no -i and no -w */ 114 /* Daemonize if no -f and no -i and no -w */
115 bb_sanitize_stdio_maybe_daemonize(!(opt & OPT_fiw)); 115 if (!(opt & OPT_fiw));
116 bb_daemonize_or_rexec(0, argv);
117
116 /* Where to log in inetd modes? "Classic" inetd 118 /* Where to log in inetd modes? "Classic" inetd
117 * probably has its stderr /dev/null'ed (we need log to syslog?), 119 * probably has its stderr /dev/null'ed (we need log to syslog?),
118 * but daemontools-like utilities usually expect that children 120 * but daemontools-like utilities usually expect that children
diff --git a/networking/telnetd.c b/networking/telnetd.c
index ef9b1ac74..5c0463bab 100644
--- a/networking/telnetd.c
+++ b/networking/telnetd.c
@@ -415,7 +415,7 @@ int telnetd_main(int argc, char **argv)
415 master_fd = create_and_bind_stream_or_die(opt_bindaddr, portnbr); 415 master_fd = create_and_bind_stream_or_die(opt_bindaddr, portnbr);
416 xlisten(master_fd, 1); 416 xlisten(master_fd, 1);
417 if (!(opt & OPT_FOREGROUND)) 417 if (!(opt & OPT_FOREGROUND))
418 xdaemon(0, 0); 418 bb_daemonize(DAEMON_CHDIR_ROOT);
419 } 419 }
420#else 420#else
421 sessions = make_new_session(); 421 sessions = make_new_session();
diff --git a/networking/zcip.c b/networking/zcip.c
index c50d5abaf..c0cf665dd 100644
--- a/networking/zcip.c
+++ b/networking/zcip.c
@@ -271,9 +271,8 @@ int zcip_main(int argc, char *argv[])
271 271
272 // daemonize now; don't delay system startup 272 // daemonize now; don't delay system startup
273 if (!FOREGROUND) { 273 if (!FOREGROUND) {
274 /* bb_daemonize(); - bad, will close fd! */
275//NOMMU 274//NOMMU
276 xdaemon(0, 0); 275 bb_daemonize(DAEMON_CHDIR_ROOT);
277 bb_info_msg("start, interface %s", intf); 276 bb_info_msg("start, interface %s", intf);
278 } 277 }
279 278
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c
index fc0ed3037..62425394c 100644
--- a/sysklogd/klogd.c
+++ b/sysklogd/klogd.c
@@ -50,12 +50,7 @@ int klogd_main(int argc, char **argv)
50 } 50 }
51 51
52 if (!(option_mask32 & OPT_FOREGROUND)) { 52 if (!(option_mask32 & OPT_FOREGROUND)) {
53#ifdef BB_NOMMU 53 bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
54 if (!re_execed)
55 vfork_daemon_rexec(0, 1, argv);
56#else
57 bb_daemonize();
58#endif
59 } 54 }
60 55
61 openlog("kernel", 0, LOG_KERN); 56 openlog("kernel", 0, LOG_KERN);
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index 437212372..51627bd82 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -642,12 +642,7 @@ int syslogd_main(int argc, char **argv)
642 } 642 }
643 643
644 if (!(option_mask32 & OPT_nofork)) { 644 if (!(option_mask32 & OPT_nofork)) {
645#ifdef BB_NOMMU 645 bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
646 if (!re_execed)
647 vfork_daemon_rexec(0, 1, argv);
648#else
649 bb_daemonize();
650#endif
651 } 646 }
652 umask(0); 647 umask(0);
653 do_syslogd(); 648 do_syslogd();