comparison 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
comparison
equal deleted inserted replaced
11932:6dd3262cbf09 11933:d033653d3df8
4168 * Open a PTY, with FD for the master and slave side. 4168 * Open a PTY, with FD for the master and slave side.
4169 * When failing "pty_master_fd" and "pty_slave_fd" are -1. 4169 * When failing "pty_master_fd" and "pty_slave_fd" are -1.
4170 * When successful both file descriptors are stored. 4170 * When successful both file descriptors are stored.
4171 */ 4171 */
4172 static void 4172 static void
4173 open_pty(int *pty_master_fd, int *pty_slave_fd) 4173 open_pty(int *pty_master_fd, int *pty_slave_fd, char_u **namep)
4174 { 4174 {
4175 char *tty_name; 4175 char *tty_name;
4176 4176
4177 *pty_master_fd = OpenPTY(&tty_name); /* open pty */ 4177 *pty_master_fd = OpenPTY(&tty_name); /* open pty */
4178 if (*pty_master_fd >= 0) 4178 if (*pty_master_fd >= 0)
4188 if (*pty_slave_fd < 0) 4188 if (*pty_slave_fd < 0)
4189 { 4189 {
4190 close(*pty_master_fd); 4190 close(*pty_master_fd);
4191 *pty_master_fd = -1; 4191 *pty_master_fd = -1;
4192 } 4192 }
4193 else if (namep != NULL)
4194 *namep = vim_strsave((char_u *)tty_name);
4193 } 4195 }
4194 } 4196 }
4195 #endif 4197 #endif
4196 4198
4197 /* 4199 /*
4382 * Try to open a master pty. 4384 * Try to open a master pty.
4383 * If this works, open the slave pty. 4385 * If this works, open the slave pty.
4384 * If the slave can't be opened, close the master pty. 4386 * If the slave can't be opened, close the master pty.
4385 */ 4387 */
4386 if (p_guipty && !(options & (SHELL_READ|SHELL_WRITE))) 4388 if (p_guipty && !(options & (SHELL_READ|SHELL_WRITE)))
4387 open_pty(&pty_master_fd, &pty_slave_fd); 4389 open_pty(&pty_master_fd, &pty_slave_fd, NULL);
4388 /* 4390 /*
4389 * If not opening a pty or it didn't work, try using pipes. 4391 * If not opening a pty or it didn't work, try using pipes.
4390 */ 4392 */
4391 if (pty_master_fd < 0) 4393 if (pty_master_fd < 0)
4392 # endif 4394 # endif
5187 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) 5189 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO)
5188 void 5190 void
5189 mch_job_start(char **argv, job_T *job, jobopt_T *options) 5191 mch_job_start(char **argv, job_T *job, jobopt_T *options)
5190 { 5192 {
5191 pid_t pid; 5193 pid_t pid;
5192 int fd_in[2]; /* for stdin */ 5194 int fd_in[2] = {-1, -1}; /* for stdin */
5193 int fd_out[2]; /* for stdout */ 5195 int fd_out[2] = {-1, -1}; /* for stdout */
5194 int fd_err[2]; /* for stderr */ 5196 int fd_err[2] = {-1, -1}; /* for stderr */
5195 int pty_master_fd = -1; 5197 int pty_master_fd = -1;
5196 int pty_slave_fd = -1; 5198 int pty_slave_fd = -1;
5197 channel_T *channel = NULL; 5199 channel_T *channel = NULL;
5198 int use_null_for_in = options->jo_io[PART_IN] == JIO_NULL; 5200 int use_null_for_in = options->jo_io[PART_IN] == JIO_NULL;
5199 int use_null_for_out = options->jo_io[PART_OUT] == JIO_NULL; 5201 int use_null_for_out = options->jo_io[PART_OUT] == JIO_NULL;
5207 if (use_out_for_err && use_null_for_out) 5209 if (use_out_for_err && use_null_for_out)
5208 use_null_for_err = TRUE; 5210 use_null_for_err = TRUE;
5209 5211
5210 /* default is to fail */ 5212 /* default is to fail */
5211 job->jv_status = JOB_FAILED; 5213 job->jv_status = JOB_FAILED;
5212 fd_in[0] = -1;
5213 fd_in[1] = -1;
5214 fd_out[0] = -1;
5215 fd_out[1] = -1;
5216 fd_err[0] = -1;
5217 fd_err[1] = -1;
5218 5214
5219 if (options->jo_pty) 5215 if (options->jo_pty)
5220 open_pty(&pty_master_fd, &pty_slave_fd); 5216 open_pty(&pty_master_fd, &pty_slave_fd, &job->jv_tty_name);
5221 5217
5222 /* TODO: without the channel feature connect the child to /dev/null? */ 5218 /* TODO: without the channel feature connect the child to /dev/null? */
5223 /* Open pipes for stdin, stdout, stderr. */ 5219 /* Open pipes for stdin, stdout, stderr. */
5224 if (use_file_for_in) 5220 if (use_file_for_in)
5225 { 5221 {