Mercurial > hg > toybox
comparison toys/oneit.c @ 330:2a003d86d805
Teach oneit to reboot on exit more reliably.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 14 Dec 2008 02:12:07 -0600 |
parents | 93223118c813 |
children |
comparison
equal
deleted
inserted
replaced
329:6773399539aa | 330:2a003d86d805 |
---|---|
56 if (pid) { | 56 if (pid) { |
57 | 57 |
58 // pid 1 just reaps zombies until it gets its child, then halts the system. | 58 // pid 1 just reaps zombies until it gets its child, then halts the system. |
59 while (pid!=wait(&i)); | 59 while (pid!=wait(&i)); |
60 sync(); | 60 sync(); |
61 reboot(toys.optflags ? RB_POWER_OFF : RB_AUTOBOOT); | 61 |
62 // PID 1 can't call reboot() because it kills the task that calls it, | |
63 // which causes the kernel to panic before the actual reboot happens. | |
64 if (!vfork()) reboot((toys.optflags&1) ? RB_POWER_OFF : RB_AUTOBOOT); | |
65 sleep(5); | |
66 _exit(1); | |
62 } | 67 } |
63 | 68 |
64 // Redirect stdio to /dev/tty0, with new session ID, so ctrl-c works. | 69 // Redirect stdio to /dev/tty0, with new session ID, so ctrl-c works. |
65 setsid(); | 70 setsid(); |
66 for (i=0; i<3; i++) { | 71 for (i=0; i<3; i++) { |