diff src/os_unix.c @ 11933:d033653d3df8 v8.0.0846

patch 8.0.0846: cannot get the name of the pty of a job commit https://github.com/vim/vim/commit/7c9aec4ac86ccc455c0859d9393253141e3f77b6 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Aug 3 13:51:25 2017 +0200 patch 8.0.0846: cannot get the name of the pty of a job Problem: Cannot get the name of the pty of a job. Solution: Add the "tty" entry to the job info. (Ozaki Kiichi, closes https://github.com/vim/vim/issues/1920) Add the term_gettty() function.
author Christian Brabandt <cb@256bit.org>
date Thu, 03 Aug 2017 14:00:06 +0200
parents fe6675d67a10
children 74e45c11b754
line wrap: on
line diff
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -4170,7 +4170,7 @@ set_default_child_environment(void)
  * When successful both file descriptors are stored.
  */
     static void
-open_pty(int *pty_master_fd, int *pty_slave_fd)
+open_pty(int *pty_master_fd, int *pty_slave_fd, char_u **namep)
 {
     char	*tty_name;
 
@@ -4190,6 +4190,8 @@ open_pty(int *pty_master_fd, int *pty_sl
 	    close(*pty_master_fd);
 	    *pty_master_fd = -1;
 	}
+	else if (namep != NULL)
+	    *namep = vim_strsave((char_u *)tty_name);
     }
 }
 #endif
@@ -4384,7 +4386,7 @@ mch_call_shell(
 	 * 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);
+	    open_pty(&pty_master_fd, &pty_slave_fd, NULL);
 	/*
 	 * If not opening a pty or it didn't work, try using pipes.
 	 */
@@ -5189,9 +5191,9 @@ error:
 mch_job_start(char **argv, job_T *job, jobopt_T *options)
 {
     pid_t	pid;
-    int		fd_in[2];	/* for stdin */
-    int		fd_out[2];	/* for stdout */
-    int		fd_err[2];	/* for stderr */
+    int		fd_in[2] = {-1, -1};	/* for stdin */
+    int		fd_out[2] = {-1, -1};	/* for stdout */
+    int		fd_err[2] = {-1, -1};	/* for stderr */
     int		pty_master_fd = -1;
     int		pty_slave_fd = -1;
     channel_T	*channel = NULL;
@@ -5209,15 +5211,9 @@ mch_job_start(char **argv, job_T *job, j
 
     /* default is to fail */
     job->jv_status = JOB_FAILED;
-    fd_in[0] = -1;
-    fd_in[1] = -1;
-    fd_out[0] = -1;
-    fd_out[1] = -1;
-    fd_err[0] = -1;
-    fd_err[1] = -1;
 
     if (options->jo_pty)
-	open_pty(&pty_master_fd, &pty_slave_fd);
+	open_pty(&pty_master_fd, &pty_slave_fd, &job->jv_tty_name);
 
     /* TODO: without the channel feature connect the child to /dev/null? */
     /* Open pipes for stdin, stdout, stderr. */