diff --git a/init.c b/init.c index 574fdb9..00f7069 100644 --- a/init.c +++ b/init.c @@ -35,6 +35,7 @@ #include "config-stage1.h" #include "lomount.h" +#include "tools.h" #define MKDEV(ma,mi) ((ma)<<8 | (mi)) #define RAMFS_MAGIC 0x858458f6 @@ -350,6 +351,7 @@ int main(int argc, char **argv) int wait_status; int fd = -1; int fds[2]; + char *init = NULL; if (mount("/proc", "/proc", "proc", 0, NULL)) fatal("failed to mount proc filesystem"); @@ -571,7 +573,12 @@ int main(int argc, char **argv) fatal("chroot"); /* Check for given init */ - if (stat(STAGE2_BINNAME, &ist) || !S_ISREG(ist.st_mode)) + init = get_from_env("INIT", myenv); + if ( init && ! stat(init, &ist) && S_ISREG(ist.st_mode)) + argv[0] = init; + else if ( ! stat(STAGE2_BINNAME, &ist) && S_ISREG(ist.st_mode)) + argv[0] = STAGE2_BINNAME; + else fatal("can't find init on root fs"); /* Spawn init */ @@ -580,7 +587,6 @@ int main(int argc, char **argv) /* unblock signals */ sigprocmask(SIG_UNBLOCK, &sig, NULL); - argv[0] = STAGE2_BINNAME; execve(argv[0], argv, myenv); fatal("stage2"); /* Failed to spawn init */ return 0; diff --git a/stage1.c b/stage1.c index a9dd0e2..efa0251 100644 --- a/stage1.c +++ b/stage1.c @@ -329,6 +329,7 @@ void stage1() { enum return_type ret; char buf[128]; + char * init; open_log(); getversion(); @@ -350,6 +351,10 @@ void stage1() "your own risk. Alternatively, you may reboot your system now."); } + init = get_param_valued("init"); + if (init) + add_to_env("INIT", init); + ret = method_select_and_prepare(); finish_frontend(); diff --git a/tools.c b/tools.c index 10ac901..8a204f0 100644 --- a/tools.c +++ b/tools.c @@ -472,6 +472,24 @@ void add_to_env(char * name, char * value) my_env[env_size] = NULL; } +char * get_from_env(const char * key, const char const ** env) +{ + int i=0; + + if (key == NULL || env == NULL) + return NULL; + + while(env[i]) + { + if (strncmp(env[i], key, strlen(key)) == 0) { + return strdup(env[i]+strlen(key)+1); + } + i++; + } + + return NULL; +} + int pass_env(int fd) { char ** ptr = my_env; diff --git a/tools.h b/tools.h index ac469ae..51c429a 100644 --- a/tools.h +++ b/tools.h @@ -47,6 +47,8 @@ int set_splash(char *); int update_splash(void); int prepare_progress(void); void close_progress(void); +char * get_param_valued(char *param_name); +char * get_from_env(const char * key, const char const ** env); struct param_elem {