summary refs log tree commit diff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2016-03-17 14:06:46 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2016-03-17 14:06:46 +0000
commit96893711ec76b3c3b554313d7e97560b3cd62179 (patch)
treea783948a9d20e8a8434c63ba928c290b22ddb363
parent82776d2fe715afcded74b3841f6d9a5b410e16c5 (diff)
downloads6-linux-utils-96893711ec76b3c3b554313d7e97560b3cd62179.tar.gz
s6-linux-utils-96893711ec76b3c3b554313d7e97560b3cd62179.tar.xz
s6-linux-utils-96893711ec76b3c3b554313d7e97560b3cd62179.zip
Add halt, poweroff, reboot as unexported commands
-rw-r--r--package/deps.mak10
-rw-r--r--package/modes3
-rw-r--r--package/targets.mak3
-rw-r--r--src/minutils/deps-exe/halt1
-rw-r--r--src/minutils/deps-exe/poweroff1
-rw-r--r--src/minutils/deps-exe/reboot1
-rw-r--r--src/minutils/halt.c7
-rw-r--r--src/minutils/hpr.c49
-rw-r--r--src/minutils/poweroff.c7
-rw-r--r--src/minutils/reboot.c7
10 files changed, 88 insertions, 1 deletions
diff --git a/package/deps.mak b/package/deps.mak
index 00606ca..0eb59f1 100644
--- a/package/deps.mak
+++ b/package/deps.mak
@@ -2,6 +2,10 @@
 # This file has been generated by tools/gen-deps.sh
 #
 
+src/minutils/halt.o src/minutils/halt.lo: src/minutils/halt.c
+src/minutils/hpr.o src/minutils/hpr.lo: src/minutils/hpr.c
+src/minutils/poweroff.o src/minutils/poweroff.lo: src/minutils/poweroff.c
+src/minutils/reboot.o src/minutils/reboot.lo: src/minutils/reboot.c
 src/minutils/s6-chroot.o src/minutils/s6-chroot.lo: src/minutils/s6-chroot.c
 src/minutils/s6-devd.o src/minutils/s6-devd.lo: src/minutils/s6-devd.c src/include/s6-linux-utils/config.h
 src/minutils/s6-freeramdisk.o src/minutils/s6-freeramdisk.lo: src/minutils/s6-freeramdisk.c
@@ -26,6 +30,12 @@ src/minutils/s6ps_statparse.o src/minutils/s6ps_statparse.lo: src/minutils/s6ps_
 src/minutils/s6ps_ttycache.o src/minutils/s6ps_ttycache.lo: src/minutils/s6ps_ttycache.c src/minutils/s6-ps.h
 src/minutils/s6ps_wchan.o src/minutils/s6ps_wchan.lo: src/minutils/s6ps_wchan.c src/minutils/s6-ps.h
 
+halt: EXTRA_LIBS :=
+halt: src/minutils/halt.o -lskarnet
+poweroff: EXTRA_LIBS :=
+poweroff: src/minutils/poweroff.o -lskarnet
+reboot: EXTRA_LIBS :=
+reboot: src/minutils/reboot.o -lskarnet
 s6-chroot: EXTRA_LIBS :=
 s6-chroot: src/minutils/s6-chroot.o -lskarnet
 s6-devd: EXTRA_LIBS :=
diff --git a/package/modes b/package/modes
index 3905269..b07ddd8 100644
--- a/package/modes
+++ b/package/modes
@@ -14,3 +14,6 @@ s6-reboot		0700
 s6-swapoff		0700
 s6-swapon		0700
 s6-umount		0700
+halt			0700
+poweroff		0700
+reboot			0700
diff --git a/package/targets.mak b/package/targets.mak
index 14bc019..964f9aa 100644
--- a/package/targets.mak
+++ b/package/targets.mak
@@ -17,4 +17,5 @@ s6-swapon \
 s6-umount \
 
 SBIN_TARGETS :=
-LIBEXEC_TARGETS :=
+LIBEXEC_TARGETS := halt poweroff reboot
+
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 <unistd.h>
+#include <signal.h>
+#include <sys/reboot.h>
+#include <skalibs/strerr2.h>
+#include <skalibs/sgetopt.h>
+
+#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"