summaryrefslogtreecommitdiff
path: root/src/os_unix.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-02-10 22:43:46 +0100
committerBram Moolenaar <Bram@vim.org>2019-02-10 22:43:46 +0100
commit593864817a08f9b719a093ef4fd8d4d35132ab86 (patch)
tree03f050e9a044d96c89545d114fd7f455fb6c3aff /src/os_unix.c
parent6524068ff3252f1373807f1ebfde21408cef624e (diff)
downloadvim-git-593864817a08f9b719a093ef4fd8d4d35132ab86.tar.gz
patch 8.1.0890: pty allocation wrong if using file for out channelv8.1.0890
Problem: Pty allocation wrong if using file for out channel and using null for in channel and null for error channel. Solution: Correct using use_file_for_out in condition. (Ozaki Kiichi, closes #3917)
Diffstat (limited to 'src/os_unix.c')
-rw-r--r--src/os_unix.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/os_unix.c b/src/os_unix.c
index a17abe3d5..425498c6b 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -4196,13 +4196,19 @@ set_default_child_environment(int is_terminal)
/*
* Open a PTY, with FD for the master and slave side.
* When failing "pty_master_fd" and "pty_slave_fd" are -1.
- * When successful both file descriptors are stored.
+ * When successful both file descriptors are stored and the allocated pty name
+ * is stored in both "*name1" and "*name2".
*/
static void
-open_pty(int *pty_master_fd, int *pty_slave_fd, char_u **namep)
+open_pty(int *pty_master_fd, int *pty_slave_fd, char_u **name1, char_u **name2)
{
char *tty_name;
+ if (name1 != NULL)
+ *name1 = NULL;
+ if (name2 != NULL)
+ *name2 = NULL;
+
*pty_master_fd = mch_openpty(&tty_name); // open pty
if (*pty_master_fd >= 0)
{
@@ -4219,8 +4225,13 @@ open_pty(int *pty_master_fd, int *pty_slave_fd, char_u **namep)
close(*pty_master_fd);
*pty_master_fd = -1;
}
- else if (namep != NULL)
- *namep = vim_strsave((char_u *)tty_name);
+ else
+ {
+ if (name1 != NULL)
+ *name1 = vim_strsave((char_u *)tty_name);
+ if (name2 != NULL)
+ *name2 = vim_strsave((char_u *)tty_name);
+ }
}
}
#endif
@@ -4513,7 +4524,7 @@ mch_call_shell_fork(
* If the slave can't be opened, close the master pty.
*/
if (p_guipty && !(options & (SHELL_READ|SHELL_WRITE)))
- open_pty(&pty_master_fd, &pty_slave_fd, NULL);
+ open_pty(&pty_master_fd, &pty_slave_fd, NULL, NULL);
/*
* If not opening a pty or it didn't work, try using pipes.
*/
@@ -5352,13 +5363,10 @@ mch_job_start(char **argv, job_T *job, jobopt_T *options, int is_terminal)
if (options->jo_pty
&& (!(use_file_for_in || use_null_for_in)
- || !(use_file_for_in || use_null_for_out)
+ || !(use_file_for_out || use_null_for_out)
|| !(use_out_for_err || use_file_for_err || use_null_for_err)))
- {
- open_pty(&pty_master_fd, &pty_slave_fd, &job->jv_tty_out);
- if (job->jv_tty_out != NULL)
- job->jv_tty_in = vim_strsave(job->jv_tty_out);
- }
+ open_pty(&pty_master_fd, &pty_slave_fd,
+ &job->jv_tty_out, &job->jv_tty_in);
/* TODO: without the channel feature connect the child to /dev/null? */
/* Open pipes for stdin, stdout, stderr. */
@@ -5834,9 +5842,7 @@ mch_create_pty_channel(job_T *job, jobopt_T *options)
int pty_slave_fd = -1;
channel_T *channel;
- open_pty(&pty_master_fd, &pty_slave_fd, &job->jv_tty_out);
- if (job->jv_tty_out != NULL)
- job->jv_tty_in = vim_strsave(job->jv_tty_out);
+ open_pty(&pty_master_fd, &pty_slave_fd, &job->jv_tty_out, &job->jv_tty_in);
close(pty_slave_fd);
channel = add_channel();