PATCH: removing hardcoded paths from init

Gabriel L. Somlo somlo at cmu.edu
Tue Jan 16 05:03:21 UTC 2007


> > Why the relutance to use the exec*p family?

Thinking more about it, that's a really good idea :) Below is the
reworked patch that uses execvp/execlp.

Denis, please disregard the previous one, and apply this.

Cheers,
Gabriel


diff -NarU5 busybox.orig/init/init.c busybox/init/init.c
--- busybox.orig/init/init.c	2007-01-15 15:18:06.000000000 -0500
+++ busybox/init/init.c	2007-01-15 23:48:05.000000000 -0500
@@ -387,10 +387,11 @@
 	static const char press_enter[] =
 #ifdef CUSTOMIZED_BANNER
 #include CUSTOMIZED_BANNER
 #endif
 		"\nPlease press Enter to activate this console. ";
+	void *app;
 
 	/* Block sigchild while forking.  */
 	sigemptyset(&nmask);
 	sigaddset(&nmask, SIGCHLD);
 	sigprocmask(SIG_BLOCK, &nmask, &omask);
@@ -558,11 +559,12 @@
 		}
 #endif
 
 		/* Now run it.  The new program will take over this PID,
 		 * so nothing further in init.c should be run. */
-		execv(cmdpath, cmd);
+		app = ENABLE_FEATURE_SH_STANDALONE_SHELL ? find_applet_by_name(cmdpath) : NULL;
+		execvp(app ? CONFIG_BUSYBOX_EXEC_PATH : cmdpath, cmd);
 
 		/* We're still here?  Some error happened. */
 		message(LOG | CONSOLE, "Bummer, cannot run '%s': %m", cmdpath);
 		_exit(-1);
 	}
@@ -676,10 +678,11 @@
 
 static void exec_signal(int sig ATTRIBUTE_UNUSED)
 {
 	struct init_action *a, *tmp;
 	sigset_t unblock_signals;
+	void *app;
 
 	for (a = init_action_list; a; a = tmp) {
 		tmp = a->next;
 		if (a->action & RESTART) {
 			shutdown_system();
@@ -711,11 +714,12 @@
 			/* Setup stdout, stderr on the supplied terminal */
 			dup(0);
 			dup(0);
 
 			messageD(CONSOLE | LOG, "Trying to re-exec %s", a->command);
-			execl(a->command, a->command, NULL);
+			app = ENABLE_FEATURE_SH_STANDALONE_SHELL ? find_applet_by_name(a->command) : NULL;
+			execlp(app ? CONFIG_BUSYBOX_EXEC_PATH : a->command, a->command, NULL);
 
 			message(CONSOLE | LOG, "exec of '%s' failed: %m",
 					a->command);
 			sync();
 			sleep(2);
@@ -850,17 +854,17 @@
 	file = fopen(INITTAB, "r");
 	if (file == NULL) {
 		/* No inittab file -- set up some default behavior */
 #endif
 		/* Reboot on Ctrl-Alt-Del */
-		new_init_action(CTRLALTDEL, "/sbin/reboot", "");
+		new_init_action(CTRLALTDEL, "reboot", "");
 		/* Umount all filesystems on halt/reboot */
-		new_init_action(SHUTDOWN, "/bin/umount -a -r", "");
+		new_init_action(SHUTDOWN, "umount -a -r", "");
 		/* Swapoff on halt/reboot */
-		if(ENABLE_SWAPONOFF) new_init_action(SHUTDOWN, "/sbin/swapoff -a", "");
+		if(ENABLE_SWAPONOFF) new_init_action(SHUTDOWN, "swapoff -a", "");
 		/* Prepare to restart init when a HUP is received */
-		new_init_action(RESTART, "/sbin/init", "");
+		new_init_action(RESTART, "init", "");
 		/* Askfirst shell on tty1-4 */
 		new_init_action(ASKFIRST, bb_default_login_shell, "");
 		new_init_action(ASKFIRST, bb_default_login_shell, VC_2);
 		new_init_action(ASKFIRST, bb_default_login_shell, VC_3);
 		new_init_action(ASKFIRST, bb_default_login_shell, VC_4);
@@ -1037,13 +1041,13 @@
 		if (!sysinfo(&info) &&
 			(info.mem_unit ? : 1) * (long long)info.totalram < 1024*1024)
 		{
 			message(CONSOLE,"Low memory: forcing swapon.");
 			/* swapon -a requires /proc typically */
-			new_init_action(SYSINIT, "/bin/mount -t proc proc /proc", "");
+			new_init_action(SYSINIT, "mount -t proc proc /proc", "");
 			/* Try to turn on swap */
-			new_init_action(SYSINIT, "/sbin/swapon -a", "");
+			new_init_action(SYSINIT, "swapon -a", "");
 			run_actions(SYSINIT);   /* wait and removing */
 		}
 	}
 
 	/* Check if we are supposed to be in single user mode */
@@ -1066,11 +1070,12 @@
 	if (getenv("SELINUX_INIT") == NULL) {
 		int enforce = 0;
 
 		putenv("SELINUX_INIT=YES");
 		if (selinux_init_load_policy(&enforce) == 0) {
-			execv(argv[0], argv);
+			void *app = ENABLE_FEATURE_SH_STANDALONE_SHELL ? find_applet_by_name(argv[0]) : NULL;
+			execvp(app ? CONFIG_BUSYBOX_EXEC_PATH : argv[0], argv);
 		} else if (enforce > 0) {
 			/* SELinux in enforcing mode but load_policy failed */
 			/* At this point, we probably can't open /dev/console, so log() won't work */
 			message(CONSOLE,"Unable to load SELinux Policy. Machine is in enforcing mode. Halting now.");
 			exit(1);




More information about the busybox mailing list