summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-06-25 22:35:06 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-06-25 22:35:06 +0000
commit60bd7b90a21690178c17b1a3daa671076fbed9d4 (patch)
tree56280f9dce44cead9105b8284fc37e396b0a4753
parent21cb73b507d27bcb101a1f3ae95312d22952988b (diff)
downloads6-linux-init-60bd7b90a21690178c17b1a3daa671076fbed9d4.tar.xz
This was still racy as fuck, because redirfd -wnb is a dirty hack and
actually opens the fifo for reading, long enough for pid 2 to unblock! So it must be called *before* the fork. Rewrote the init script logic; found a nice way to factorize the redirect_stage2 impact. This one's good... I think.
-rw-r--r--src/init/s6-linux-init-maker.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/src/init/s6-linux-init-maker.c b/src/init/s6-linux-init-maker.c
index 7032bc7..42a58bc 100644
--- a/src/init/s6-linux-init-maker.c
+++ b/src/init/s6-linux-init-maker.c
@@ -267,28 +267,20 @@ static int make_init_script (buffer *b)
{
if (buffer_puts(b, "if { s6-mount -nt devtmpfs dev /dev }\n") < 0) goto err ;
}
- if (buffer_puts(b, "redirfd -r 0 /dev/null\ns6-envdir -I -- ") < 0
+ if (buffer_puts(b, "s6-envdir -I -- ") < 0
|| buffer_put(b, satmp.s + pos, pos2 - pos) < 0
- || buffer_puts(b, "/env\nbackground\n{\n s6-setsid --\n ") < 0) goto err ;
- if (redirect_stage2)
- {
- if (buffer_puts(b, "redirfd -w 2 ") < 0
- || buffer_put(b, satmp.s + sabase, pos - sabase) < 0
- || buffer_puts(b, "/service/s6-svscan-log/fifo\n fdmove -c 1 2\n ") < 0) goto err ;
- }
- else
- {
- if (buffer_puts(b, "redirfd -w 3 ") < 0
- || buffer_put(b, satmp.s + sabase, pos - sabase) < 0
- || buffer_puts(b, "/service/s6-svscan-log/fifo\n fdclose 3\n ") < 0) goto err ;
- }
- if (!string_quote(&satmp, init_script, str_len(init_script))
- || buffer_put(b, satmp.s + pos2, satmp.len - pos2) < 0
- || buffer_puts(b, "\n}\nunexport !\nredirfd -wnb 1 ") < 0
+ || buffer_puts(b, "/env\nredirfd -r 0 /dev/null\nredirfd -wnb 1 ") < 0
+ || buffer_put(b, satmp.s + sabase, pos - sabase) < 0
+ || buffer_puts(b, "/service/s6-svscan-log/fifo\nbackground\n{\n s6-setsid --\n redirfd -w 1 ") < 0
|| buffer_put(b, satmp.s + sabase, pos - sabase) < 0
- || buffer_puts(b, "/service/s6-svscan-log/fifo\nfdmove -c 2 1\ncd ") < 0
+ || buffer_puts(b, "/service/s6-svscan-log/fifo\n fdmove -c ") < 0
+ || buffer_puts(b, redirect_stage2 ? "2 1" : "1 2") < 0
+ || buffer_puts(b, "\n ") < 0
+ || !string_quote(&satmp, init_script, str_len(init_script))
+ || buffer_put(b, satmp.s + pos2, satmp.len - pos2) < 0
+ || buffer_puts(b, "\n}\nunexport !\ncd ") < 0
|| buffer_put(b, satmp.s + sabase, pos - sabase) < 0
- || buffer_puts(b, "/service\ns6-svscan -t0\n") < 0) goto err ;
+ || buffer_puts(b, "/service\nfdmove -c 2 1\ns6-svscan -t0\n") < 0) goto err ;
return 1 ;
err:
satmp.len = sabase ;