aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCem Keylan <cem@ckyln.com>2020-09-16 15:55:20 +0300
committerCem Keylan <cem@ckyln.com>2020-09-16 15:55:20 +0300
commit79fafa3c6aa574f641d634fd3e136f29ec0ee9cf (patch)
tree2047c83784422790809db925811e6a50a971bc02
parentee006dbf0743bd3276ca3cdd1d6b5b563aa933f6 (diff)
downloadinit-79fafa3c6aa574f641d634fd3e136f29ec0ee9cf.tar.gz
respawn: add seperate shell utility instead of running while loops
Technically, these are the same shell commands, but since they are run by a separate shell, they are easier to predict and easier to kill.
-rw-r--r--Makefile2
-rw-r--r--contrib/getty.boot4
-rw-r--r--contrib/respawn23
-rw-r--r--contrib/runit.boot2
4 files changed, 28 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index fe893ad..be66946 100644
--- a/Makefile
+++ b/Makefile
@@ -23,6 +23,8 @@ install: bin/shalt
mkdir -p ${DESTDIR}${CONFDIR} ${DESTDIR}${INITDIR} ${DESTDIR}${BINDIR}
cp bin/shalt ${DESTDIR}${BINDIR}/shalt
chmod 755 ${DESTDIR}${BINDIR}/shalt
+ cp contrib/respawn ${DESTDIR}${BINDIR}/respawn
+ chmod 755 ${DESTDIR}${BINDIR}/respawn
cp rc.lib rc.boot rc.shutdown ${DESTDIR}${INITDIR}
chmod 755 ${DESTDIR}${INITDIR}/rc.boot ${DESTDIR}${INITDIR}/rc.shutdown
cp rc.conf contrib/runit.boot contrib/getty.boot ${DESTDIR}${CONFDIR}
diff --git a/contrib/getty.boot b/contrib/getty.boot
index bb5a5e3..eaf90d9 100644
--- a/contrib/getty.boot
+++ b/contrib/getty.boot
@@ -1,4 +1,4 @@
for getty in 1 2 3 4 5 6; do
- while :; do /sbin/getty 38400 tty${getty} 2>&1 ; done & # busybox getty
- while :; do /sbin/getty /dev/tty${getty} linux 2>&1 ; done & # ubase getty
+ respawn getty 38400 tty${getty} 2>&1 ; done & # busybox getty
+ respawn getty /dev/tty${getty} linux 2>&1 ; done & # ubase getty
done
diff --git a/contrib/respawn b/contrib/respawn
new file mode 100644
index 0000000..1b914ea
--- /dev/null
+++ b/contrib/respawn
@@ -0,0 +1,23 @@
+#!/bin/sh -e
+# POSIX shell variant for ubase respawn
+
+usage() {
+ printf 'usage: %s [-d N] cmd [args...]\n' "${0##*/}"
+ exit "${1:-0}"
+}
+
+die() { printf '%s\n' "$@" >&2; exit 1;}
+
+case "$1" in
+ -d) [ "$3" ] || usage 1
+ [ "$2" -gt 0 ] || die "Not a number: $2"
+ delay=$2; shift 2
+ ;;
+ --help|-h|'') usage ;;
+ -*) usage 1
+esac
+
+while :; do
+ "$@"
+ [ "$delay" ] && sleep "$delay"
+done
diff --git a/contrib/runit.boot b/contrib/runit.boot
index aafe142..f8858c9 100644
--- a/contrib/runit.boot
+++ b/contrib/runit.boot
@@ -1 +1 @@
-while :; do /usr/bin/runsvdir -P /var/service ; done &
+respawn runsvdir -P /var/service ; done &