morpheus-base

morpheus base system
git clone git://git.2f30.org/morpheus-base
Log | Files | Refs

ctrlaltdel.c (683B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include <sys/syscall.h>
      3 
      4 #include <stdio.h>
      5 #include <stdlib.h>
      6 #include <unistd.h>
      7 
      8 #include "reboot.h"
      9 #include "util.h"
     10 
     11 static void
     12 usage(void)
     13 {
     14 	eprintf("usage: %s [-hs]\n", argv0);
     15 }
     16 
     17 int
     18 main(int argc, char *argv[])
     19 {
     20 	int hflag = 0;
     21 	int sflag = 0;
     22 	int cmd;
     23 
     24 	ARGBEGIN {
     25 	case 'h':
     26 		hflag = 1;
     27 		break;
     28 	case 's':
     29 		sflag = 1;
     30 		break;
     31 	default:
     32 		usage();
     33 	} ARGEND;
     34 
     35 	if (argc > 0 || (hflag ^ sflag) == 0)
     36 		usage();
     37 
     38 	cmd = hflag ? LINUX_REBOOT_CMD_CAD_ON : LINUX_REBOOT_CMD_CAD_OFF;
     39 
     40 	if (syscall(__NR_reboot, LINUX_REBOOT_MAGIC1,
     41 		    LINUX_REBOOT_MAGIC2, cmd, NULL) < 0)
     42 		eprintf("reboot:");
     43 	return 0;
     44 }