X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/Ventoy.git/blobdiff_plain/6434e453b2553be864fdcb29b4d07677b4fb7aab..c19cd649d89fe24740f1d4222b85a77ae324634b:/Unix/ventoy_unix_src/DragonFly/oinit.c diff --git a/Unix/ventoy_unix_src/DragonFly/oinit.c b/Unix/ventoy_unix_src/DragonFly/oinit.c index ae59123..5323334 100644 --- a/Unix/ventoy_unix_src/DragonFly/oinit.c +++ b/Unix/ventoy_unix_src/DragonFly/oinit.c @@ -84,7 +84,7 @@ static int setctty(const char *name) return fd; } -static void ventoy_init(char **argv_orig) +static void ventoy_init(void) { pid_t pid, wpid; int status, error; @@ -155,56 +155,55 @@ static void ventoy_init(char **argv_orig) /* step 7: swich_root */ vdebug("[VTOY] step 7: switch root ...\n"); - error = chdir("/new_root"); +} + +int main(int argc __unused, char **argv) +{ + pid_t pid, wpid; + int status, error; + size_t varsize = sizeof(int); + + /* Dispose of random users. */ + if (getuid() != 0) + errx(1, "%s", strerror(EPERM)); + + /* Init is not allowed to die, it would make the kernel panic */ + signal(SIGTERM, SIG_IGN); + + if ((pid = fork()) == 0) { + + setctty(_PATH_CONSOLE); + sysctlbyname("debug.bootverbose", &boot_verbose, &varsize, NULL, 0); + + vdebug("======= Ventoy Init Start ========\n"); + + ventoy_init(); + exit(1); /* force single user mode */ + } + + do { + wpid = waitpid(-1, &status, WUNTRACED); + } while (wpid != pid); + + error = chdir("/new_root"); if (error) - { - printf("[VTOY] chdir /new_root failed %d\n", error); goto chroot_failed; - } error = chroot_kernel("/new_root"); if (error) - { - printf("[VTOY] chroot_kernel /new_root failed %d\n", error); goto chroot_failed; - } error = chroot("/new_root"); if (error) - { - printf("[VTOY] chroot /new_root failed %d\n", error); goto chroot_failed; - } - vdebug("[VTOY] step 8: now run /sbin/init ...\n"); - execv("/sbin/init", __DECONST(char **, argv_orig)); + execv("/sbin/init", __DECONST(char **, argv)); /* We failed to exec /sbin/init in the chroot, sleep forever */ chroot_failed: - printf("[VTOY] ################### DEAD ################\n"); while(1) { sleep(3); }; -} - -int main(int argc __unused, char **argv) -{ - size_t varsize = sizeof(int); - - /* Dispose of random users. */ - if (getuid() != 0) - errx(1, "%s", strerror(EPERM)); - - /* Init is not allowed to die, it would make the kernel panic */ - signal(SIGTERM, SIG_IGN); - - setctty(_PATH_CONSOLE); - - sysctlbyname("debug.bootverbose", &boot_verbose, &varsize, NULL, 0); - - vdebug("======= Ventoy Init Start ========\n"); - - ventoy_init(argv); return 1; }