M README.md => README.md +6 -3
@@ 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`.
M shinit => shinit +9 -1
@@ 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