1/* reboot.c - Restart, halt or powerdown the system. 2 * 3 * Copyright 2013 Elie De Brauwer <eliedebrauwer@gmail.com> 4 5USE_REBOOT(NEWTOY(reboot, "d:fn", TOYFLAG_SBIN|TOYFLAG_NEEDROOT)) 6USE_REBOOT(OLDTOY(halt, reboot, TOYFLAG_SBIN|TOYFLAG_NEEDROOT)) 7USE_REBOOT(OLDTOY(poweroff, reboot, TOYFLAG_SBIN|TOYFLAG_NEEDROOT)) 8 9config REBOOT 10 bool "reboot" 11 default y 12 help 13 usage: reboot/halt/poweroff [-fn] [-d DELAY] 14 15 Restart, halt, or power off the system. 16 17 -d Wait DELAY before proceeding (in seconds or m/h/d suffix: -d 1.5m = 90s) 18 -f Force reboot (don't signal init, reboot directly) 19 -n Don't sync filesystems before reboot 20*/ 21 22#define FOR_reboot 23#include "toys.h" 24#include <sys/reboot.h> 25 26GLOBALS( 27 char *d; 28) 29 30void reboot_main(void) 31{ 32 struct timespec ts; 33 int types[] = {RB_AUTOBOOT, RB_HALT_SYSTEM, RB_POWER_OFF}, 34 sigs[] = {SIGTERM, SIGUSR1, SIGUSR2}, idx; 35 36 if (TT.d) { 37 xparsetimespec(TT.d, &ts); 38 nanosleep(&ts, NULL); 39 } 40 41 if (!FLAG(n)) sync(); 42 43 idx = stridx("hp", *toys.which->name)+1; 44 if (FLAG(f)) toys.exitval = reboot(types[idx]); 45 else toys.exitval = kill(1, sigs[idx]); 46} 47