chiark / gitweb /
prefork-interp: wip compile
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 17 Jul 2022 19:00:34 +0000 (20:00 +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

index fdc5da9db86ce7302402bd1a8b22caa5cbacc218..4e044a26c46a12f85946534fb52fea716fc5499b 100644 (file)
@@ -91,7 +91,7 @@ struct sockaddr_un sun;
 
 #define ACK_BYTE '\n'
 
-static struct sockaddr_unix socket_sun;
+static struct sockaddr_un socket_sun;
 static const char *const *executor_argv;
 
 static void propagate_exit_status(int status, const char *what) {
@@ -130,11 +130,11 @@ static void propagate_exit_status(int status, const char *what) {
          signame);
     }
 
-    die("setup failed due to signal %d %s%s", sig, signame,
+    die("%s failed due to signal %d %s%s", what, sig, signame,
        WCOREDUMP(status) ? " (core dumped)" : "");
   }
 
-  die("setup failed with weird wait status %d 0x%x", status, status);
+  die("%s failed with weird wait status %d 0x%x", what, status, status);
 }
 
 static __attribute((noreturn)) void die_data_overflow(void) {
@@ -256,6 +256,10 @@ static FILE *call_sock_from_fd(int fd) {
   return call_sock;
 }
 
+static bool was_eof(FILE *call_sock) {
+  return feof(call_sock) || errno==ECONNRESET;
+}
+
 // Returns: call(client-end), or 0 to mean "is garbage"
 // find_socket_path must have been called
 static FILE *connect_existing(void) {
@@ -279,7 +283,7 @@ static FILE *connect_existing(void) {
   char ack;
   size_t sr = fread(&ack, sizeof(ack), 1, call_sock);
   if (sr != 1) {
-    if (feof(call_sock) || errno==ECONNRESET) goto x_garbage;
+    if (was_eof(call_sock)) goto x_garbage;
     diee("read() ack byte");
   }
   if (ack != '\n') die("got ack byte 0x%02x, not '\n'", ack);
@@ -358,7 +362,7 @@ static FILE *connect_or_spawn(void) {
   if (got == (pid_t)-1) diee("waitpid setup [%ld]", (long)setup_pid);
   if (got != setup_pid) diee("waitpid setup [%ld] gave [%ld]!",
                             (long)setup_pid, (long)got);
-  if (status != 0) propagate_exit_status(status, "invocation");
+  if (status != 0) propagate_exit_status(status, "setup");
 
   close(lockfd);
   return call_sock_from_fd(fake_pair[0]);
@@ -401,4 +405,16 @@ int main(int argc_unused, const char *const *argv) {
   strncpy(sun.sun_path, socket_path, sizeof(sun.sun_path));
 
   FILE *call_sock = connect_or_spawn();
+  uint32_t status;
+  ssize_t sr = fread(&status, sizeof(status), 1, call_sock);
+  if (sr != 1) {
+    if (was_eof(call_sock)) die("per-call server monitor process quit");
+    diee("read status from call socket");
+  }
+
+  status = ntohl(status);
+  if (status > INT_MAX) die("status 0x%lx does not fit in an int",
+                           (unsigned long)status);
+
+  propagate_exit_status(status, "invocation");
 }