ubase

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

commit d8a51e73b91975867acb40e15db8bc2c3735e2ae
parent 450f930c175d906420fb203d38036eb7e1e80b6d
Author: sin <sin@2f30.org>
Date:   Tue, 17 Sep 2013 16:34:26 +0100

Add support for rebooting the system through halt

Remove reboot

Diffstat:
MMakefile | 1-
Mhalt.c | 14+++++++++++---
Dreboot.c | 32--------------------------------
3 files changed, 11 insertions(+), 36 deletions(-)

diff --git a/Makefile b/Makefile @@ -35,7 +35,6 @@ SRC = \ pidof.c \ pivot_root.c \ ps.c \ - reboot.c \ rmmod.c \ stat.c \ swapoff.c \ diff --git a/halt.c b/halt.c @@ -8,19 +8,22 @@ static void usage(void) { - eprintf("usage: %s [-p]\n", argv0); + eprintf("usage: %s [-pr]\n", argv0); } int main(int argc, char *argv[]) { - int pflag = 0; + 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; @@ -30,11 +33,16 @@ main(int argc, char *argv[]) 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) - eprintf("reboot:"); + eprintf("halt:"); return 0; } diff --git a/reboot.c b/reboot.c @@ -1,32 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -#include <sys/syscall.h> -#include <unistd.h> -#include <stdio.h> -#include "reboot.h" -#include "util.h" - -static void -usage(void) -{ - eprintf("usage: %s\n", argv0); -} - -int -main(int argc, char *argv[]) -{ - ARGBEGIN { - default: - usage(); - } ARGEND; - - if (argc > 0) - usage(); - - sync(); - - if (syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, - LINUX_REBOOT_MAGIC2, - LINUX_REBOOT_CMD_RESTART, NULL) < 0) - eprintf("reboot:"); - return 0; -}