svn commit: trunk/busybox: applets include libbb miscutils networki etc...

vda at busybox.net vda at busybox.net
Sat Mar 24 12:11:31 UTC 2007


Author: vda
Date: 2007-03-24 05:11:17 -0700 (Sat, 24 Mar 2007)
New Revision: 18219

Log:
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.


Modified:
   trunk/busybox/applets/busybox.c
   trunk/busybox/applets/individual.c
   trunk/busybox/include/libbb.h
   trunk/busybox/libbb/vfork_daemon_rexec.c
   trunk/busybox/miscutils/crond.c
   trunk/busybox/miscutils/watchdog.c
   trunk/busybox/networking/dnsd.c
   trunk/busybox/networking/inetd.c
   trunk/busybox/sysklogd/klogd.c
   trunk/busybox/sysklogd/syslogd.c


Changeset:
Modified: trunk/busybox/applets/busybox.c
===================================================================
--- trunk/busybox/applets/busybox.c	2007-03-24 12:08:57 UTC (rev 18218)
+++ trunk/busybox/applets/busybox.c	2007-03-24 12:11:17 UTC (rev 18219)
@@ -7,6 +7,7 @@
 #include "busybox.h"
 
 const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE;
+smallint re_execed;
 
 #ifdef CONFIG_FEATURE_INSTALLER
 /*
@@ -59,6 +60,12 @@
 {
 	const char *s;
 
+	/* NOMMU re-exec trick sets high-order bit in first byte of name */
+	if (argv[0][0] & 0x80) {
+		re_execed = 1;
+		argv[0][0] &= 0x7f;
+	}
+
 	applet_name = argv[0];
 	if (*applet_name == '-')
 		applet_name++;

Modified: trunk/busybox/applets/individual.c
===================================================================
--- trunk/busybox/applets/individual.c	2007-03-24 12:08:57 UTC (rev 18218)
+++ trunk/busybox/applets/individual.c	2007-03-24 12:11:17 UTC (rev 18219)
@@ -9,12 +9,11 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-//Ok to remove? #include "bb_config.h"
 #include "usage.h"
 
 int main(int argc, char *argv[])
 {
-	applet_name=argv[0];
+	applet_name = argv[0];
 
 	return APPLET_main(argc,argv);
 }

Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2007-03-24 12:08:57 UTC (rev 18218)
+++ trunk/busybox/include/libbb.h	2007-03-24 12:11:17 UTC (rev 18219)
@@ -616,9 +616,7 @@
 extern void print_login_issue(const char *issue_file, const char *tty);
 extern void print_login_prompt(void);
 #ifdef BB_NOMMU
-extern void vfork_daemon(int nochdir, int noclose);
-extern void vfork_daemon_rexec(int nochdir, int noclose,
-		int argc, char **argv, char *foreground_opt);
+extern void vfork_daemon_rexec(int nochdir, int noclose, char **argv);
 #endif
 extern int get_terminal_width_height(const int fd, int *width, int *height);
 
@@ -763,6 +761,7 @@
 };
 
 #define FILEUTILS_CP_OPTSTR "pdRfils" USE_SELINUX("c")
+extern smallint re_execed;
 extern const char *applet_name;
 extern const char BB_BANNER[];
 

Modified: trunk/busybox/libbb/vfork_daemon_rexec.c
===================================================================
--- trunk/busybox/libbb/vfork_daemon_rexec.c	2007-03-24 12:08:57 UTC (rev 18218)
+++ trunk/busybox/libbb/vfork_daemon_rexec.c	2007-03-24 12:11:17 UTC (rev 18219)
@@ -19,19 +19,18 @@
 #include "libbb.h"
 
 #ifdef BB_NOMMU
