blob: a135888694358e8e3e0a37394993d95343fb3d7b [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
Paul Barker1dd37042015-04-04 11:58:06 -05005USE_REBOOT(NEWTOY(reboot, "n", TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
6USE_REBOOT(OLDTOY(halt, reboot, TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
7USE_REBOOT(OLDTOY(poweroff, reboot, TOYFLAG_SBIN|TOYFLAG_NEEDROOT))
Elie De Brauwer9b2b24a2013-10-01 20:57:21 +02008
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{
Rob Landley4aee3032013-10-17 14:43:38 -050026 int types[] = {RB_AUTOBOOT, RB_HALT_SYSTEM, RB_POWER_OFF};
Elie De Brauwer9b2b24a2013-10-01 20:57:21 +020027
Rob Landley4aee3032013-10-17 14:43:38 -050028 if (!(toys.optflags & FLAG_n)) sync();
Elie De Brauwer9b2b24a2013-10-01 20:57:21 +020029
Rob Landley4aee3032013-10-17 14:43:38 -050030 toys.exitval = reboot(types[stridx("hp", *toys.which->name)+1]);
Elie De Brauwer9b2b24a2013-10-01 20:57:21 +020031}