}
*--argv = startas;
if (opt & OPT_BACKGROUND) {
- setsid();
- bb_daemonize();
+ bb_daemonize(0);
}
if (opt & OPT_MAKEPID) {
/* user wants _us_ to make the pidfile */
{
unsigned opt;
char *lopt, *Lopt, *copt;
+ USE_DEBUG_CROND_OPTION(char *dopt;)
-#if ENABLE_DEBUG_CROND_OPTION
- char *dopt;
-
- opt_complementary = "f-b:b-f:S-L:L-S:d-l";
-#else
- opt_complementary = "f-b:b-f:S-L:L-S";
-#endif
-
+ opt_complementary = "f-b:b-f:S-L:L-S" USE_DEBUG_CROND_OPTION(":d-l");
opterr = 0; /* disable getopt 'errors' message. */
- opt = getopt32(ac, av, "l:L:fbSc:"
-#if ENABLE_DEBUG_CROND_OPTION
- "d:"
-#endif
- , &lopt, &Lopt, &copt
-#if ENABLE_DEBUG_CROND_OPTION
- , &dopt
-#endif
- );
- if (opt & 1) {
+ opt = getopt32(ac, av, "l:L:fbSc:" USE_DEBUG_CROND_OPTION("d:"),
+ &lopt, &Lopt, &copt USE_DEBUG_CROND_OPTION(, &dopt));
+ if (opt & 1) /* -l */
LogLevel = xatou(lopt);
- }
- if (opt & 2) {
- if (*Lopt != 0) {
+ if (opt & 2) /* -L */
+ if (*Lopt)
LogFile = Lopt;
- }
- }
- if (opt & 32) {
- if (*copt != 0) {
+ if (opt & 32) /* -c */
+ if (*copt)
CDir = copt;
- }
- }
#if ENABLE_DEBUG_CROND_OPTION
- if (opt & 64) {
+ if (opt & 64) { /* -d */
DebugOpt = xatou(dopt);
LogLevel = 0;
}
#endif
- /*
- * change directory
- */
-
- xchdir(CDir);
- signal(SIGHUP, SIG_IGN); /* hmm.. but, if kill -HUP original
- * version - his died. ;(
- */
- /*
- * close stdin and stdout, stderr.
+ /* close stdin and stdout, stderr.
* close unused descriptors - don't need.
* optional detach from controlling terminal
*/
+ if (!(opt & 4))
+ bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, av);
- if (!(opt & 4)) {
-#ifdef BB_NOMMU
- if (!re_execed)
- vfork_daemon_rexec(1, 0, av);
-#else
- xdaemon(1, 0);
-#endif
- }
+ xchdir(CDir);
+ signal(SIGHUP, SIG_IGN); /* ? original crond dies on HUP... */
- (void) startlogger(); /* need if syslog mode selected */
+ startlogger(); /* need if syslog mode selected */
/*
* main loop - synchronize to 1 second after the minute, minimum sleep
* of 1 second.
*/
-
crondlog("\011%s " VERSION " dillon, started, log level %d\n",
applet_name, LogLevel);
unsigned timer_duration = 30; /* Userspace timer duration, in seconds */
char *t_arg;
+ opt_complementary = "=1"; /* must have 1 argument */
opts = getopt32(argc, argv, "Ft:", &t_arg);
if (opts & OPT_TIMER)
timer_duration = xatou(t_arg);
- /* We're only interested in the watchdog device .. */
- if (optind < argc - 1 || argc == 1)
- bb_show_usage();
-
if (!(opts & OPT_FOREGROUND)) {
-#ifdef BB_NOMMU
- if (!re_execed)
- vfork_daemon_rexec(0, 1, argv);
-#else
- xdaemon(0, 1);
-#endif
+ bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
}
signal(SIGHUP, watchdog_shutdown);
signal(SIGINT, watchdog_shutdown);
/* Use known fd # - avoid needing global 'int fd' */
- dup2(xopen(argv[argc - 1], O_WRONLY), 3);
+ xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3);
while (1) {
/*
}
watchdog_shutdown(0);
-
/* return EXIT_SUCCESS; */
}
}
if (OPT_daemon) {
-#ifdef BB_NOMMU
- if (!re_execed)
- vfork_daemon_rexec(1, 0, argv);
-#else
- xdaemon(1, 0);
-#endif
+ bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv);
openlog(applet_name, LOG_PID, LOG_DAEMON);
logmode = LOGMODE_SYSLOG;
}
return miniHttpd_inetd();
if (!(opt & OPT_FOREGROUND))
- xdaemon(1, 0); /* don't change current directory */
+ bb_daemonize(0); /* don't change current directory */
return miniHttpd(config->server_socket);
}
LastArg = envp[-1] + strlen(envp[-1]);
#endif
- opt = getopt32(argc, argv, "R:f", &stoomany);
- if(opt & 1) {
- toomany = xatoi_u(stoomany);
- }
- argc -= optind;
- argv += optind;
-
uid = getuid();
if (uid != 0)
config_filename = NULL;
- if (argc > 0)
+
+ opt = getopt32(argc, argv, "R:f", &stoomany);
+ if (opt & 1)
+ toomany = xatoi_u(stoomany);
+ argv += optind;
+ argc -= optind;
+ if (argc)
config_filename = argv[0];
if (config_filename == NULL)
bb_error_msg_and_die("non-root must specify a config file");
-#ifdef BB_NOMMU
- if (!(opt & 2)) {
- if (!re_execed)
- vfork_daemon_rexec(0, 0, argv);
- }
- bb_sanitize_stdio();
-#else
- bb_sanitize_stdio_maybe_daemonize(!(opt & 2));
-#endif
+ if (!(opt & 2))
+ bb_daemonize_or_rexec(0, argv - optind);
+ else
+ bb_sanitize_stdio();
openlog(applet_name, LOG_PID | LOG_NOWAIT, LOG_DAEMON);
logmode = LOGMODE_SYSLOG;
bogouser = argv[optind];
/* Daemonize if no -f and no -i and no -w */
- bb_sanitize_stdio_maybe_daemonize(!(opt & OPT_fiw));
+ if (!(opt & OPT_fiw));
+ bb_daemonize_or_rexec(0, argv);
+
/* Where to log in inetd modes? "Classic" inetd
* probably has its stderr /dev/null'ed (we need log to syslog?),
* but daemontools-like utilities usually expect that children
master_fd = create_and_bind_stream_or_die(opt_bindaddr, portnbr);
xlisten(master_fd, 1);
if (!(opt & OPT_FOREGROUND))
- xdaemon(0, 0);
+ bb_daemonize(DAEMON_CHDIR_ROOT);
}
#else
sessions = make_new_session();
// daemonize now; don't delay system startup
if (!FOREGROUND) {
- /* bb_daemonize(); - bad, will close fd! */
//NOMMU
- xdaemon(0, 0);
+ bb_daemonize(DAEMON_CHDIR_ROOT);
bb_info_msg("start, interface %s", intf);
}
}
if (!(option_mask32 & OPT_FOREGROUND)) {
-#ifdef BB_NOMMU
- if (!re_execed)
- vfork_daemon_rexec(0, 1, argv);
-#else
- bb_daemonize();
-#endif
+ bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
}
openlog("kernel", 0, LOG_KERN);
}
if (!(option_mask32 & OPT_nofork)) {
-#ifdef BB_NOMMU
- if (!re_execed)
- vfork_daemon_rexec(0, 1, argv);
-#else
- bb_daemonize();
-#endif
+ bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
}
umask(0);
do_syslogd();