diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2018-04-14 17:23:17 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-04-15 18:23:11 +0200 |
commit | 142ac021ac88387ef7319dc4eb1f430753480f44 (patch) | |
tree | 15c95a7e175774645b0f69eabd30b146dbc98144 | |
parent | 8fa0b8051dbe2f4e4a00c162913886a34bf78bfa (diff) | |
download | rneovim-142ac021ac88387ef7319dc4eb1f430753480f44.tar.gz rneovim-142ac021ac88387ef7319dc4eb1f430753480f44.tar.bz2 rneovim-142ac021ac88387ef7319dc4eb1f430753480f44.zip |
job-control: one-shot timer instead of repeating
Before f31c26f1afb5 the timer was used to try SIGTERM *and* SIGKILL, so
a repeating timer was needed. After f31c26f1afb5 process_stop() sends
SIGTERM immediately, and the timer only sends SIGKILL.
So we don't need a repeating timer.
- Simplifies the logic: don't need to call uv_timer_stop() explicitly.
- Avoids a problem: if process_stop() is called more than once in the
2-second window, the first on_process_exit() would call
uv_timer_stop() which stops the timer for all stopped processes.
-rw-r--r-- | src/nvim/event/process.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/nvim/event/process.c b/src/nvim/event/process.c index 59bf2fccf3..312da54c76 100644 --- a/src/nvim/event/process.c +++ b/src/nvim/event/process.c @@ -111,6 +111,7 @@ int process_spawn(Process *proc, bool in, bool out, bool err) proc->internal_close_cb = decref; proc->refcount++; kl_push(WatcherPtr, proc->loop->children, proc); + DLOG("new: pid=%d argv=[%s]", proc->pid, *proc->argv); return 0; } @@ -227,11 +228,10 @@ void process_stop(Process *proc) FUNC_ATTR_NONNULL_ALL abort(); } - Loop *loop = proc->loop; - // Start a timer to periodically check if a signal should be sent to the job. + // Start a timer to verify that the job process terminated. ILOG("starting job kill timer"); - uv_timer_start(&loop->children_kill_timer, children_kill_cb, - KILL_TIMEOUT_MS, KILL_TIMEOUT_MS); + uv_timer_start(&proc->loop->children_kill_timer, children_kill_cb, + KILL_TIMEOUT_MS, 0); } /// Sends SIGKILL (or SIGTERM for PTY jobs) to processes that didn't terminate @@ -380,12 +380,8 @@ static void process_close_handles(void **argv) static void on_process_exit(Process *proc) { Loop *loop = proc->loop; - ILOG("exited: pid=%d status=%d stoptime=%" PRId64, proc->pid, - proc->status, proc->stopped_time); - if (proc->stopped_time) { - ILOG("stopping process kill timer"); - uv_timer_stop(&loop->children_kill_timer); - } + ILOG("exited: pid=%d status=%d stoptime=%" PRIu64, proc->pid, proc->status, + proc->stopped_time); // Process has terminated, but there could still be data to be read from the // OS. We are still in the libuv loop, so we cannot call code that polls for |