On Monday 01 September 2008 10:59, Vladimir Dronnikov wrote: > > > I see. But "who" (which process) calls finalization? > > > > Calls what? I didn't understand you. > > > > Well. I use initramfs. Bootloader loads kernel, initramfs and finally > executes /sbin/init. > In my case init is BB (locally patched) runit which then sits and calls > stages.
A-ha. Stage 1 runit runs /etc/runit/1 and waits for it to terminate. The system’s one time tasks are done here. /etc/runit/1 has full control of /dev/console to be able to start an emergency shell if the one time initialization tasks fail. If /etc/runit/1 crashes, or exits 100, runit will skip stage 2 and enter stage 3. Stage 2 runit runs /etc/runit/2, which should not return until system shutdown; if it crashes, or exits 111, it will be restarted. Normally /etc/runit/2 starts runsvdir(8). runit is able to handle the ctrl-alt-del keyboard request in stage 2, see below. Stage 3 If runit is told to shutdown the system, or stage 2 returns, it terminates stage 2 if it is running, and runs /etc/runit/3. The systems tasks to shutdown and possibly halt or reboot the system are done here. If stage 3 returns, runit checks if the file /etc/runit/reboot exists and has the execute by owner permission set. If so, the system is rebooted, it’s halted otherwise. > So finalization is called by that runit process. But how do you > perform startup? Your /sbin/init is what? The mentioned shell script? Or you > use /linuxrc? Yes. Look again at the above. Why there is stage 1 at all? Why not #!/bin/sh /a/path/to/stage1_script.sh /a/path/to/stage2_script.sh or even roll them up into one script (or split into more scripts, whatever). and stage 3 is not needed at all - "killall5 -TERM" etc still works, no need to talk to init. > > I could reuse existing halt/reboot/poweroff in halt.c but it is made > > > specially for init.c and sends different signals to pid 1, depending > > > on the name of called applet. And runsvdir exits cleanly only if gets > > > TERM signal. Exactly. "Good" programs _have_ to_ exit on TERM, why can't we use that? > > I don't understand you again. You can reuse halt/reboot/poweroff for what? > > > > I wanna have halt/reboot/poweroff utilities to operate my box. With BB runit > (if we apply the patch) they can be bundled in runit.c. But I see that these > applets already exist in init/halt.c BB source file. I can reuse them > ........ to operate on runit-less stage 2 (bare runsvdir run from shell > script, as you suggested) but they (applets) need to be patched so they > should send TERM signal to pid #1, not USR1, USR2. I personally will continue to use script as init + killall5 for shutdown. http://busybox.net/~vda/init_vs_runsv.html explains my position. Of course you don't have to do the same. It only means that if you want runit in busybox, you need to write up a mini-doc "why is it useful + how to use it (targeted for those who only ever used sysV init)". -- vda _______________________________________________ busybox mailing list busybox@busybox.net http://busybox.net/cgi-bin/mailman/listinfo/busybox