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