1 /* reboot.c - Restart, halt or powerdown the system.
2 *
3 * Copyright 2013 Elie De Brauwer <eliedebrauwer@gmail.com>
4
5 USE_REBOOT(NEWTOY(reboot, "fn", TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
6 USE_REBOOT(OLDTOY(halt, reboot, TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
7 USE_REBOOT(OLDTOY(poweroff, reboot, TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
8
9 config REBOOT
10 bool "reboot"
11 default y
12 help
13 usage: reboot/halt/poweroff [-fn]
14
15 Restart, halt or powerdown the system.
16
17 -f Don't signal init
18 -n Don't sync before stopping the system.
19 */
20
21 #define FOR_reboot
22 #include "toys.h"
23 #include <sys/reboot.h>
24
reboot_main(void)25 void reboot_main(void)
26 {
27 int types[] = {RB_AUTOBOOT, RB_HALT_SYSTEM, RB_POWER_OFF},
28 sigs[] = {SIGTERM, SIGUSR1, SIGUSR2}, idx;
29
30 if (!(toys.optflags & FLAG_n)) sync();
31
32 idx = stridx("hp", *toys.which->name)+1;
33 if (toys.optflags & FLAG_f) toys.exitval = reboot(types[idx]);
34 else toys.exitval = kill(1, sigs[idx]);
35 }
36