aboutsummaryrefslogtreecommitdiff
path: root/toys/other/reboot.c
blob: ae70cf916f44282cd927abe5ef5e17c58f554fe3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* reboot.c - Restart, halt or powerdown the system.
 *
 * Copyright 2013 Elie De Brauwer <eliedebrauwer@gmail.com>

USE_REBOOT(NEWTOY(reboot, "n", TOYFLAG_BIN|TOYFLAG_NEEDROOT))
USE_REBOOT(OLDTOY(halt, reboot, "n", TOYFLAG_BIN|TOYFLAG_NEEDROOT))
USE_REBOOT(OLDTOY(poweroff, reboot, "n", TOYFLAG_BIN|TOYFLAG_NEEDROOT))

config REBOOT
  bool "reboot"
  default y
  help
    usage: reboot/halt/poweroff [-n]

    Restart, halt or powerdown the system.

    -n	Don't sync before stopping the system.
*/

#define FOR_reboot
#include "toys.h"
#include <sys/reboot.h>

void reboot_main(void)
{
  char c = toys.which->name[0];

  if (!(toys.optflags & FLAG_n))
    sync();

  switch(c) {
  case 'p':
    toys.exitval = reboot(RB_POWER_OFF);
      break;
  case 'h':
    toys.exitval = reboot(RB_HALT_SYSTEM);
    break;
  case 'r':
  default:
    toys.exitval = reboot(RB_AUTOBOOT);
  }
}