process.c: Fix a block when in teardown mode

nvim blocking can be tested with "nvim +te +'!xclip' +qa"

By closing all handles for a pty process, we unblock the event loop if
the process has not terminated yet.
This commit is contained in:
oni-link
2016-05-20 21:19:10 +02:00
parent 48e945e588
commit 677eae6b0f

View File

@@ -116,18 +116,13 @@ 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);
}
} }
} }
@@ -315,8 +310,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);