diff --git a/Makefile b/Makefile index 1322fb4..46d28d3 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ SRC = \ ifeq ($(OS),linux) SRC += \ + halt.c \ insmod.c \ lsmod.c \ mkswap.c \ diff --git a/halt.c b/halt.c new file mode 100644 index 0000000..3408988 --- /dev/null +++ b/halt.c @@ -0,0 +1,40 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include +#include +#include +#include "util.h" + +static void +usage(void) +{ + eprintf("usage: %s [-p]\n", argv0); +} + +int +main(int argc, char *argv[]) +{ + int pflag = 0; + int cmd = LINUX_REBOOT_CMD_HALT; + + ARGBEGIN { + case 'p': + pflag = 1; + break; + default: + usage(); + } ARGEND; + + if (argc > 0) + usage(); + + sync(); + + if (pflag) + cmd = LINUX_REBOOT_CMD_POWER_OFF; + + if (syscall(__NR_reboot, 0xfee1dead, 672274793, + cmd, NULL) < 0) + eprintf("reboot:"); + return 0; +}