From 96893711ec76b3c3b554313d7e97560b3cd62179 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 17 Mar 2016 14:06:46 +0000 Subject: Add halt, poweroff, reboot as unexported commands --- src/minutils/deps-exe/halt | 1 + src/minutils/deps-exe/poweroff | 1 + src/minutils/deps-exe/reboot | 1 + src/minutils/halt.c | 7 ++++++ src/minutils/hpr.c | 49 ++++++++++++++++++++++++++++++++++++++++++ src/minutils/poweroff.c | 7 ++++++ src/minutils/reboot.c | 7 ++++++ 7 files changed, 73 insertions(+) create mode 100644 src/minutils/deps-exe/halt create mode 100644 src/minutils/deps-exe/poweroff create mode 100644 src/minutils/deps-exe/reboot create mode 100644 src/minutils/halt.c create mode 100644 src/minutils/hpr.c create mode 100644 src/minutils/poweroff.c create mode 100644 src/minutils/reboot.c (limited to 'src') diff --git a/src/minutils/deps-exe/halt b/src/minutils/deps-exe/halt new file mode 100644 index 0000000..e7187fe --- /dev/null +++ b/src/minutils/deps-exe/halt @@ -0,0 +1 @@ +-lskarnet diff --git a/src/minutils/deps-exe/poweroff b/src/minutils/deps-exe/poweroff new file mode 100644 index 0000000..e7187fe --- /dev/null +++ b/src/minutils/deps-exe/poweroff @@ -0,0 +1 @@ +-lskarnet diff --git a/src/minutils/deps-exe/reboot b/src/minutils/deps-exe/reboot new file mode 100644 index 0000000..e7187fe --- /dev/null +++ b/src/minutils/deps-exe/reboot @@ -0,0 +1 @@ +-lskarnet diff --git a/src/minutils/halt.c b/src/minutils/halt.c new file mode 100644 index 0000000..8ef9ef4 --- /dev/null +++ b/src/minutils/halt.c @@ -0,0 +1,7 @@ +/* ISC license. */ + +#undef PROGNAME +#define PROGNAME "halt" +#undef WHATDEFAULT +#define WHATDEFAULT 1 +#include "hpr.c" diff --git a/src/minutils/hpr.c b/src/minutils/hpr.c new file mode 100644 index 0000000..d78470e --- /dev/null +++ b/src/minutils/hpr.c @@ -0,0 +1,49 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include + +#define USAGE PROGNAME " [ -h | -p | -r ] [ -f ] [ -w | -d ]" + +int main (int argc, char const *const *argv) +{ + int what = WHATDEFAULT ; + int force = 0 ; + PROG = PROGNAME ; + + { + subgetopt_t l = SUBGETOPT_ZERO ; + for (;;) + { + register int opt = subgetopt_r(argc, argv, "hprfwd", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'h' : what = 1 ; break ; + case 'p' : what = 2 ; break ; + case 'r' : what = 3 ; break ; + case 'f' : force = 1 ; break ; + case 'w' : what = 0 ; break ; + case 'd' : break ; + default : strerr_dieusage(100, USAGE) ; + } + } + argc -= l.ind ; argv += l.ind ; + } + + if (what) + { + if (force) + { + sync() ; + reboot(what == 3 ? RB_AUTOBOOT : what == 2 ? RB_POWER_OFF : RB_HALT_SYSTEM) ; + strerr_diefu1sys(111, "reboot()") ; + } + else if (kill(1, what == 3 ? SIGINT : what == 2 ? SIGUSR1 : SIGUSR2) < 0) + strerr_diefu1sys(111, "signal process 1") ; + } + return 0 ; +} diff --git a/src/minutils/poweroff.c b/src/minutils/poweroff.c new file mode 100644 index 0000000..2856aac --- /dev/null +++ b/src/minutils/poweroff.c @@ -0,0 +1,7 @@ +/* ISC license. */ + +#undef PROGNAME +#define PROGNAME "poweroff" +#undef WHATDEFAULT +#define WHATDEFAULT 2 +#include "hpr.c" diff --git a/src/minutils/reboot.c b/src/minutils/reboot.c new file mode 100644 index 0000000..12480d4 --- /dev/null +++ b/src/minutils/reboot.c @@ -0,0 +1,7 @@ +/* ISC license. */ + +#undef PROGNAME +#define PROGNAME "reboot" +#undef WHATDEFAULT +#define WHATDEFAULT 3 +#include "hpr.c" -- cgit v1.2.3