]> glassweightruler.freedombox.rocks Git - Ventoy.git/blobdiff - Unix/ventoy_unix_src/DragonFly/oinit.c
change password input field to type=password (#2427)
[Ventoy.git] / Unix / ventoy_unix_src / DragonFly / oinit.c
index ae59123927f6bb8408e4d3fad389a2864e61e1de..532333454ebea7ebfa48deb79779cf1bc63918e1 100644 (file)
@@ -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;
 }