This patch adds stage 4, an optional stage which is run after stage 3. If /etc/runit/4 is found and executable, runit will execve() into it, giving it control of PID 1. Finnix (http://www.finnix.org/) uses runit as its init system, and uses this patch as a way to pivot root back into a ramdisk upon shutdown, so it may cleanly umount the union mount which houses runit.
Signed-off-by: Ryan Finnie <r...@finnie.org> --- diff -ruN a/runit-2.1.1/src/runit.c b/runit-2.1.1/src/runit.c --- a/runit-2.1.1/src/runit.c 2009-10-04 13:44:02.000000000 -0700 +++ b/runit-2.1.1/src/runit.c 2013-10-10 16:03:21.738259966 -0700 @@ -22,10 +22,11 @@ #define WARNING "- runit: warning: " #define FATAL "- runit: fatal: " -const char * const stage[3] ={ +const char * const stage[4] ={ "/etc/runit/1", "/etc/runit/2", - "/etc/runit/3" }; + "/etc/runit/3", + "/etc/runit/4" }; int selfpipe[2]; int sigc =0; @@ -94,7 +95,17 @@ ": booting.", 0); /* runit */ - for (st =0; st < 3; st++) { + for (st =0; st < 4; st++) { + /* stage 4 gets control of pid 1 */ + if (st == 3) { + if ((stat(stage[st], &s) != -1) && (s.st_mode & S_IXUSR)) { + prog[0] =stage[st]; + prog[1] =0; + strerr_warn3(INFO, "enter stage: ", stage[st], 0); + execve(*prog, (char *const *)prog, envp); + strerr_die4sys(0, FATAL, "unable to exec: ", stage[st], ": "); + } + } /* if (st == 2) logwtmp("~", "reboot", ""); */ while ((pid =fork()) == -1) { strerr_warn4(FATAL, "unable to fork for \"", stage[st], "\" pausing: ",
signature.asc
Description: OpenPGP digital signature