chiark / gitweb /
prefork-interp: add signalling byte
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Aug 2022 12:04:05 +0000 (13:04 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Aug 2022 20:21:10 +0000 (21:21 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
cprogs/prefork-interp.c
pm/Proc/Prefork/Interp.pm

index 0b4988d36d2ba3c581355315a722f0997fcf7138..62e5ff05b72b2e5f78c91f98a8137e797c12ce75 100644 (file)
@@ -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");
index d3c9241baf786fd184fd556678cf2abc9cf6304f..9c4bc6a0a893e84dfc06c23076a0c04dcd0b841f 100644 (file)
@@ -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;