From dfa16e4a89158f3d3198db71e2eba3bda9330078 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 10 Sep 2016 13:29:56 +0000 Subject: Make s6-linux-init a real init package. This means: - removing leaky options to s6-linux-init-maker. Default initial_path is now always /usr/bin:/bin; the uid and gid of the catch-all logger (used at boot time) can now be given numerically instead of relying on the (run-time) user db mapping. - moving s6-halt, s6-poweroff and s6-reboot over here, from s6-linux-utils - clarifying on the documentation a bit. --- src/init/hpr.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/init/hpr.c (limited to 'src/init/hpr.c') diff --git a/src/init/hpr.c b/src/init/hpr.c new file mode 100644 index 0000000..0e1c27a --- /dev/null +++ b/src/init/hpr.c @@ -0,0 +1,44 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include + +#define USAGE PROGNAME " [ -h | -p | -r ] [ -f ]" + +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, "hprf", &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 ; + default : strerr_dieusage(100, USAGE) ; + } + } + argc -= l.ind ; argv += l.ind ; + } + + 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 ; +} -- cgit v1.3.1