summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
7f9d763)
This is much less typing.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
const char our_name[] = "prefork-interp";
static struct sockaddr_un sockaddr_sun;
const char our_name[] = "prefork-interp";
static struct sockaddr_un sockaddr_sun;
prepare_string(len, buf, s);
}
prepare_string(len, buf, s);
}
-static void send_fd(FILE *call_sock, int payload_fd) {
+static void send_fd(int payload_fd) {
int via_fd = fileno(call_sock);
union {
int via_fd = fileno(call_sock);
union {
-static void send_request(FILE *call_sock) {
+static void send_request(void) {
// Sending these first makes it easier for the script to
// use buffered IO for the message.
// Sending these first makes it easier for the script to
// use buffered IO for the message.
- send_fd(call_sock, 0);
- send_fd(call_sock, 1);
- send_fd(call_sock, 2);
+ send_fd(0);
+ send_fd(1);
+ send_fd(2);
size_t len = 4;
prepare_message(&len, 0);
size_t len = 4;
prepare_message(&len, 0);
-static int protocol_read_maybe(FILE *call_sock, void *data, size_t sz) {
+static int protocol_read_maybe(void *data, size_t sz) {
size_t sr = fread(data, sz, 1, call_sock);
if (sr != 1) {
if (was_eof(call_sock)) return -1;
size_t sr = fread(data, sz, 1, call_sock);
if (sr != 1) {
if (was_eof(call_sock)) return -1;
-static void protocol_read(FILE *call_sock, void *data, size_t sz) {
- if (protocol_read_maybe(call_sock, data, sz) < 0)
+static void protocol_read(void *data, size_t sz) {
+ if (protocol_read_maybe(data, sz) < 0)
die("monitor process quit unexpectedly");
}
// Returns 0 if OK, error msg if peer was garbage.
die("monitor process quit unexpectedly");
}
// Returns 0 if OK, error msg if peer was garbage.
-static const char *protocol_greeting(FILE *call_sock) {
+static const char *protocol_greeting(void) {
char got_magic[sizeof(header_magic)];
char got_magic[sizeof(header_magic)];
- if (protocol_read_maybe(call_sock, &got_magic, sizeof(got_magic)) < 0)
+ if (protocol_read_maybe(&got_magic, sizeof(got_magic)) < 0)
return "initial monitor process quit";
if (memcmp(got_magic, header_magic, sizeof(header_magic)))
return "initial monitor process quit";
if (memcmp(got_magic, header_magic, sizeof(header_magic)))
got_magic[0], got_magic[1], got_magic[2], got_magic[3]);
uint32_t xdata_len;
got_magic[0], got_magic[1], got_magic[2], got_magic[3]);
uint32_t xdata_len;
- protocol_read(call_sock, &xdata_len, sizeof(xdata_len));
+ protocol_read(&xdata_len, sizeof(xdata_len));
void *xdata = xmalloc(xdata_len);
void *xdata = xmalloc(xdata_len);
- protocol_read(call_sock, xdata, xdata_len);
+ protocol_read(xdata, xdata_len);
static FILE *connect_existing(void) {
int r;
int fd = -1;
static FILE *connect_existing(void) {
int r;
int fd = -1;
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd==-1) diee("socket() for client");
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd==-1) diee("socket() for client");
call_sock = call_sock_from_fd(fd);
fd = -1;
call_sock = call_sock_from_fd(fd);
fd = -1;
- if (protocol_greeting(call_sock))
+ if (protocol_greeting())
goto x_garbage;
return call_sock;
x_garbage:
goto x_garbage;
return call_sock;
x_garbage:
- if (call_sock) fclose(call_sock);
+ if (call_sock) { fclose(call_sock); call_sock=0; }
if (fd >= 0) close(fd);
return 0;
}
if (fd >= 0) close(fd);
return 0;
}
diee("execute %s", executor_argv[0]);
}
diee("execute %s", executor_argv[0]);
}
-static FILE *connect_or_spawn(void) {
+static void connect_or_spawn(void) {
- FILE *call_sock = connect_existing();
- if (call_sock) return call_sock;
+ call_sock = connect_existing();
+ if (call_sock) return;
int lockfd = acquire_lock();
call_sock = connect_existing();
int lockfd = acquire_lock();
call_sock = connect_existing();
- if (call_sock) { close(lockfd); return call_sock; }
+ if (call_sock) { close(lockfd); return; }
// We must start a fresh one, and we hold the lock
// We must start a fresh one, and we hold the lock
(long)setup_pid, (long)got);
if (status != 0) propagate_exit_status(status, "setup");
(long)setup_pid, (long)got);
if (status != 0) propagate_exit_status(status, "setup");
- const char *emsg = protocol_greeting(call_sock);
+ const char *emsg = protocol_greeting();
if (emsg) die("setup failed: %s", emsg);
close(lockfd);
if (emsg) die("setup failed: %s", emsg);
close(lockfd);
}
static void make_executor_argv(const char *const *argv) {
}
static void make_executor_argv(const char *const *argv) {
assert(strlen(socket_path) <= sizeof(sockaddr_sun.sun_path));
strncpy(sockaddr_sun.sun_path, socket_path, sizeof(sockaddr_sun.sun_path));
assert(strlen(socket_path) <= sizeof(sockaddr_sun.sun_path));
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)
// We're committed now, send the request (or bail out)
- send_request(call_sock);
- protocol_read(call_sock, &status, sizeof(status));
+ protocol_read(&status, sizeof(status));
status = ntohl(status);
if (status > INT_MAX) die("status 0x%lx does not fit in an int",
status = ntohl(status);
if (status > INT_MAX) die("status 0x%lx does not fit in an int",