-void vfork_daemon_rexec(int nochdir, int noclose,
-		int argc, char **argv, char *foreground_opt)
+void vfork_daemon_rexec(int nochdir, int noclose, char **argv)
 {
 	int fd;
-	char **vfork_args;
-	int a = 0;
 
 	setsid();
 
 	if (!nochdir)
 		xchdir("/");
 
-	if (!noclose && (fd = open(bb_dev_null, O_RDWR, 0)) != -1) {
+	if (!noclose) {
+		/* if "/dev/null" doesn't exist, bail out! */
+		fd = xopen(bb_dev_null, O_RDWR);
 		dup2(fd, STDIN_FILENO);
 		dup2(fd, STDOUT_FILENO);
 		dup2(fd, STDERR_FILENO);
@@ -39,21 +38,17 @@
 			close(fd--);
 	}
 
-	vfork_args = xzalloc(sizeof(char *) * (argc + 3));
-	vfork_args[a++] = CONFIG_BUSYBOX_EXEC_PATH;
-	while (*argv) {
-		vfork_args[a++] = *argv;
-		argv++;
-	}
-	vfork_args[a] = foreground_opt;
 	switch (vfork()) {
 	case 0: /* child */
 		/* Make certain we are not a session leader, or else we
 		 * might reacquire a controlling terminal */
 		if (vfork())
 			_exit(0);
-		execv(vfork_args[0], vfork_args);
-		bb_perror_msg_and_die("execv %s", vfork_args[0]);
+		/* High-order bit of first char in argv[0] is a hidden
+		 * "we have (alrealy) re-execed, don't do it again" flag */
+		argv[0][0] |= 0x80;
+		execv(CONFIG_BUSYBOX_EXEC_PATH, argv);
+		bb_perror_msg_and_die("exec %s", CONFIG_BUSYBOX_EXEC_PATH);
 	case -1: /* error */
 		bb_perror_msg_and_die("vfork");
 	default: /* parent */

Modified: trunk/busybox/miscutils/crond.c
===================================================================
--- trunk/busybox/miscutils/crond.c	2007-03-24 12:08:57 UTC (rev 18218)
+++ trunk/busybox/miscutils/crond.c	2007-03-24 12:11:17 UTC (rev 18219)
@@ -191,8 +191,8 @@
 
 	if (!(opt & 4)) {
 #ifdef BB_NOMMU
-		/* reexec for vfork() do continue parent */
-		vfork_daemon_rexec(1, 0, ac, av, "-f");
+		if (!re_execed)
+			vfork_daemon_rexec(1, 0, av);
 #else
 		xdaemon(1, 0);
 #endif

Modified: trunk/busybox/miscutils/watchdog.c
===================================================================
--- trunk/busybox/miscutils/watchdog.c	2007-03-24 12:08:57 UTC (rev 18218)
+++ trunk/busybox/miscutils/watchdog.c	2007-03-24 12:11:17 UTC (rev 18219)
@@ -38,12 +38,14 @@
 	if (optind < argc - 1 || argc == 1)
 		bb_show_usage();
 
+	if (!(opts & OPT_FOREGROUND)) {
 #ifdef BB_NOMMU
-	if (!(opts & OPT_FOREGROUND))
-		vfork_daemon_rexec(0, 1, argc, argv, "-F");
+		if (!re_execed)
+			vfork_daemon_rexec(0, 1, argv);
 #else
-	xdaemon(0, 1);
+		xdaemon(0, 1);
 #endif
+	}
 
 	signal(SIGHUP, watchdog_shutdown);
 	signal(SIGINT, watchdog_shutdown);

Modified: trunk/busybox/networking/dnsd.c
===================================================================
--- trunk/busybox/networking/dnsd.c	2007-03-24 12:08:57 UTC (rev 18218)
+++ trunk/busybox/networking/dnsd.c	2007-03-24 12:11:17 UTC (rev 18219)
@@ -357,8 +357,8 @@
 	if (OPT_daemon) {
 //FIXME: NOMMU will NOT set LOGMODE_SYSLOG!
 #ifdef BB_NOMMU
-		/* reexec for vfork() do continue parent */
-		vfork_daemon_rexec(1, 0, argc, argv, "-d");
+		if (!re_execed)
+			vfork_daemon_rexec(1, 0, argv);
 #else
 		xdaemon(1, 0);
 #endif

Modified: trunk/busybox/networking/inetd.c
===================================================================
--- trunk/busybox/networking/inetd.c	2007-03-24 12:08:57 UTC (rev 18218)
+++ trunk/busybox/networking/inetd.c	2007-03-24 12:11:17 UTC (rev 18219)
@@ -1289,8 +1289,8 @@
 
 #ifdef BB_NOMMU
 	if (!(opt & 2)) {
-		/* reexec for vfork() do continue parent */
-		vfork_daemon_rexec(0, 0, argc, argv, "-f");
+		if (!re_execed)
+			vfork_daemon_rexec(0, 0, argv);
 	}
 	bb_sanitize_stdio();
 #else

Modified: trunk/busybox/sysklogd/klogd.c
===================================================================
--- trunk/busybox/sysklogd/klogd.c	2007-03-24 12:08:57 UTC (rev 18218)
+++ trunk/busybox/sysklogd/klogd.c	2007-03-24 12:11:17 UTC (rev 18219)
@@ -51,7 +51,8 @@
 
 	if (!(option_mask32 & OPT_FOREGROUND)) {
 #ifdef BB_NOMMU
-		vfork_daemon_rexec(0, 1, argc, argv, "-n");
+		if (!re_execed)
+			vfork_daemon_rexec(0, 1, argv);
 #else
 		bb_daemonize();
 #endif

Modified: trunk/busybox/sysklogd/syslogd.c
===================================================================
--- trunk/busybox/sysklogd/syslogd.c	2007-03-24 12:08:57 UTC (rev 18218)
+++ trunk/busybox/sysklogd/syslogd.c	2007-03-24 12:11:17 UTC (rev 18219)
@@ -643,7 +643,8 @@
 
 	if (!(option_mask32 & OPT_nofork)) {
 #ifdef BB_NOMMU
-		vfork_daemon_rexec(0, 1, argc, argv, "-n");
+		if (!re_execed)
+			vfork_daemon_rexec(0, 1, argv);
 #else
 		bb_daemonize();
 #endif




More information about the busybox-cvs mailing list