public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix 2.6.x incorrect argv[0] for init
@ 2003-09-09 22:34 Erik Andersen
  0 siblings, 0 replies; only message in thread
From: Erik Andersen @ 2003-09-09 22:34 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel

In both 2.4.x and in 2.6.x, when someone specifies "init=" to
select an alternative binary to run instead of /sbin/init,
argv[0] is not set correctly.  This is a problem for programs
such as busybox that multiplex applications based on the value of
argv[0].  For example, even if you specify init=/bin/sh" on the
kernel command line, busybox will still receive "/sbin/init" as
argv[0], and will therefore run init rather than /bin/sh...

This patch fixes it.  Please apply,

 -Erik

--
Erik B. Andersen             http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--


--- linux-2.6.0-test5/init/main.c.orig	2003-09-08 13:49:54.000000000 -0600
+++ linux-2.6.0-test5/init/main.c	2003-09-09 16:28:02.000000000 -0600
@@ -542,6 +542,12 @@
 	spawn_ksoftirqd();
 }
 
+static void run_init_process(char *init_filename)
+{
+	argv_init[0] = init_filename;
+	execve(init_filename, argv_init, envp_init);
+}
+
 extern void prepare_namespace(void);
 
 static int init(void * unused)
@@ -592,10 +598,12 @@
 	 */
 
 	if (execute_command)
-		execve(execute_command,argv_init,envp_init);
-	execve("/sbin/init",argv_init,envp_init);
-	execve("/etc/init",argv_init,envp_init);
-	execve("/bin/init",argv_init,envp_init);
-	execve("/bin/sh",argv_sh,envp_init);
+		run_init_process(execute_command);
+
+	run_init_process("/sbin/init");
+	run_init_process("/etc/init");
+	run_init_process("/bin/init");
+	run_init_process("/bin/sh");
+
 	panic("No init found.  Try passing init= option to kernel.");
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-09-09 22:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-09-09 22:34 [PATCH] fix 2.6.x incorrect argv[0] for init Erik Andersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox