Hi Martin !
After some smashing things together, I took original init.c from base FreeBSD src tree and removed parts until it's just rudimentary initialization function that execves into execlineb boot script.
I'm interested in learning what you did: what is needed for FreeBSD to run a script as init ? Why can't the kernel boot on stage 1 directly ?
One problem I am having though, is "uncaught" logger dance, as unlike on linux, stage 1 dies with "broken pipe" signal when it tries to write to logger fifo (as it has no reader yet).
Ah, yes. You just can't write to the pipe until the catch-all logger has started, else it crashes like this.
For now I got around that by redirecting stderr to logger only right before supervisor boots up, however that means initial messages appear only on console. Is there some way to buffer those from fifo until last resort logger starts (using tools in s6 packages)? Or can I somehow spawn logger before supervisor spins up and have it "descent" later into supervision tree?
If you're certain that the amount of data you write will not exceed PIPE_BUF, you may spawn a process that opens the fifo for reading, but reads nothing, and only dies once the logger has started and opened the fifo for reading again. (Example: "background { redirfd -r 0 logger-fifo s6-pause }" and store $! somewhere, then kill $! once the catch-all logger has opened logger-fifo.) I don't know at all if it would work: the behaviour of fifos when there are several readers is unspecified by POSIX and totally implementation- defined. It's definitely a hack. But it might do what you want. The best solution is still to have a very minimal stage 1 and not do anything until the supervision tree is in place and the fifo has a writer: anything that writes to stdout/stderr once you have redirected them to the fifo, defer it to stage 2. There's an example of a minimal stage 1 in the examples/ subdirectory of the s6 tarball. For another example, you can install the s6-linux-init package: the s6-linux-init-maker tool will work on FreeBSD. The generated scripts won't, but you can still look at them to see how they perform a minimal stage 1 and delegate all the real stuff to stage 2.
Second problem is when I compile s6 and portable utils package with: ./configure --enable-static-libc all s6 tools are correctly identified by 'file' command as fully static ELFs, however s6-svstat for example fails to work correctly. It always reports given service as down. Without static libc it all works as intended. Is this a bug?
It's certainly a bug, but it probably has more to do with the toolchain and the way the programs are linked than with the s6 code. Can you please send me a log of your build, as well as a strace (or ktrace, or whatever FreeBSD tool can give a dump of the sequence of system calls) of the failing s6-svstat invocation ? Thanks, -- Laurent