Fix parsing of child pid and exit code
This commit is contained in:
parent
2525994db4
commit
c7718d078c
@ -446,7 +446,7 @@ class SocketChild:
|
|||||||
def handle_death(self, status: int) -> None:
|
def handle_death(self, status: int) -> None:
|
||||||
if hasattr(os, 'waitstatus_to_exitcode'):
|
if hasattr(os, 'waitstatus_to_exitcode'):
|
||||||
status = os.waitstatus_to_exitcode(status)
|
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.shutdown(socket.SHUT_RDWR)
|
||||||
self.conn.close()
|
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)
|
poll.unregister(scq.fd)
|
||||||
scq.conn.shutdown(socket.SHUT_RD)
|
scq.conn.shutdown(socket.SHUT_RD)
|
||||||
scq.fork(get_all_non_child_fds())
|
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:
|
except SocketClosed:
|
||||||
socket_children.pop(q)
|
socket_children.pop(q)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@ -289,10 +289,14 @@ read_child_data(void) {
|
|||||||
from_child_buf_pos += n;
|
from_child_buf_pos += n;
|
||||||
char *p = memchr(from_child_buf, ':', from_child_buf_pos);
|
char *p = memchr(from_child_buf, ':', from_child_buf_pos);
|
||||||
if (p && child_pid == 0) {
|
if (p && child_pid == 0) {
|
||||||
|
*p = 0;
|
||||||
long cp = 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 (!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; }
|
if (cp == 0) { print_error("Got zero child pid from prewarm socket", 0); return false; }
|
||||||
child_pid = cp;
|
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;
|
return true;
|
||||||
@ -344,7 +348,7 @@ loop(void) {
|
|||||||
if (!read_child_data()) fail("reading information about child failed");
|
if (!read_child_data()) fail("reading information about child failed");
|
||||||
}
|
}
|
||||||
if (poll_data[2].revents & POLLHUP) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (poll_data[2].revents & POLLOUT) {
|
if (poll_data[2].revents & POLLOUT) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user