svn commit: trunk/busybox: debianutils miscutils networking sysklog etc...

vda at busybox.net vda at busybox.net
Mon Mar 26 13:20:54 UTC 2007


Author: vda
Date: 2007-03-26 06:20:54 -0700 (Mon, 26 Mar 2007)
New Revision: 18242

Log:
move everything to new NOMMU helpers, except udhcp


Modified:
   trunk/busybox/debianutils/start_stop_daemon.c
   trunk/busybox/miscutils/crond.c
   trunk/busybox/miscutils/watchdog.c
   trunk/busybox/networking/dnsd.c
   trunk/busybox/networking/httpd.c
   trunk/busybox/networking/inetd.c
   trunk/busybox/networking/isrv_identd.c
   trunk/busybox/networking/telnetd.c
   trunk/busybox/networking/zcip.c
   trunk/busybox/sysklogd/klogd.c
   trunk/busybox/sysklogd/syslogd.c


Changeset:
Modified: trunk/busybox/debianutils/start_stop_daemon.c
===================================================================
--- trunk/busybox/debianutils/start_stop_daemon.c	2007-03-26 13:20:04 UTC (rev 18241)
+++ trunk/busybox/debianutils/start_stop_daemon.c	2007-03-26 13:20:54 UTC (rev 18242)
@@ -299,8 +299,7 @@
 	}
 	*--argv = startas;
 	if (opt & OPT_BACKGROUND) {
-		setsid();
-		bb_daemonize();
+		bb_daemonize(0);
 	}
 	if (opt & OPT_MAKEPID) {
 		/* user wants _us_ to make the pidfile */

Modified: trunk/busybox/miscutils/crond.c
===================================================================
--- trunk/busybox/miscutils/crond.c	2007-03-26 13:20:04 UTC (rev 18241)
+++ trunk/busybox/miscutils/crond.c	2007-03-26 13:20:54 UTC (rev 18242)
@@ -136,75 +136,43 @@
 {
 	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);
 

Modified: trunk/busybox/miscutils/watchdog.c
===================================================================
--- trunk/busybox/miscutils/watchdog.c	2007-03-26 13:20:04 UTC (rev 18241)
+++ trunk/busybox/miscutils/watchdog.c	2007-03-26 13:20:54 UTC (rev 18242)
@@ -29,29 +29,21 @@
 	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) {
 		/*
@@ -63,6 +55,5 @@
 	}
 
 	watchdog_shutdown(0);
-
 	/* return EXIT_SUCCESS; */
 }

Modified: trunk/busybox/networking/dnsd.c
===================================================================
--- trunk/busybox/networking/dnsd.c	2007-03-26 13:20:04 UTC (rev 18241)
+++ trunk/busybox/networking/dnsd.c	2007-03-26 13:20:54 UTC (rev 18242)
@@ -353,12 +353,7 @@
 	}
 
 	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;
 	}

Modified: trunk/busybox/networking/httpd.c
===================================================================
--- trunk/busybox/networking/httpd.c	2007-03-26 13:20:04 UTC (rev 18241)
+++ trunk/busybox/networking/httpd.c	2007-03-26 13:20:54 UTC (rev 18242)
@@ -2044,6 +2044,6 @@
 		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);
 }

Modified: trunk/busybox/networking/inetd.c
===================================================================
--- trunk/busybox/networking/inetd.c	2007-03-26 13:20:04 UTC (rev 18241)
+++ trunk/busybox/networking/inetd.c	2007-03-26 13:20:54 UTC (rev 18242)
@@ -1274,30 +1274,24 @@
 	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;
 

Modified: trunk/busybox/networking/isrv_identd.c
===================================================================
--- trunk/busybox/networking/isrv_identd.c	2007-03-26 13:20:04 UTC (rev 18241)
+++ trunk/busybox/networking/isrv_identd.c	2007-03-26 13:20:54 UTC (rev 18242)
@@ -112,7 +112,9 @@
 		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

Modified: trunk/busybox/networking/telnetd.c
===================================================================
--- trunk/busybox/networking/telnetd.c	2007-03-26 13:20:04 UTC (rev 18241)
+++ trunk/busybox/networking/telnetd.c	2007-03-26 13:20:54 UTC (rev 18242)
@@ -415,7 +415,7 @@
 		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();

Modified: trunk/busybox/networking/zcip.c
===================================================================
--- trunk/busybox/networking/zcip.c	2007-03-26 13:20:04 UTC (rev 18241)
+++ trunk/busybox/networking/zcip.c	2007-03-26 13:20:54 UTC (rev 18242)
@@ -271,9 +271,8 @@
 
 	// 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);
 	}
 

Modified: trunk/busybox/sysklogd/klogd.c
===================================================================
--- trunk/busybox/sysklogd/klogd.c	2007-03-26 13:20:04 UTC (rev 18241)
+++ trunk/busybox/sysklogd/klogd.c	2007-03-26 13:20:54 UTC (rev 18242)
@@ -50,12 +50,7 @@
 	}
 
 	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);

Modified: trunk/busybox/sysklogd/syslogd.c
===================================================================
--- trunk/busybox/sysklogd/syslogd.c	2007-03-26 13:20:04 UTC (rev 18241)
+++ trunk/busybox/sysklogd/syslogd.c	2007-03-26 13:20:54 UTC (rev 18242)
@@ -642,12 +642,7 @@
 	}
 
 	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();




More information about the busybox-cvs mailing list