2013-08-09 14:04:02 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <sys/syscall.h>
|
2014-06-30 18:03:41 +00:00
|
|
|
|
2013-08-09 14:04:02 +00:00
|
|
|
#include <stdio.h>
|
2013-10-07 18:11:40 +00:00
|
|
|
#include <stdlib.h>
|
2014-06-30 18:03:41 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2013-08-19 15:27:21 +00:00
|
|
|
#include "reboot.h"
|
2013-08-09 14:04:02 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2013-09-17 15:34:26 +00:00
|
|
|
eprintf("usage: %s [-pr]\n", argv0);
|
2013-08-09 14:04:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2013-09-17 15:34:26 +00:00
|
|
|
int pflag = 0, rflag = 0;
|
2013-08-09 14:04:02 +00:00
|
|
|
int cmd = LINUX_REBOOT_CMD_HALT;
|
|
|
|
|
|
|
|
ARGBEGIN {
|
|
|
|
case 'p':
|
|
|
|
pflag = 1;
|
|
|
|
break;
|
2013-09-17 15:34:26 +00:00
|
|
|
case 'r':
|
|
|
|
rflag = 1;
|
|
|
|
break;
|
2013-08-09 14:04:02 +00:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
|
|
|
if (argc > 0)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
sync();
|
|
|
|
|
2013-09-17 15:34:26 +00:00
|
|
|
if (pflag && rflag)
|
|
|
|
usage();
|
|
|
|
|
2013-08-09 14:04:02 +00:00
|
|
|
if (pflag)
|
|
|
|
cmd = LINUX_REBOOT_CMD_POWER_OFF;
|
2013-09-17 15:34:26 +00:00
|
|
|
if (rflag)
|
|
|
|
cmd = LINUX_REBOOT_CMD_RESTART;
|
2013-08-09 14:04:02 +00:00
|
|
|
|
2013-09-04 12:46:45 +00:00
|
|
|
if (syscall(__NR_reboot, LINUX_REBOOT_MAGIC1,
|
|
|
|
LINUX_REBOOT_MAGIC2, cmd, NULL) < 0)
|
2013-09-17 15:44:45 +00:00
|
|
|
eprintf("reboot:");
|
2014-10-02 22:45:25 +00:00
|
|
|
return 0;
|
2013-08-09 14:04:02 +00:00
|
|
|
}
|