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