ubase

suckless linux base utils
git clone git://git.2f30.org/ubase
Log | Files | Refs | README | LICENSE

commit 051ed9a79cbe9af13fc38f361126fa1da9038b13
parent 4a8e5b14ab28485d797c4f39e1bcde81a536fb81
Author: sin <sin@2f30.org>
Date:   Fri,  9 Aug 2013 15:04:02 +0100

Add halt(8)

This is a very barebones halt cmd.  Please make sure that your
system is in a proper state to halt before using this.  This is
likely only useful for very barebones systems like an emergency
shell or similar.

Normally this command would be part of an actual init system.

Diffstat:
MMakefile | 1+
Ahalt.c | 40++++++++++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+), 0 deletions(-)

diff --git 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 @@ -0,0 +1,40 @@ +/* See LICENSE file for copyright and license details. */ +#include <linux/reboot.h> +#include <sys/syscall.h> +#include <unistd.h> +#include <stdio.h> +#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; +}