aboutsummaryrefslogtreecommitdiffstats
path: root/init
diff options
context:
space:
mode:
authorAndrew Morton <akpm@osdl.org>2003-09-21 01:40:10 -0700
committerLinus Torvalds <torvalds@home.osdl.org>2003-09-21 01:40:10 -0700
commitfe713e4b1f24114ea895a8e82b068eaf4900a7c7 (patch)
tree7ce24e08f878ef6094015d1a5016508073930cb3 /init
parentf5aaaa3eed214c5ee05dda86413b8a943a998866 (diff)
downloadhistory-fe713e4b1f24114ea895a8e82b068eaf4900a7c7.tar.gz
[PATCH] fix incorrect argv[0] for init
From: Erik Andersen <andersen@codepoet.org> 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...
Diffstat (limited to 'init')
-rw-r--r--init/main.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/init/main.c b/init/main.c
index d857325e3dc8aa..13eff1cdd527d0 100644
--- a/init/main.c
+++ b/init/main.c
@@ -542,12 +542,16 @@ static void do_pre_smp_initcalls(void)
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)
{
- static char * argv_sh[] = { "sh", NULL, };
-
lock_kernel();
/*
* Tell the world that we're going to be the grim
@@ -592,10 +596,12 @@ static int init(void * unused)
*/
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.");
}