ctrlaltdel.c (993B)
1 /* see LICENSE file for copyright and license details */ 2 3 #if FEATURE_LINUX_SYSCALL 4 #ifndef _GNU_SOURCE 5 #define _GNU_SOURCE 6 #endif 7 #endif 8 #include <sys/syscall.h> 9 10 #include <stdio.h> 11 #include <unistd.h> 12 13 #include "reboot.h" 14 #include "util.h" 15 16 static void 17 usage(void) 18 { 19 eprintf("usage: %s -h | -s\n", argv0); 20 } 21 22 // ?man ctrlaltdel: set ctrl-alt-del function 23 // ?man arguments: -h | -s 24 // ?man set the behavior of the ctrl-alt-del key combination 25 int 26 main(int argc, char *argv[]) 27 { 28 int hflag = 0, sflag = 0, cmd; 29 30 ARGBEGIN 31 { 32 // ?man -h: suppress headers or print help 33 case 'h': 34 hflag = 1; 35 break; 36 // ?man -s: silent mode or print summary 37 case 's': 38 sflag = 1; 39 break; 40 default: 41 usage(); 42 } 43 ARGEND; 44 45 if (argc || !(hflag ^ sflag)) 46 usage(); 47 48 cmd = hflag ? LINUX_REBOOT_CMD_CAD_ON : LINUX_REBOOT_CMD_CAD_OFF; 49 50 if (syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd, NULL) < 0) 51 eprintf("reboot:"); 52 53 return 0; 54 }