# HG changeset patch # User Rob Landley # Date 1229242327 21600 # Node ID 2a003d86d805717fb3aed52821aa6eb55df86276 # Parent 6773399539aa9a027486782ce05db2f22913e23b Teach oneit to reboot on exit more reliably. diff -r 6773399539aa -r 2a003d86d805 toys/oneit.c --- a/toys/oneit.c Sun Dec 14 01:08:37 2008 -0600 +++ b/toys/oneit.c Sun Dec 14 02:12:07 2008 -0600 @@ -58,7 +58,12 @@ // pid 1 just reaps zombies until it gets its child, then halts the system. while (pid!=wait(&i)); sync(); - reboot(toys.optflags ? RB_POWER_OFF : RB_AUTOBOOT); + + // PID 1 can't call reboot() because it kills the task that calls it, + // which causes the kernel to panic before the actual reboot happens. + if (!vfork()) reboot((toys.optflags&1) ? RB_POWER_OFF : RB_AUTOBOOT); + sleep(5); + _exit(1); } // Redirect stdio to /dev/tty0, with new session ID, so ctrl-c works.