aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/event/process.c
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2016-01-04 17:15:25 +0100
committerBjörn Linse <bjorn.linse@gmail.com>2016-01-20 11:09:25 +0100
commitd0d5d17b69b635096bc4c0f88c4a9b10af04cf01 (patch)
tree555e96fd7a50e223e35d41492a785e4ba39ad350 /src/nvim/event/process.c
parentee0e214427d7ed2a9fd8ffc85c424cfffc927408 (diff)
downloadrneovim-d0d5d17b69b635096bc4c0f88c4a9b10af04cf01.tar.gz
rneovim-d0d5d17b69b635096bc4c0f88c4a9b10af04cf01.tar.bz2
rneovim-d0d5d17b69b635096bc4c0f88c4a9b10af04cf01.zip
job control: add 'detach' option to jobstart
Diffstat (limited to 'src/nvim/event/process.c')
-rw-r--r--src/nvim/event/process.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/nvim/event/process.c b/src/nvim/event/process.c
index 0336eb880a..d365a78a9d 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,17 @@ 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 {
+ uv_kill(proc->pid, SIGTERM);
+ proc->term_sent = true;
+ process_stop(proc);
+ }
}
// Wait until all children exit
@@ -303,6 +310,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 +344,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