aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/event/process.c
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2016-01-20 11:55:40 +0100
committerBjörn Linse <bjorn.linse@gmail.com>2016-01-20 11:55:40 +0100
commit297075bf47d09437deb82266c61cd830dc8d72eb (patch)
treeb6a2e2f41abb83f0f732ad259cddf7dab66ef741 /src/nvim/event/process.c
parentee0e214427d7ed2a9fd8ffc85c424cfffc927408 (diff)
parentf6ecd127b9c999b63d33e2da542f32528530698a (diff)
downloadrneovim-297075bf47d09437deb82266c61cd830dc8d72eb.tar.gz
rneovim-297075bf47d09437deb82266c61cd830dc8d72eb.tar.bz2
rneovim-297075bf47d09437deb82266c61cd830dc8d72eb.zip
Merge pull request #3944 from bfredl/detach
job control: add `detach` option and `jobpid` function and teardown PTY processes correctly.
Diffstat (limited to 'src/nvim/event/process.c')
-rw-r--r--src/nvim/event/process.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/nvim/event/process.c b/src/nvim/event/process.c
index 0336eb880a..e6012595fd 100644
--- a/src/nvim/event/process.c
+++ b/src/nvim/event/process.c
@@ -29,6 +29,7 @@
} \
} while (0)
+static bool process_is_tearing_down = false;
bool process_spawn(Process *proc) FUNC_ATTR_NONNULL_ALL
{
@@ -112,11 +113,22 @@ bool process_spawn(Process *proc) FUNC_ATTR_NONNULL_ALL
void process_teardown(Loop *loop) FUNC_ATTR_NONNULL_ALL
{
+ process_is_tearing_down = true;
kl_iter(WatcherPtr, loop->children, current) {
Process *proc = (*current)->data;
- uv_kill(proc->pid, SIGTERM);
- proc->term_sent = true;
- process_stop(proc);
+ if (proc->detach) {
+ // Close handles to process without killing it.
+ CREATE_EVENT(loop->events, process_close_handles, 1, proc);
+ } else {
+ if (proc->type == kProcessTypeUv) {
+ uv_kill(proc->pid, SIGTERM);
+ proc->term_sent = true;
+ process_stop(proc);
+ } else { // kProcessTypePty
+ process_close_streams(proc);
+ pty_process_close_master((PtyProcess *)proc);
+ }
+ }
}
// Wait until all children exit
@@ -303,6 +315,10 @@ static void decref(Process *proc)
static void process_close(Process *proc)
FUNC_ATTR_NONNULL_ARG(1)
{
+ if (process_is_tearing_down && proc->detach && proc->closed) {
+ // If a detached process dies while tearing down it might get closed twice.
+ return;
+ }
assert(!proc->closed);
proc->closed = true;
switch (proc->type) {
@@ -333,6 +349,7 @@ static void on_process_exit(Process *proc)
DLOG("Stopping process kill timer");
uv_timer_stop(&loop->children_kill_timer);
}
+
// Process handles are closed in the next event loop tick. This is done to
// give libuv more time to read data from the OS after the process exits(If
// process_close_streams is called with data still in the OS buffer, we lose