Merge branch 'peers/stanv'

This commit is contained in:
Sergey Bolshakov 2009-07-06 18:45:44 +04:00
commit 544819c936
4 changed files with 33 additions and 2 deletions

10
init.c
View File

@ -35,6 +35,7 @@
#include "config-stage1.h" #include "config-stage1.h"
#include "lomount.h" #include "lomount.h"
#include "tools.h"
#define MKDEV(ma,mi) ((ma)<<8 | (mi)) #define MKDEV(ma,mi) ((ma)<<8 | (mi))
#define RAMFS_MAGIC 0x858458f6 #define RAMFS_MAGIC 0x858458f6
@ -350,6 +351,7 @@ int main(int argc, char **argv)
int wait_status; int wait_status;
int fd = -1; int fd = -1;
int fds[2]; int fds[2];
char *init = NULL;
if (mount("/proc", "/proc", "proc", 0, NULL)) if (mount("/proc", "/proc", "proc", 0, NULL))
fatal("failed to mount proc filesystem"); fatal("failed to mount proc filesystem");
@ -571,7 +573,12 @@ int main(int argc, char **argv)
fatal("chroot"); fatal("chroot");
/* Check for given init */ /* 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"); fatal("can't find init on root fs");
/* Spawn init */ /* Spawn init */
@ -580,7 +587,6 @@ int main(int argc, char **argv)
/* unblock signals */ /* unblock signals */
sigprocmask(SIG_UNBLOCK, &sig, NULL); sigprocmask(SIG_UNBLOCK, &sig, NULL);
argv[0] = STAGE2_BINNAME;
execve(argv[0], argv, myenv); execve(argv[0], argv, myenv);
fatal("stage2"); /* Failed to spawn init */ fatal("stage2"); /* Failed to spawn init */
return 0; return 0;

View File

@ -329,6 +329,7 @@ void stage1()
{ {
enum return_type ret; enum return_type ret;
char buf[128]; char buf[128];
char * init;
open_log(); open_log();
getversion(); getversion();
@ -350,6 +351,10 @@ void stage1()
"your own risk. Alternatively, you may reboot your system now."); "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(); ret = method_select_and_prepare();
finish_frontend(); finish_frontend();

18
tools.c
View File

@ -472,6 +472,24 @@ void add_to_env(char * name, char * value)
my_env[env_size] = NULL; 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) int pass_env(int fd)
{ {
char ** ptr = my_env; char ** ptr = my_env;

View File

@ -47,6 +47,8 @@ int set_splash(char *);
int update_splash(void); int update_splash(void);
int prepare_progress(void); int prepare_progress(void);
void close_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 struct param_elem
{ {