From: Ian Jackson Date: Sun, 21 Aug 2022 12:04:05 +0000 (+0100) Subject: prefork-interp: add signalling byte X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=893872f3b6de2536968edb0b110fda70e83db940;p=chiark-utils.git prefork-interp: add signalling byte Signed-off-by: Ian Jackson --- diff --git a/cprogs/prefork-interp.c b/cprogs/prefork-interp.c index 0b4988d..62e5ff0 100644 --- a/cprogs/prefork-interp.c +++ b/cprogs/prefork-interp.c @@ -530,7 +530,11 @@ static void send_fd(int payload_fd) { } static void send_request(void) { - // Sending these first makes it easier for the script to + char ibyte= 0; + ssize_t sr = fwrite(&ibyte, 1, 1, call_sock); + if (sr != 1) diee("write signalling byte"); + + // Sending these before the big message makes it easier for the script to // use buffered IO for the message. send_fd(0); send_fd(1); @@ -546,7 +550,7 @@ static void send_request(void) { prepare_message(0, &p); assert(p == m + tlen); - ssize_t sr = fwrite(m, tlen, 1, call_sock); + sr = fwrite(m, tlen, 1, call_sock); if (sr != 1) diee("write request (buffer)"); if (fflush(call_sock)) diee("write request"); diff --git a/pm/Proc/Prefork/Interp.pm b/pm/Proc/Prefork/Interp.pm index d3c9241..9c4bc6a 100644 --- a/pm/Proc/Prefork/Interp.pm +++ b/pm/Proc/Prefork/Interp.pm @@ -125,6 +125,17 @@ sub protocol_exchange () { my $greeting = "PFI\n\0\0\0\0"; protocol_write($greeting); + my $ibyte = 0; + my $r; + for (;;) { + $r = sysread CALL, $ibyte, 1; + last if $r > 0; + $!==EINTR or protocol_read_fail("signalling byte"); + } + $r == 1 or _exit(0); + $ibyte = ord $ibyte; + $ibyte and die(sprintf "signalling byte is 0x%02x, not zero", $ibyte); + @call_fds = map { my $r; for (;;) { @@ -138,7 +149,7 @@ sub protocol_exchange () { } 0..2; my $len; - my $r = read(CALL, $len, 4) // protocol_read_fail("message length"); + $r = read(CALL, $len, 4) // protocol_read_fail("message length"); $r == 4 or _exit(0); $len = unpack "N", $len;