10f66f451Sopenharmony_ci/* reboot.c - Restart, halt or powerdown the system. 20f66f451Sopenharmony_ci * 30f66f451Sopenharmony_ci * Copyright 2013 Elie De Brauwer <eliedebrauwer@gmail.com> 40f66f451Sopenharmony_ci 50f66f451Sopenharmony_ciUSE_REBOOT(NEWTOY(reboot, "d:fn", TOYFLAG_SBIN|TOYFLAG_NEEDROOT)) 60f66f451Sopenharmony_ciUSE_REBOOT(OLDTOY(halt, reboot, TOYFLAG_SBIN|TOYFLAG_NEEDROOT)) 70f66f451Sopenharmony_ciUSE_REBOOT(OLDTOY(poweroff, reboot, TOYFLAG_SBIN|TOYFLAG_NEEDROOT)) 80f66f451Sopenharmony_ci 90f66f451Sopenharmony_ciconfig REBOOT 100f66f451Sopenharmony_ci bool "reboot" 110f66f451Sopenharmony_ci default y 120f66f451Sopenharmony_ci help 130f66f451Sopenharmony_ci usage: reboot/halt/poweroff [-fn] [-d DELAY] 140f66f451Sopenharmony_ci 150f66f451Sopenharmony_ci Restart, halt, or power off the system. 160f66f451Sopenharmony_ci 170f66f451Sopenharmony_ci -d Wait DELAY before proceeding (in seconds or m/h/d suffix: -d 1.5m = 90s) 180f66f451Sopenharmony_ci -f Force reboot (don't signal init, reboot directly) 190f66f451Sopenharmony_ci -n Don't sync filesystems before reboot 200f66f451Sopenharmony_ci*/ 210f66f451Sopenharmony_ci 220f66f451Sopenharmony_ci#define FOR_reboot 230f66f451Sopenharmony_ci#include "toys.h" 240f66f451Sopenharmony_ci#include <sys/reboot.h> 250f66f451Sopenharmony_ci 260f66f451Sopenharmony_ciGLOBALS( 270f66f451Sopenharmony_ci char *d; 280f66f451Sopenharmony_ci) 290f66f451Sopenharmony_ci 300f66f451Sopenharmony_civoid reboot_main(void) 310f66f451Sopenharmony_ci{ 320f66f451Sopenharmony_ci struct timespec ts; 330f66f451Sopenharmony_ci int types[] = {RB_AUTOBOOT, RB_HALT_SYSTEM, RB_POWER_OFF}, 340f66f451Sopenharmony_ci sigs[] = {SIGTERM, SIGUSR1, SIGUSR2}, idx; 350f66f451Sopenharmony_ci 360f66f451Sopenharmony_ci if (TT.d) { 370f66f451Sopenharmony_ci xparsetimespec(TT.d, &ts); 380f66f451Sopenharmony_ci nanosleep(&ts, NULL); 390f66f451Sopenharmony_ci } 400f66f451Sopenharmony_ci 410f66f451Sopenharmony_ci if (!FLAG(n)) sync(); 420f66f451Sopenharmony_ci 430f66f451Sopenharmony_ci idx = stridx("hp", *toys.which->name)+1; 440f66f451Sopenharmony_ci if (FLAG(f)) toys.exitval = reboot(types[idx]); 450f66f451Sopenharmony_ci else toys.exitval = kill(1, sigs[idx]); 460f66f451Sopenharmony_ci} 47