Merge #4798 'process.c: Fix block in teardown'

This commit is contained in:
Justin M. Keyes 2016-07-16 03:36:12 -04:00
commit 7fa1baf44e

View File

@ -116,23 +116,20 @@ void process_teardown(Loop *loop) FUNC_ATTR_NONNULL_ALL
process_is_tearing_down = true; process_is_tearing_down = true;
kl_iter(WatcherPtr, loop->children, current) { kl_iter(WatcherPtr, loop->children, current) {
Process *proc = (*current)->data; Process *proc = (*current)->data;
if (proc->detach) { if (proc->detach || proc->type == kProcessTypePty) {
// Close handles to process without killing it. // Close handles to process without killing it.
CREATE_EVENT(loop->events, process_close_handles, 1, proc); CREATE_EVENT(loop->events, process_close_handles, 1, proc);
} else { } else {
if (proc->type == kProcessTypeUv) { uv_kill(proc->pid, SIGTERM);
uv_kill(proc->pid, SIGTERM); proc->term_sent = true;
proc->term_sent = true; process_stop(proc);
process_stop(proc);
} else { // kProcessTypePty
process_close_streams(proc);
pty_process_close_master((PtyProcess *)proc);
}
} }
} }
// Wait until all children exit // Wait until all children exit and all close events are processed.
LOOP_PROCESS_EVENTS_UNTIL(loop, loop->events, -1, kl_empty(loop->children)); LOOP_PROCESS_EVENTS_UNTIL(
loop, loop->events, -1,
kl_empty(loop->children) && queue_empty(loop->events));
pty_process_teardown(loop); pty_process_teardown(loop);
} }
@ -315,8 +312,10 @@ static void decref(Process *proc)
static void process_close(Process *proc) static void process_close(Process *proc)
FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_NONNULL_ARG(1)
{ {
if (process_is_tearing_down && proc->detach && proc->closed) { if (process_is_tearing_down && (proc->detach || proc->type == kProcessTypePty)
// If a detached process dies while tearing down it might get closed twice. && proc->closed) {
// If a detached/pty process dies while tearing down it might get closed
// twice.
return; return;
} }
assert(!proc->closed); assert(!proc->closed);