aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2015-03-29 21:07:56 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2015-03-29 21:07:56 -0300
commit960b9108c2928b6cf0adcabdb829d06996635211 (patch)
treeccae254cda1e902971d2689210d14d8f44ebc4b8 /src/nvim/os
parent2c7e8c38e0f483cf803eb225720cd11ae370ae75 (diff)
parentb94f29004b8d74e80156853695a1aaeec857085d (diff)
downloadrneovim-960b9108c2928b6cf0adcabdb829d06996635211.tar.gz
rneovim-960b9108c2928b6cf0adcabdb829d06996635211.tar.bz2
rneovim-960b9108c2928b6cf0adcabdb829d06996635211.zip
Merge PR #2247 'Refactor/enhance job api'
Diffstat (limited to 'src/nvim/os')
-rw-r--r--src/nvim/os/job.c24
-rw-r--r--src/nvim/os/job_defs.h3
-rw-r--r--src/nvim/os/job_private.h2
3 files changed, 24 insertions, 5 deletions
diff --git a/src/nvim/os/job.c b/src/nvim/os/job.c
index ccd7891601..8fe44c7a53 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 {
@@ -289,6 +290,18 @@ void job_close_in(Job *job) FUNC_ATTR_NONNULL_ALL
close_job_in(job);
}
+// Close the job stdout stream.
+void job_close_out(Job *job) FUNC_ATTR_NONNULL_ALL
+{
+ close_job_out(job);
+}
+
+// Close the job stderr stream.
+void job_close_err(Job *job) FUNC_ATTR_NONNULL_ALL
+{
+ close_job_out(job);
+}
+
/// All writes that complete after calling this function will be reported
/// to `cb`.
///
@@ -357,6 +370,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 ac9a37b366..7fee900ac0 100644
--- a/src/nvim/os/job_defs.h
+++ b/src/nvim/os/job_defs.h
@@ -5,13 +5,14 @@
#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
///
/// @param id The job id
/// @param data Some data associated with the job by the caller
-typedef void (*job_exit_cb)(Job *job, void *data);
+typedef void (*job_exit_cb)(Job *job, int status, void *data);
// Job startup options
// job_exit_cb Callback that will be invoked when the job exits
diff --git a/src/nvim/os/job_private.h b/src/nvim/os/job_private.h
index b1d5e13feb..af13d2e636 100644
--- a/src/nvim/os/job_private.h
+++ b/src/nvim/os/job_private.h
@@ -88,7 +88,7 @@ static inline void job_exit_callback(Job *job)
if (job->opts.exit_cb) {
// Invoke the exit callback
- job->opts.exit_cb(job, job->opts.data);
+ job->opts.exit_cb(job, job->status, job->opts.data);
}
if (stop_requests && !--stop_requests) {