aruu

[MIRROR] Actual replacement for Busybox | suckless
git clone https://git.daat.foo/aruu.git
Log | Files | Refs | README | LICENSE

reboot_linux.c (640B)


      1 /* see LICENSE file for copyright and license details */
      2 #ifndef _DEFAULT_SOURCE
      3 #define _DEFAULT_SOURCE
      4 #endif
      5 #include "../reboot.h"
      6 
      7 #if defined(__linux__) && !defined(ARUU_FORCE_POSIX)
      8 #include <stddef.h>
      9 #include <sys/syscall.h>
     10 #include <unistd.h>
     11 
     12 int
     13 machine_reboot(int how)
     14 {
     15   int cmd;
     16 
     17   switch (how) {
     18     case REBOOT_POWEROFF:
     19       cmd = LINUX_REBOOT_CMD_POWER_OFF;
     20       break;
     21     case REBOOT_RESTART:
     22       cmd = LINUX_REBOOT_CMD_RESTART;
     23       break;
     24     default:
     25       cmd = LINUX_REBOOT_CMD_HALT;
     26       break;
     27   }
     28   return syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd, NULL) < 0 ? -1 : 0;
     29 }
     30 #endif