shinit

basic init daemon in POSIX sh
git clone git://git.ckyln.com/~cem/shinit.git
Log | Files | Refs | README | LICENSE

commit 1927bc62666cd1c3dd62bd81acb4beb926855f93
parent 9fe01a8c5c99c3d853b4d0ebda784e83745c315e
Author: Cem Keylan <cem@ckyln.com>
Date:   Fri, 24 Apr 2020 15:20:27 +0300

shinit: add shutdown script support

Diffstat:
MREADME.md | 9++++++---
Mshinit | 10+++++++++-
2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md @@ -1,14 +1,17 @@ shinit ====== -Basic init daemon in POSIX sh with only 3 lines of code. +Basic init daemon in POSIX sh with only 5 lines of code. It supports +acting upon signals. + +On USR1 signal it will poweroff, and on INT signal it will reboot. Installing ---------- -Before installing, edit the second command to use your boot script. If you -are using Carbs Linux or KISS, you don't need to change it. +Before installing, edit the second command to use your boot/poweroff +script. If you are using Carbs Linux or KISS, you don't need to change it. You can then install with `make`. diff --git a/shinit b/shinit @@ -6,10 +6,18 @@ # Run the boot script /lib/init/rc.boot +# Add signal traps for poweroff and reboot +trap '/lib/init/rc.shutdown poweroff' USR1 +trap '/lib/init/rc.shutdown reboot' INT + # Sleep for a day. As sleep is not a builtin for every # shell, we don't want to keep spawning processes, hence # the long sleep time. # # We also don't want to run 'while :; do :; done' as # it would lead to high cpu usage. -while :; do sleep 86400; done +# +# Since we want to trap signals, We fork and wait for the +# sleep. If sleep is not forked, signals will not be acted +# upon. +while :; do sleep 86400 & wait ; done