Fix parsing of child pid and exit code

This commit is contained in:
Kovid Goyal 2022-07-02 13:51:30 +05:30
parent 2525994db4
commit c7718d078c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 7 additions and 3 deletions

View File

@ -446,7 +446,7 @@ class SocketChild:
def handle_death(self, status: int) -> None:
if hasattr(os, 'waitstatus_to_exitcode'):
status = os.waitstatus_to_exitcode(status)
self.conn.sendall(f'{status}:'.encode('ascii'))
self.conn.sendall(f'{status}'.encode('ascii'))
self.conn.shutdown(socket.SHUT_RDWR)
self.conn.close()
@ -626,7 +626,7 @@ def main(stdin_fd: int, stdout_fd: int, notify_child_death_fd: int, unix_socket:
poll.unregister(scq.fd)
scq.conn.shutdown(socket.SHUT_RD)
scq.fork(get_all_non_child_fds())
scq.child_id = child_pid_map[scq.pid] = next(child_id_counter)
scq.child_id = next(child_id_counter)
except SocketClosed:
socket_children.pop(q)
continue

View File

@ -289,10 +289,14 @@ read_child_data(void) {
from_child_buf_pos += n;
char *p = memchr(from_child_buf, ':', from_child_buf_pos);
if (p && child_pid == 0) {
*p = 0;
long cp = 0;
if (!parse_long(from_child_buf, &cp)) { print_error("Could not parse child pid from prewarm socket", 0); return false; }
if (cp == 0) { print_error("Got zero child pid from prewarm socket", 0); return false; }
child_pid = cp;
memset(from_child_buf, 0, (p - from_child_buf) + 1);
from_child_buf_pos -= (p - from_child_buf) + 1;
if (from_child_buf_pos) memmove(from_child_buf, p + 1, from_child_buf_pos);
}
}
return true;
@ -344,7 +348,7 @@ loop(void) {
if (!read_child_data()) fail("reading information about child failed");
}
if (poll_data[2].revents & POLLHUP) {
if (from_child_buf[0]) { char *p = memchr(from_child_buf, ':', sizeof(from_child_buf)); if (p) parse_int(p+1, &exit_status); }
if (from_child_buf[0]) { parse_int(from_child_buf, &exit_status); }
return;
}
if (poll_data[2].revents & POLLOUT) {