diff options
| author | Thiago de Arruda <tpadilha84@gmail.com> | 2015-03-28 11:30:23 -0300 |
|---|---|---|
| committer | Thiago de Arruda <tpadilha84@gmail.com> | 2015-03-29 20:35:44 -0300 |
| commit | 028f6d7d3f822dd620873a2a51c2d68ab1ef0b95 (patch) | |
| tree | d11b222424c732f4824857b7f2e8508280c5befe /src/nvim/os | |
| parent | 6e7757ad51dfe3b2de857ff8a8688718ff6115ac (diff) | |
| download | rneovim-028f6d7d3f822dd620873a2a51c2d68ab1ef0b95.tar.gz rneovim-028f6d7d3f822dd620873a2a51c2d68ab1ef0b95.tar.bz2 rneovim-028f6d7d3f822dd620873a2a51c2d68ab1ef0b95.zip | |
eval: Implement `jobwait()` vimscript function
Diffstat (limited to 'src/nvim/os')
| -rw-r--r-- | src/nvim/os/job.c | 12 | ||||
| -rw-r--r-- | src/nvim/os/job_defs.h | 1 |
2 files changed, 10 insertions, 3 deletions
diff --git a/src/nvim/os/job.c b/src/nvim/os/job.c index ccd7891601..7d9a91a1b2 100644 --- a/src/nvim/os/job.c +++ b/src/nvim/os/job.c @@ -24,7 +24,6 @@ // before we send SIGNAL to it #define TERM_TIMEOUT 1000000000 #define KILL_TIMEOUT (TERM_TIMEOUT * 2) -#define MAX_RUNNING_JOBS 100 #define JOB_BUFFER_SIZE 0xFFFF #define close_job_stream(job, stream, type) \ @@ -234,11 +233,12 @@ void job_stop(Job *job) /// @return returns the status code of the exited job. -1 if the job is /// still running and the `timeout` has expired. Note that this is /// indistinguishable from the process returning -1 by itself. Which -/// is possible on some OS. +/// is possible on some OS. Returns -2 if the job was interrupted. int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL { // The default status is -1, which represents a timeout int status = -1; + bool interrupted = false; // Increase refcount to stop the job from being freed before we have a // chance to get the status. @@ -251,6 +251,7 @@ int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL // we'll assume that a user frantically hitting interrupt doesn't like // the current job. Signal that it has to be killed. if (got_int) { + interrupted = true; got_int = false; job_stop(job); if (ms == -1) { @@ -265,7 +266,7 @@ int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL if (job->refcount == 1) { // Job exited, collect status and manually invoke close_cb to free the job // resources - status = job->status; + status = interrupted ? -2 : job->status; job_close_streams(job); job_decref(job); } else { @@ -357,6 +358,11 @@ void job_close_streams(Job *job) close_job_err(job); } +JobOptions *job_opts(Job *job) +{ + return &job->opts; +} + /// Iterates the table, sending SIGTERM to stopped jobs and SIGKILL to those /// that didn't die from SIGTERM after a while(exit_timeout is 0). static void job_stop_timer_cb(uv_timer_t *handle) diff --git a/src/nvim/os/job_defs.h b/src/nvim/os/job_defs.h index 200cf75e59..7fee900ac0 100644 --- a/src/nvim/os/job_defs.h +++ b/src/nvim/os/job_defs.h @@ -5,6 +5,7 @@ #include "nvim/os/rstream_defs.h" #include "nvim/os/wstream_defs.h" +#define MAX_RUNNING_JOBS 100 typedef struct job Job; /// Function called when the job reads data |