summaryrefslogtreecommitdiff
path: root/src/os_unix.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-05-05 21:01:00 +0200
committerBram Moolenaar <Bram@vim.org>2018-05-05 21:01:00 +0200
commitb0b98d523036d534755bf1cf79d1595e61c3f7ce (patch)
tree5ca3b11d4f59557fbacfe202ec574664d2132bf2 /src/os_unix.c
parentb833c1ef7be1ed216a967dd7262473ec97084fa2 (diff)
downloadvim-git-b0b98d523036d534755bf1cf79d1595e61c3f7ce.tar.gz
patch 8.0.1795: lose contact with jobs when :gui forksv8.0.1795
Problem: Lose contact with jobs when :gui forks. Solution: Don't fork when there is a running job. Make log message for a died job clearer. Also close the terminal when stderr and stdout are the same FD.
Diffstat (limited to 'src/os_unix.c')
-rw-r--r--src/os_unix.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/os_unix.c b/src/os_unix.c
index d20c94b9a..495d13475 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -5642,8 +5642,10 @@ mch_job_start(char **argv, job_T *job, jobopt_T *options)
? INVALID_FD : fd_in[1] < 0 ? pty_master_fd : fd_in[1];
int out_fd = use_file_for_out || use_null_for_out
? INVALID_FD : fd_out[0] < 0 ? pty_master_fd : fd_out[0];
+ /* When using pty_master_fd only set it for stdout, do not duplicate it
+ * for stderr, it only needs to be read once. */
int err_fd = use_out_for_err || use_file_for_err || use_null_for_err
- ? INVALID_FD : fd_err[0] < 0 ? pty_master_fd : fd_err[0];
+ ? INVALID_FD : fd_err[0] < 0 ? INVALID_FD : fd_err[0];
channel_set_pipes(channel, in_fd, out_fd, err_fd);
channel_set_job(channel, job, options);
@@ -5701,6 +5703,9 @@ mch_job_status(job_T *job)
if (wait_pid == -1)
{
/* process must have exited */
+ if (job->jv_status < JOB_ENDED)
+ ch_log(job->jv_channel, "Job no longer exists: %s",
+ strerror(errno));
goto return_dead;
}
if (wait_pid == 0)
@@ -5709,21 +5714,22 @@ mch_job_status(job_T *job)
{
/* LINTED avoid "bitwise operation on signed value" */
job->jv_exitval = WEXITSTATUS(status);
+ if (job->jv_status < JOB_ENDED)
+ ch_log(job->jv_channel, "Job exited with %d", job->jv_exitval);
goto return_dead;
}
if (WIFSIGNALED(status))
{
job->jv_exitval = -1;
+ if (job->jv_status < JOB_ENDED)
+ ch_log(job->jv_channel, "Job terminated by a signal");
goto return_dead;
}
return "run";
return_dead:
if (job->jv_status < JOB_ENDED)
- {
- ch_log(job->jv_channel, "Job ended");
job->jv_status = JOB_ENDED;
- }
return "dead";
}
@@ -5857,7 +5863,9 @@ mch_create_pty_channel(job_T *job, jobopt_T *options)
job->jv_channel = channel; /* ch_refcount was set by add_channel() */
channel->ch_keep_open = TRUE;
- channel_set_pipes(channel, pty_master_fd, pty_master_fd, pty_master_fd);
+ /* Only set the pty_master_fd for stdout, do not duplicate it for stderr,
+ * it only needs to be read once. */
+ channel_set_pipes(channel, pty_master_fd, pty_master_fd, INVALID_FD);
channel_set_job(channel, job, options);
return OK;
}