1
0
mirror of git://git.suckless.org/ubase synced 2024-12-20 05:40:37 +00:00
ubase/halt.c

50 lines
757 B
C
Raw Normal View History

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