ubase

suckless linux base utils
git clone git://git.2f30.org/ubase
Log | Files | Refs | README | LICENSE

ctrlaltdel.c (655B)


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