move everything to new NOMMU helpers, except udhcp
This commit is contained in:
parent
bb7fcb4229
commit
5a142025d3
@ -299,8 +299,7 @@ int start_stop_daemon_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
*--argv = startas;
|
*--argv = startas;
|
||||||
if (opt & OPT_BACKGROUND) {
|
if (opt & OPT_BACKGROUND) {
|
||||||
setsid();
|
bb_daemonize(0);
|
||||||
bb_daemonize();
|
|
||||||
}
|
}
|
||||||
if (opt & OPT_MAKEPID) {
|
if (opt & OPT_MAKEPID) {
|
||||||
/* user wants _us_ to make the pidfile */
|
/* user wants _us_ to make the pidfile */
|
||||||
|
@ -136,75 +136,43 @@ int crond_main(int ac, char **av)
|
|||||||
{
|
{
|
||||||
unsigned opt;
|
unsigned opt;
|
||||||
char *lopt, *Lopt, *copt;
|
char *lopt, *Lopt, *copt;
|
||||||
|
USE_DEBUG_CROND_OPTION(char *dopt;)
|
||||||
|
|
||||||
#if ENABLE_DEBUG_CROND_OPTION
|
opt_complementary = "f-b:b-f:S-L:L-S" USE_DEBUG_CROND_OPTION(":d-l");
|
||||||
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
|
|
||||||
|
|
||||||
opterr = 0; /* disable getopt 'errors' message. */
|
opterr = 0; /* disable getopt 'errors' message. */
|
||||||
opt = getopt32(ac, av, "l:L:fbSc:"
|
opt = getopt32(ac, av, "l:L:fbSc:" USE_DEBUG_CROND_OPTION("d:"),
|
||||||
#if ENABLE_DEBUG_CROND_OPTION
|
&lopt, &Lopt, &copt USE_DEBUG_CROND_OPTION(, &dopt));
|
||||||
"d:"
|
if (opt & 1) /* -l */
|
||||||
#endif
|
|
||||||
, &lopt, &Lopt, &copt
|
|
||||||
#if ENABLE_DEBUG_CROND_OPTION
|
|
||||||
, &dopt
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
if (opt & 1) {
|
|
||||||
LogLevel = xatou(lopt);
|
LogLevel = xatou(lopt);
|
||||||
}
|
if (opt & 2) /* -L */
|
||||||
if (opt & 2) {
|
if (*Lopt)
|
||||||
if (*Lopt != 0) {
|
|
||||||
LogFile = Lopt;
|
LogFile = Lopt;
|
||||||
}
|
if (opt & 32) /* -c */
|
||||||
}
|
if (*copt)
|
||||||
if (opt & 32) {
|
|
||||||
if (*copt != 0) {
|
|
||||||
CDir = copt;
|
CDir = copt;
|
||||||
}
|
|
||||||
}
|
|
||||||
#if ENABLE_DEBUG_CROND_OPTION
|
#if ENABLE_DEBUG_CROND_OPTION
|
||||||
if (opt & 64) {
|
if (opt & 64) { /* -d */
|
||||||
DebugOpt = xatou(dopt);
|
DebugOpt = xatou(dopt);
|
||||||
LogLevel = 0;
|
LogLevel = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/* close stdin and stdout, stderr.
|
||||||
* change directory
|
|
||||||
*/
|
|
||||||
|
|
||||||
xchdir(CDir);
|
|
||||||
signal(SIGHUP, SIG_IGN); /* hmm.. but, if kill -HUP original
|
|
||||||
* version - his died. ;(
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* close stdin and stdout, stderr.
|
|
||||||
* close unused descriptors - don't need.
|
* close unused descriptors - don't need.
|
||||||
* optional detach from controlling terminal
|
* optional detach from controlling terminal
|
||||||
*/
|
*/
|
||||||
|
if (!(opt & 4))
|
||||||
|
bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, av);
|
||||||
|
|
||||||
if (!(opt & 4)) {
|
xchdir(CDir);
|
||||||
#ifdef BB_NOMMU
|
signal(SIGHUP, SIG_IGN); /* ? original crond dies on HUP... */
|
||||||
if (!re_execed)
|
|
||||||
vfork_daemon_rexec(1, 0, av);
|
|
||||||
#else
|
|
||||||
xdaemon(1, 0);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
(void) startlogger(); /* need if syslog mode selected */
|
startlogger(); /* need if syslog mode selected */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* main loop - synchronize to 1 second after the minute, minimum sleep
|
* main loop - synchronize to 1 second after the minute, minimum sleep
|
||||||
* of 1 second.
|
* of 1 second.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
crondlog("\011%s " VERSION " dillon, started, log level %d\n",
|
crondlog("\011%s " VERSION " dillon, started, log level %d\n",
|
||||||
applet_name, LogLevel);
|
applet_name, LogLevel);
|
||||||
|
|
||||||
|
@ -29,29 +29,21 @@ int watchdog_main(int argc, char **argv)
|
|||||||
unsigned timer_duration = 30; /* Userspace timer duration, in seconds */
|
unsigned timer_duration = 30; /* Userspace timer duration, in seconds */
|
||||||
char *t_arg;
|
char *t_arg;
|
||||||
|
|
||||||
|
opt_complementary = "=1"; /* must have 1 argument */
|
||||||
opts = getopt32(argc, argv, "Ft:", &t_arg);
|
opts = getopt32(argc, argv, "Ft:", &t_arg);
|
||||||
|
|
||||||
if (opts & OPT_TIMER)
|
if (opts & OPT_TIMER)
|
||||||
timer_duration = xatou(t_arg);
|
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)) {
|
if (!(opts & OPT_FOREGROUND)) {
|
||||||
#ifdef BB_NOMMU
|
bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
|
||||||
if (!re_execed)
|
|
||||||
vfork_daemon_rexec(0, 1, argv);
|
|
||||||
#else
|
|
||||||
xdaemon(0, 1);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
signal(SIGHUP, watchdog_shutdown);
|
signal(SIGHUP, watchdog_shutdown);
|
||||||
signal(SIGINT, watchdog_shutdown);
|
signal(SIGINT, watchdog_shutdown);
|
||||||
|
|
||||||
/* Use known fd # - avoid needing global 'int fd' */
|
/* 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) {
|
while (1) {
|
||||||
/*
|
/*
|
||||||
@ -63,6 +55,5 @@ int watchdog_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
watchdog_shutdown(0);
|
watchdog_shutdown(0);
|
||||||
|
|
||||||
/* return EXIT_SUCCESS; */
|
/* return EXIT_SUCCESS; */
|
||||||
}
|
}
|
||||||
|
@ -353,12 +353,7 @@ int dnsd_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (OPT_daemon) {
|
if (OPT_daemon) {
|
||||||
#ifdef BB_NOMMU
|
bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv);
|
||||||
if (!re_execed)
|
|
||||||
vfork_daemon_rexec(1, 0, argv);
|
|
||||||
#else
|
|
||||||
xdaemon(1, 0);
|
|
||||||
#endif
|
|
||||||
openlog(applet_name, LOG_PID, LOG_DAEMON);
|
openlog(applet_name, LOG_PID, LOG_DAEMON);
|
||||||
logmode = LOGMODE_SYSLOG;
|
logmode = LOGMODE_SYSLOG;
|
||||||
}
|
}
|
||||||
|
@ -2044,6 +2044,6 @@ int httpd_main(int argc, char *argv[])
|
|||||||
return miniHttpd_inetd();
|
return miniHttpd_inetd();
|
||||||
|
|
||||||
if (!(opt & OPT_FOREGROUND))
|
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);
|
return miniHttpd(config->server_socket);
|
||||||
}
|
}
|
||||||
|
@ -1274,30 +1274,24 @@ int inetd_main(int argc, char *argv[])
|
|||||||
LastArg = envp[-1] + strlen(envp[-1]);
|
LastArg = envp[-1] + strlen(envp[-1]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
opt = getopt32(argc, argv, "R:f", &stoomany);
|
|
||||||
if(opt & 1) {
|
|
||||||
toomany = xatoi_u(stoomany);
|
|
||||||
}
|
|
||||||
argc -= optind;
|
|
||||||
argv += optind;
|
|
||||||
|
|
||||||
uid = getuid();
|
uid = getuid();
|
||||||
if (uid != 0)
|
if (uid != 0)
|
||||||
config_filename = NULL;
|
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];
|
config_filename = argv[0];
|
||||||
if (config_filename == NULL)
|
if (config_filename == NULL)
|
||||||
bb_error_msg_and_die("non-root must specify a config file");
|
bb_error_msg_and_die("non-root must specify a config file");
|
||||||
|
|
||||||
#ifdef BB_NOMMU
|
if (!(opt & 2))
|
||||||
if (!(opt & 2)) {
|
bb_daemonize_or_rexec(0, argv - optind);
|
||||||
if (!re_execed)
|
else
|
||||||
vfork_daemon_rexec(0, 0, argv);
|
bb_sanitize_stdio();
|
||||||
}
|
|
||||||
bb_sanitize_stdio();
|
|
||||||
#else
|
|
||||||
bb_sanitize_stdio_maybe_daemonize(!(opt & 2));
|
|
||||||
#endif
|
|
||||||
openlog(applet_name, LOG_PID | LOG_NOWAIT, LOG_DAEMON);
|
openlog(applet_name, LOG_PID | LOG_NOWAIT, LOG_DAEMON);
|
||||||
logmode = LOGMODE_SYSLOG;
|
logmode = LOGMODE_SYSLOG;
|
||||||
|
|
||||||
|
@ -112,7 +112,9 @@ int fakeidentd_main(int argc, char **argv)
|
|||||||
bogouser = argv[optind];
|
bogouser = argv[optind];
|
||||||
|
|
||||||
/* Daemonize if no -f and no -i and no -w */
|
/* 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
|
/* Where to log in inetd modes? "Classic" inetd
|
||||||
* probably has its stderr /dev/null'ed (we need log to syslog?),
|
* probably has its stderr /dev/null'ed (we need log to syslog?),
|
||||||
* but daemontools-like utilities usually expect that children
|
* but daemontools-like utilities usually expect that children
|
||||||
|
@ -415,7 +415,7 @@ int telnetd_main(int argc, char **argv)
|
|||||||
master_fd = create_and_bind_stream_or_die(opt_bindaddr, portnbr);
|
master_fd = create_and_bind_stream_or_die(opt_bindaddr, portnbr);
|
||||||
xlisten(master_fd, 1);
|
xlisten(master_fd, 1);
|
||||||
if (!(opt & OPT_FOREGROUND))
|
if (!(opt & OPT_FOREGROUND))
|
||||||
xdaemon(0, 0);
|
bb_daemonize(DAEMON_CHDIR_ROOT);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
sessions = make_new_session();
|
sessions = make_new_session();
|
||||||
|
@ -271,9 +271,8 @@ int zcip_main(int argc, char *argv[])
|
|||||||
|
|
||||||
// daemonize now; don't delay system startup
|
// daemonize now; don't delay system startup
|
||||||
if (!FOREGROUND) {
|
if (!FOREGROUND) {
|
||||||
/* bb_daemonize(); - bad, will close fd! */
|
|
||||||
//NOMMU
|
//NOMMU
|
||||||
xdaemon(0, 0);
|
bb_daemonize(DAEMON_CHDIR_ROOT);
|
||||||
bb_info_msg("start, interface %s", intf);
|
bb_info_msg("start, interface %s", intf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,12 +50,7 @@ int klogd_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(option_mask32 & OPT_FOREGROUND)) {
|
if (!(option_mask32 & OPT_FOREGROUND)) {
|
||||||
#ifdef BB_NOMMU
|
bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
|
||||||
if (!re_execed)
|
|
||||||
vfork_daemon_rexec(0, 1, argv);
|
|
||||||
#else
|
|
||||||
bb_daemonize();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
openlog("kernel", 0, LOG_KERN);
|
openlog("kernel", 0, LOG_KERN);
|
||||||
|
@ -642,12 +642,7 @@ int syslogd_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(option_mask32 & OPT_nofork)) {
|
if (!(option_mask32 & OPT_nofork)) {
|
||||||
#ifdef BB_NOMMU
|
bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
|
||||||
if (!re_execed)
|
|
||||||
vfork_daemon_rexec(0, 1, argv);
|
|
||||||
#else
|
|
||||||
bb_daemonize();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
umask(0);
|
umask(0);
|
||||||
do_syslogd();
|
do_syslogd();
|
||||||
|
Loading…
Reference in New Issue
Block a user