diff options
-rw-r--r-- | Makefile | 11 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rwxr-xr-x | halt | bin | 0 -> 10538 bytes | |||
-rw-r--r-- | halt.c | 76 | ||||
-rwxr-xr-x | pause | bin | 0 -> 8871 bytes | |||
-rw-r--r-- | pause.1 | 39 | ||||
-rw-r--r-- | pause.c | 20 |
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; +} + |