preinit.c: reindent
This commit is contained in:
parent
0f38ee0e9c
commit
d2f517a4e9
1 changed files with 45 additions and 45 deletions
|
@ -14,23 +14,23 @@ void parseopts(char * cmdline, char **root, char **rootfstype);
|
||||||
|
|
||||||
static int begins_with(char * str, char * prefix)
|
static int begins_with(char * str, char * prefix)
|
||||||
{
|
{
|
||||||
while(*prefix) {
|
while(*prefix) {
|
||||||
if(*str == '\0') return 0;
|
if(*str == '\0') return 0;
|
||||||
if(*str != *prefix) return 0;
|
if(*str != *prefix) return 0;
|
||||||
str++;
|
str++;
|
||||||
prefix++;
|
prefix++;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fork_exec(char * command, char *args[])
|
static int fork_exec(char * command, char *args[])
|
||||||
{
|
{
|
||||||
int fork_pid = fork();
|
int fork_pid = fork();
|
||||||
AVER(fork_pid);
|
AVER(fork_pid);
|
||||||
if(fork_pid > 0)
|
if(fork_pid > 0)
|
||||||
wait(NULL);
|
wait(NULL);
|
||||||
else
|
else
|
||||||
return execve(command, args, NULL);
|
return execve(command, args, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
char banner[] = "Running pre-init...\n";
|
char banner[] = "Running pre-init...\n";
|
||||||
|
@ -38,45 +38,45 @@ char buf[COMMAND_LINE_SIZE];
|
||||||
|
|
||||||
int main(int argc, char *argv[], char *envp[])
|
int main(int argc, char *argv[], char *envp[])
|
||||||
{
|
{
|
||||||
char *rootdevice = 0;
|
char *rootdevice = 0;
|
||||||
char *rootfstype = 0;
|
char *rootfstype = 0;
|
||||||
char *p = buf;
|
char *p = buf;
|
||||||
write(1, banner, strlen(banner));
|
write(1, banner, strlen(banner));
|
||||||
|
|
||||||
mount("none", "/proc", "proc", 0, NULL);
|
mount("none", "/proc", "proc", 0, NULL);
|
||||||
|
|
||||||
int cmdline = open("/proc/cmdline", O_RDONLY, 0);
|
int cmdline = open("/proc/cmdline", O_RDONLY, 0);
|
||||||
|
|
||||||
if(cmdline>=0) {
|
if(cmdline>=0) {
|
||||||
int len = read(cmdline, buf, sizeof buf - 1);
|
int len = read(cmdline, buf, sizeof buf - 1);
|
||||||
buf[len]='\0';
|
buf[len]='\0';
|
||||||
write(1, "cmdline ", 8);
|
write(1, "cmdline ", 8);
|
||||||
write(1, buf, len);
|
write(1, buf, len);
|
||||||
};
|
};
|
||||||
|
|
||||||
parseopts(buf, &rootdevice, &rootfstype);
|
parseopts(buf, &rootdevice, &rootfstype);
|
||||||
|
|
||||||
if(rootdevice) {
|
if(rootdevice) {
|
||||||
if(!rootfstype) rootfstype = "jffs2"; /* backward compatibility */
|
if(!rootfstype) rootfstype = "jffs2"; /* backward compatibility */
|
||||||
write(1, "rootdevice ", 11);
|
write(1, "rootdevice ", 11);
|
||||||
write(1, rootdevice, strlen(rootdevice));
|
write(1, rootdevice, strlen(rootdevice));
|
||||||
write(1, " (", 2);
|
write(1, " (", 2);
|
||||||
write(1, rootfstype, strlen(rootfstype));
|
write(1, rootfstype, strlen(rootfstype));
|
||||||
write(1, ")\n", 1);
|
write(1, ")\n", 1);
|
||||||
|
|
||||||
AVER(mount(rootdevice, "/target/persist", rootfstype, 0, NULL));
|
AVER(mount(rootdevice, "/target/persist", rootfstype, 0, NULL));
|
||||||
AVER(mount("/target/persist/nix", "/target/nix",
|
AVER(mount("/target/persist/nix", "/target/nix",
|
||||||
"bind", MS_BIND, NULL));
|
"bind", MS_BIND, NULL));
|
||||||
|
|
||||||
char *exec_args[] = { "activate", "/target", NULL };
|
char *exec_args[] = { "activate", "/target", NULL };
|
||||||
AVER(fork_exec("/target/persist/activate", exec_args));
|
AVER(fork_exec("/target/persist/activate", exec_args));
|
||||||
AVER(chdir("/target"));
|
AVER(chdir("/target"));
|
||||||
|
|
||||||
AVER(mount("/target", "/", "bind", MS_BIND | MS_REC, NULL));
|
AVER(mount("/target", "/", "bind", MS_BIND | MS_REC, NULL));
|
||||||
AVER(chroot("."));
|
AVER(chroot("."));
|
||||||
argv[0] = "init";
|
|
||||||
argv[1] = NULL;
|
|
||||||
|
|
||||||
AVER(execve("/persist/init", argv, envp));
|
argv[0] = "init";
|
||||||
}
|
argv[1] = NULL;
|
||||||
|
AVER(execve("/persist/init", argv, envp));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue