static const char *const *executor_argv;
+static const char header_magic[4] = "PFI\n";
+
void fusagemessage(FILE *f) {
fprintf(f, "usage: #!/usr/bin/prefork-interp [<options>]\n");
}
die("monitor process quit unexpectedly");
}
-// Does protocol exchange. Returns 0 if OK, error msg if peer was garbage.
-static const char *protocol_exchange(FILE *call_sock) {
- char magic[sizeof(header_magic)];
+// Returns 0 if OK, error msg if peer was garbage.
+static const char *protocol_greeting(FILE *call_sock) {
+ char got_magic[sizeof(header_magic)];
- if (protocol_read_maybe(&magic, sizeof(magic)) < 0)
+ if (protocol_read_maybe(call_sock, &got_magic, sizeof(got_magic)) < 0)
return "initial monitor process quit";
- if (memcmp(header, header_magic, sizeof(header_magic)))
- die("got unexpected protocol magic 0x%04lx",
- header[0], header[1], header[2], header[3]);
+ if (memcmp(got_magic, header_magic, sizeof(header_magic)))
+ die("got unexpected protocol magic 0x%02x%02x%02x%02x",
+ got_magic[0], got_magic[1], got_magic[2], got_magic[3]);
uint32_t xdata_len;
- protocol_read(&xdata_len, sizeof(xdata_len));
+ protocol_read(call_sock, &xdata_len, sizeof(xdata_len));
void *xdata = xmalloc(xdata_len);
- protocol_read(xdata, xdata_len);
-
- // We're committed now, send the request (or bail out)
- send_request(call_sock);
+ protocol_read(call_sock, xdata, xdata_len);
return 0;
}
call_sock = call_sock_from_fd(fd);
fd = -1;
- if (protocol_exchange(call_sock))
+ if (protocol_greeting(call_sock))
goto x_garbage;
return call_sock;
close(sfd);
call_sock = call_sock_from_fd(fake_pair[0]);
- const char *emsg = protocol_exchange(call_sock);
- if (emsg) die("setup failed: %s", emsg);
int status;
pid_t got = waitpid(setup_pid, &status, 0);
(long)setup_pid, (long)got);
if (status != 0) propagate_exit_status(status, "setup");
+ const char *emsg = protocol_greeting(call_sock);
+ if (emsg) die("setup failed: %s", emsg);
+
close(lockfd);
return call_sock;
}
strncpy(sockaddr_sun.sun_path, socket_path, sizeof(sockaddr_sun.sun_path));
FILE *call_sock = connect_or_spawn();
+
+ // We're committed now, send the request (or bail out)
+ send_request(call_sock);
+
uint32_t status;
- protocol_read(&status, sizeof(status);
+ protocol_read(call_sock, &status, sizeof(status));
status = ntohl(status);
if (status > INT_MAX) die("status 0x%lx does not fit in an int",