about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJuan RP <xtraeme@gmail.com>2014-04-26 09:28:15 +0200
committerJuan RP <xtraeme@gmail.com>2014-04-26 09:29:39 +0200
commit7aecf46ec589a5bc49ae2392137bcd0e7468dd08 (patch)
tree2164dbf05eea99348d6a0bf893b9fd218bc9ee83
parent72c31feddc31ca0e9f5311a3133d26eef69de971 (diff)
downloadrunit-void-7aecf46ec589a5bc49ae2392137bcd0e7468dd08.tar.gz
runit-void-7aecf46ec589a5bc49ae2392137bcd0e7468dd08.tar.xz
runit-void-7aecf46ec589a5bc49ae2392137bcd0e7468dd08.zip
Add halt/pause utils from ignite.
-rw-r--r--Makefile11
-rw-r--r--README.md3
-rwxr-xr-xhaltbin0 -> 10538 bytes
-rw-r--r--halt.c76
-rwxr-xr-xpausebin0 -> 8871 bytes
-rw-r--r--pause.139
-rw-r--r--pause.c20
7 files changed, 149 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index caabf57..e6c8527 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,17 @@
 SCRIPTS=	1 2 3 ctrlaltdel
 
+all:
+	$(CC) $(CFLAGS) halt.c -o halt
+	$(CC) $(CFLAGS) pause.c -o pause
+
 install:
+	install -d ${DESTDIR}/${PREFIX}/bin
+	install -m755 halt ${DESTDIR}/${PREFIX}/bin
+	install -m755 pause ${DESTDIR}/${PREFIX}/bin
+	ln -s halt ${DESTDIR}/${PREFIX}/bin/poweroff
+	ln -s halt ${DESTDIR}/${PREFIX}/bin/reboot
+	install -d ${DESTDIR}/${PREFIX}/share/man/man1
+	install -m644 pause.1 ${DESTDIR}/${PREFIX}/share/man/man1
 	install -d ${DESTDIR}/etc/sv
 	install -d ${DESTDIR}/etc/runit/runsvdir
 	install -m755 ${SCRIPTS} ${DESTDIR}/etc/runit
diff --git a/README.md b/README.md
index 1b10abc..4dd30dc 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,9 @@
 
 This repository contains the runit init scripts for the Void Linux distribution.
 
+This is loosely based on https://github.com/chneukirchen/ignite but with the
+difference that I'm trying to avoid the bash dependency.
+
 ### How to use it
 
     # xbps-install -Sy runit-void
diff --git a/halt b/halt
new file mode 100755
index 0000000..25960c0
--- /dev/null
+++ b/halt
Binary files differdiff --git a/halt.c b/halt.c
new file mode 100644
index 0000000..d6c52e6
--- /dev/null
+++ b/halt.c
@@ -0,0 +1,76 @@
+#include <errno.h>
+#include <unistd.h>
+#include <err.h>
+#include <string.h>
+#include <sys/reboot.h>
+
+extern char *__progname;
+
+typedef enum {NOOP, HALT, REBOOT, POWEROFF} action_t;
+
+int main(int argc, char *argv[]) {
+  int do_sync = 1;
+  int do_force = 0;
+  int opt;
+  action_t action = NOOP;
+
+  if (strcmp(__progname, "halt") == 0)
+    action = HALT;
+  else if (strcmp(__progname, "reboot") == 0)
+    action = REBOOT;
+  else if (strcmp(__progname, "poweroff") == 0)
+    action = POWEROFF;
+  else
+    warnx("no default behavior, needs to be called as halt/reboot/poweroff.");
+
+  while ((opt = getopt(argc, argv, "dfhinw")) != -1)
+    switch (opt) {
+    case 'n':
+      do_sync = 0;
+      break;
+    case 'w':
+      action = NOOP;
+      break;
+    case 'd':
+    case 'h':
+    case 'i':
+      /* silently ignored.  */
+      break;
+    case 'f':
+      do_force = 1;
+      break;
+    default:
+      errx(1, "Usage: %s [-n] [-f]", __progname);
+    }
+  
+  if (do_sync)
+    sync();
+
+  switch (action) {
+  case HALT:
+    if (do_force)
+      reboot(RB_HALT_SYSTEM);
+    else
+      execl("/bin/init", "init", "0", (char*)0);
+    err(1, "halt failed");
+    break;
+  case POWEROFF:
+    if (do_force)
+      reboot(RB_POWER_OFF);
+    else
+      execl("/bin/init", "init", "0", (char*)0);
+    err(1, "poweroff failed");
+    break;
+  case REBOOT:
+    if (do_force)
+      reboot(RB_AUTOBOOT);
+    else
+      execl("/bin/init", "init", "6", (char*)0);
+    err(1, "reboot failed");
+    break;
+  case NOOP:
+    break;
+  }
+
+  return 0;
+}
diff --git a/pause b/pause
new file mode 100755
index 0000000..be408b6
--- /dev/null
+++ b/pause
Binary files differdiff --git a/pause.1 b/pause.1
new file mode 100644
index 0000000..b5a5dd6
--- /dev/null
+++ b/pause.1
@@ -0,0 +1,39 @@
+.Dd September 27, 2012
+.Dt PAUSE 1
+.Os Linux
+.Sh NAME
+.Nm pause
+.Nd don't exit, efficiently
+.Sh SYNOPSIS
+.Nm pause
+.Sh DESCRIPTION
+.Nm pause
+waits to be terminated by a signal.
+It can be used when service supervision is used but there is no
+long-running program to supervise.
+.Nm pause
+uses minimal system resources.
+.Sh EXAMPLES
+Setting up a static IP address with
+.Xr plugsv 8 .
+.Pp
+.Pa /etc/netsv/eth0/run :
+.Bd -literal -offset indent
+#!/bin/sh
+ip link set eth0 up
+ip addr add 192.0.2.1/24 dev eth0
+exec pause
+.Ed
+.Pp
+.Pa /etc/netsv/eth0/finish :
+.Bd -literal -offset indent
+#!/bin/sh
+ip addr del 192.0.2.1/24 dev eth0
+ip link set eth0 down
+.Ed
+.Sh SEE ALSO
+.Xr sleep 1 ,
+.Xr pause 3
+.Sh AUTHOR
+.An Christian Neukirchen ,
+.Mt chneukirchen@gmail.com .
diff --git a/pause.c b/pause.c
new file mode 100644
index 0000000..4825df6
--- /dev/null
+++ b/pause.c
@@ -0,0 +1,20 @@
+#include <unistd.h>
+#include <signal.h>
+
+static void
+nop(int sig)
+{
+}
+
+int
+main()
+{
+  signal(SIGTERM, nop);
+  signal(SIGINT, nop);
+  signal(SIGHUP, SIG_IGN);
+
+  pause();
+
+  return 0;
+}
+