minit

A small yet feature-complete init (http://fefe.de/minit/)
Log | Files | Refs | README | LICENSE

hard-reboot.c (691B)


      1 #include <unistd.h>
      2 #include <sys/reboot.h>
      3 #include <stdlib.h>
      4 
      5 #include <libowfat/str.h>
      6 
      7 #define ABORTMSG "hard-reboot: Aborted.\n"
      8 #define USAGE "Say \"hard-reboot (RESTART|HALT|POWER_OFF)\" if you really mean it.\n"
      9 
     10 void usage(void) {
     11   write(2, ABORTMSG, str_len(ABORTMSG));
     12   write(2, USAGE, str_len(USAGE));
     13   exit(1);
     14 }
     15 
     16 int main(int argc, char *argv[]) {
     17   if (argc!=2)
     18     usage();
     19 
     20   sync();
     21   sync();
     22   sync();
     23   if (strcmp(argv[1], "RESTART")==0) {
     24     reboot(RB_AUTOBOOT);
     25   } else if (strcmp(argv[1], "HALT")==0) {
     26     reboot(RB_HALT_SYSTEM);
     27   } else if (strcmp(argv[1], "POWER_OFF")==0) {
     28     reboot(RB_POWER_OFF);
     29   } else {
     30     usage();
     31   }
     32 
     33   while(1)
     34     sleep(10);
     35 }