blob: ae70cf916f44282cd927abe5ef5e17c58f554fe3 [file] [log] [blame]
Elie De Brauwer9b2b24a2013-10-01 20:57:21 +02001/* reboot.c - Restart, halt or powerdown the system.
2 *
3 * Copyright 2013 Elie De Brauwer <eliedebrauwer@gmail.com>
4
5USE_REBOOT(NEWTOY(reboot, "n", TOYFLAG_BIN|TOYFLAG_NEEDROOT))
6USE_REBOOT(OLDTOY(halt, reboot, "n", TOYFLAG_BIN|TOYFLAG_NEEDROOT))
7USE_REBOOT(OLDTOY(poweroff, reboot, "n", TOYFLAG_BIN|TOYFLAG_NEEDROOT))
8
9config REBOOT
10 bool "reboot"
11 default y
12 help
13 usage: reboot/halt/poweroff [-n]
14
15 Restart, halt or powerdown the system.
16
17 -n Don't sync before stopping the system.
18*/
19
20#define FOR_reboot
21#include "toys.h"
22#include <sys/reboot.h>
23
24void reboot_main(void)
25{
26 char c = toys.which->name[0];
27
28 if (!(toys.optflags & FLAG_n))
29 sync();
30
31 switch(c) {
32 case 'p':
33 toys.exitval = reboot(RB_POWER_OFF);
34 break;
35 case 'h':
36 toys.exitval = reboot(RB_HALT_SYSTEM);
37 break;
38 case 'r':
39 default:
40 toys.exitval = reboot(RB_AUTOBOOT);
41 }
42}