From ce8eaba8581ebbb56242cc2ee73c72a928e59a99 Mon Sep 17 00:00:00 2001 From: Cem Keylan Date: Tue, 24 Mar 2020 17:11:52 +0300 Subject: add simple halt utility --- Makefile | 17 ++++++++++++++++- bin/shalt.c | 13 +++++++++++++ rc.shutdown | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 bin/shalt.c diff --git a/Makefile b/Makefile index 9a933be..9f34284 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,20 @@ PREFIX = /usr INITDIR = ${PREFIX}/lib/init +BINDIR = ${PREFIX}/bin +CC = cc -install: +all: bin/shalt + +bin/shalt: + ${CC} -o bin/shalt bin/shalt.c + +clean: + rm -f bin/shalt + +install: bin/shalt mkdir -p ${DESTDIR}/etc + install -Dm755 -t ${DESTDIR}${BINDIR} bin/shalt install -Dm644 rc.conf ${DESTDIR}/etc/init/rc.conf install -Dm644 rc.lib ${DESTDIR}${INITDIR}/rc.lib install -Dm644 -t ${DESTDIR}/etc/init/ contrib/getty.boot contrib/runit.boot @@ -15,6 +26,7 @@ install: install -Dm644 README ${DESTDIR}${INITDIR}/README uninstall: + rm -f ${DESTDIR}${BINDIR}/shalt rm -f ${DESTDIR}/etc/init/rc.conf rm -f ${DESTDIR}/etc/init/rc.local rm -f ${DESTDIR}/etc/init/getty.boot ${DESTDIR}/etc/init/runit.boot @@ -22,3 +34,6 @@ uninstall: rm -f ${DESTDIR}${INITDIR}/rc.shutdown rm -f ${DESTDIR}${INITDIR}/rc.lib rm -f ${DESTDIR}${INITDIR}/README + + +.PHONY: all clean install uninstall diff --git a/bin/shalt.c b/bin/shalt.c new file mode 100644 index 0000000..924d85d --- /dev/null +++ b/bin/shalt.c @@ -0,0 +1,13 @@ +#include +#include + +/* Simple halt utility */ +/* Reboot if the argument is r, Poweroff is the argument is p */ + +int main (int argc, char *argv[]) { + switch ((int)argv[argc < 2 ? 0 : 1][0] + geteuid()) { + case 'p': reboot(RB_POWER_OFF); break; + case 'r': reboot(RB_AUTOBOOT); break; + default: return 1; + }; return 0; +} diff --git a/rc.shutdown b/rc.shutdown index a9ca570..848f114 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -53,3 +53,5 @@ for file in /etc/init/*.post.shutdown ; do [ -f "$file" ] && \ out "Running $file" && . "$file" done + +case "$1" in reboot) shalt r ;; poweroff) shalt p ;; esac -- cgit v1.2.3