Merge branch 'peers/stanv'
This commit is contained in:
commit
544819c936
10
init.c
10
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;
|
||||
|
5
stage1.c
5
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();
|
||||
|
18
tools.c
18
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;
|
||||
|
Loading…
Reference in New Issue
Block a user