• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     -d	Wait DELAY before proceeding (in seconds or m/h/d suffix: -d 1.5m = 90s)
18     -f	Don't signal init
19     -n	Don't sync before stopping the system
20 */
21 
22 #define FOR_reboot
23 #include "toys.h"
24 #include <sys/reboot.h>
25 
reboot_main(void)26 void reboot_main(void)
27 {
28   int types[] = {RB_AUTOBOOT, RB_HALT_SYSTEM, RB_POWER_OFF},
29       sigs[] = {SIGTERM, SIGUSR1, SIGUSR2}, idx;
30 
31   if (!(toys.optflags & FLAG_n)) sync();
32 
33   idx = stridx("hp", *toys.which->name)+1;
34   if (toys.optflags & FLAG_f) toys.exitval = reboot(types[idx]);
35   else toys.exitval = kill(1, sigs[idx]);
36 }
37