comparison src/os_unix.c @ 15766:9d18e8457209 v8.1.0890

patch 8.1.0890: pty allocation wrong if using file for out channel commit https://github.com/vim/vim/commit/593864817a08f9b719a093ef4fd8d4d35132ab86 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Feb 10 22:43:46 2019 +0100 patch 8.1.0890: pty allocation wrong if using file for out channel 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)
author Bram Moolenaar <Bram@vim.org>
date Sun, 10 Feb 2019 22:45:06 +0100
parents 287104a1d51e
children 7fad90423bd2
comparison
equal deleted inserted replaced
15765:e4f8d017a0c6 15766:9d18e8457209
4194 4194
4195 #if defined(FEAT_GUI) || defined(FEAT_JOB_CHANNEL) 4195 #if defined(FEAT_GUI) || defined(FEAT_JOB_CHANNEL)
4196 /* 4196 /*
4197 * Open a PTY, with FD for the master and slave side. 4197 * Open a PTY, with FD for the master and slave side.
4198 * When failing "pty_master_fd" and "pty_slave_fd" are -1. 4198 * When failing "pty_master_fd" and "pty_slave_fd" are -1.
4199 * When successful both file descriptors are stored. 4199 * When successful both file descriptors are stored and the allocated pty name
4200 * is stored in both "*name1" and "*name2".
4200 */ 4201 */
4201 static void 4202 static void
4202 open_pty(int *pty_master_fd, int *pty_slave_fd, char_u **namep) 4203 open_pty(int *pty_master_fd, int *pty_slave_fd, char_u **name1, char_u **name2)
4203 { 4204 {
4204 char *tty_name; 4205 char *tty_name;
4206
4207 if (name1 != NULL)
4208 *name1 = NULL;
4209 if (name2 != NULL)
4210 *name2 = NULL;
4205 4211
4206 *pty_master_fd = mch_openpty(&tty_name); // open pty 4212 *pty_master_fd = mch_openpty(&tty_name); // open pty
4207 if (*pty_master_fd >= 0) 4213 if (*pty_master_fd >= 0)
4208 { 4214 {
4209 /* Leaving out O_NOCTTY may lead to waitpid() always returning 4215 /* Leaving out O_NOCTTY may lead to waitpid() always returning
4217 if (*pty_slave_fd < 0) 4223 if (*pty_slave_fd < 0)
4218 { 4224 {
4219 close(*pty_master_fd); 4225 close(*pty_master_fd);
4220 *pty_master_fd = -1; 4226 *pty_master_fd = -1;
4221 } 4227 }
4222 else if (namep != NULL) 4228 else
4223 *namep = vim_strsave((char_u *)tty_name); 4229 {
4230 if (name1 != NULL)
4231 *name1 = vim_strsave((char_u *)tty_name);
4232 if (name2 != NULL)
4233 *name2 = vim_strsave((char_u *)tty_name);
4234 }
4224 } 4235 }
4225 } 4236 }
4226 #endif 4237 #endif
4227 4238
4228 /* 4239 /*
4511 * Try to open a master pty. 4522 * Try to open a master pty.
4512 * If this works, open the slave pty. 4523 * If this works, open the slave pty.
4513 * If the slave can't be opened, close the master pty. 4524 * If the slave can't be opened, close the master pty.
4514 */ 4525 */
4515 if (p_guipty && !(options & (SHELL_READ|SHELL_WRITE))) 4526 if (p_guipty && !(options & (SHELL_READ|SHELL_WRITE)))
4516 open_pty(&pty_master_fd, &pty_slave_fd, NULL); 4527 open_pty(&pty_master_fd, &pty_slave_fd, NULL, NULL);
4517 /* 4528 /*
4518 * If not opening a pty or it didn't work, try using pipes. 4529 * If not opening a pty or it didn't work, try using pipes.
4519 */ 4530 */
4520 if (pty_master_fd < 0) 4531 if (pty_master_fd < 0)
4521 # endif 4532 # endif
5350 /* default is to fail */ 5361 /* default is to fail */
5351 job->jv_status = JOB_FAILED; 5362 job->jv_status = JOB_FAILED;
5352 5363
5353 if (options->jo_pty 5364 if (options->jo_pty
5354 && (!(use_file_for_in || use_null_for_in) 5365 && (!(use_file_for_in || use_null_for_in)
5355 || !(use_file_for_in || use_null_for_out) 5366 || !(use_file_for_out || use_null_for_out)
5356 || !(use_out_for_err || use_file_for_err || use_null_for_err))) 5367 || !(use_out_for_err || use_file_for_err || use_null_for_err)))
5357 { 5368 open_pty(&pty_master_fd, &pty_slave_fd,
5358 open_pty(&pty_master_fd, &pty_slave_fd, &job->jv_tty_out); 5369 &job->jv_tty_out, &job->jv_tty_in);
5359 if (job->jv_tty_out != NULL)
5360 job->jv_tty_in = vim_strsave(job->jv_tty_out);
5361 }
5362 5370
5363 /* TODO: without the channel feature connect the child to /dev/null? */ 5371 /* TODO: without the channel feature connect the child to /dev/null? */
5364 /* Open pipes for stdin, stdout, stderr. */ 5372 /* Open pipes for stdin, stdout, stderr. */
5365 if (use_file_for_in) 5373 if (use_file_for_in)
5366 { 5374 {
5832 { 5840 {
5833 int pty_master_fd = -1; 5841 int pty_master_fd = -1;
5834 int pty_slave_fd = -1; 5842 int pty_slave_fd = -1;
5835 channel_T *channel; 5843 channel_T *channel;
5836 5844
5837 open_pty(&pty_master_fd, &pty_slave_fd, &job->jv_tty_out); 5845 open_pty(&pty_master_fd, &pty_slave_fd, &job->jv_tty_out, &job->jv_tty_in);
5838 if (job->jv_tty_out != NULL)
5839 job->jv_tty_in = vim_strsave(job->jv_tty_out);
5840 close(pty_slave_fd); 5846 close(pty_slave_fd);
5841 5847
5842 channel = add_channel(); 5848 channel = add_channel();
5843 if (channel == NULL) 5849 if (channel == NULL)
5844 { 5850 {