comparison src/os_unix.c @ 14065:e271ca6f32f9 v8.1.0050

patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window commit https://github.com/vim/vim/commit/493359eb3b10377d5c3524e91d911809b8ac7a76 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jun 12 20:25:52 2018 +0200 patch 8.1.0050: $VIM_TERMINAL is also set when not in a terminal window Problem: $VIM_TERMINAL is also set when not in a terminal window. Solution: Pass a flag to indicate whether the job runs in a terminal.
author Christian Brabandt <cb@256bit.org>
date Tue, 12 Jun 2018 20:30:06 +0200
parents f39150ec146e
children a9b141cf99ff
comparison
equal deleted inserted replaced
14064:54b39896cc45 14065:e271ca6f32f9
4157 #if !defined(USE_SYSTEM) || defined(FEAT_JOB_CHANNEL) 4157 #if !defined(USE_SYSTEM) || defined(FEAT_JOB_CHANNEL)
4158 /* 4158 /*
4159 * Set the environment for a child process. 4159 * Set the environment for a child process.
4160 */ 4160 */
4161 static void 4161 static void
4162 set_child_environment(long rows, long columns, char *term) 4162 set_child_environment(
4163 long rows,
4164 long columns,
4165 char *term,
4166 int is_terminal UNUSED)
4163 { 4167 {
4164 # ifdef HAVE_SETENV 4168 # ifdef HAVE_SETENV
4165 char envbuf[50]; 4169 char envbuf[50];
4166 # else 4170 # else
4167 static char envbuf_Term[30]; 4171 static char envbuf_Term[30];
4168 static char envbuf_Rows[20]; 4172 static char envbuf_Rows[20];
4169 static char envbuf_Lines[20]; 4173 static char envbuf_Lines[20];
4170 static char envbuf_Columns[20]; 4174 static char envbuf_Columns[20];
4171 static char envbuf_Colors[20]; 4175 static char envbuf_Colors[20];
4176 # ifdef FEAT_TERMINAL
4172 static char envbuf_Version[20]; 4177 static char envbuf_Version[20];
4178 # endif
4173 # ifdef FEAT_CLIENTSERVER 4179 # ifdef FEAT_CLIENTSERVER
4174 static char envbuf_Servername[60]; 4180 static char envbuf_Servername[60];
4175 # endif 4181 # endif
4176 # endif 4182 # endif
4177 long colors = 4183 long colors =
4188 setenv("LINES", (char *)envbuf, 1); 4194 setenv("LINES", (char *)envbuf, 1);
4189 sprintf((char *)envbuf, "%ld", columns); 4195 sprintf((char *)envbuf, "%ld", columns);
4190 setenv("COLUMNS", (char *)envbuf, 1); 4196 setenv("COLUMNS", (char *)envbuf, 1);
4191 sprintf((char *)envbuf, "%ld", colors); 4197 sprintf((char *)envbuf, "%ld", colors);
4192 setenv("COLORS", (char *)envbuf, 1); 4198 setenv("COLORS", (char *)envbuf, 1);
4193 sprintf((char *)envbuf, "%ld", get_vim_var_nr(VV_VERSION)); 4199 # ifdef FEAT_TERMINAL
4194 setenv("VIM_TERMINAL", (char *)envbuf, 1); 4200 if (is_terminal)
4201 {
4202 sprintf((char *)envbuf, "%ld", get_vim_var_nr(VV_VERSION));
4203 setenv("VIM_TERMINAL", (char *)envbuf, 1);
4204 }
4205 # endif
4195 # ifdef FEAT_CLIENTSERVER 4206 # ifdef FEAT_CLIENTSERVER
4196 setenv("VIM_SERVERNAME", serverName == NULL ? "" : (char *)serverName, 1); 4207 setenv("VIM_SERVERNAME", serverName == NULL ? "" : (char *)serverName, 1);
4197 # endif 4208 # endif
4198 # else 4209 # else
4199 /* 4210 /*
4210 vim_snprintf(envbuf_Columns, sizeof(envbuf_Columns), 4221 vim_snprintf(envbuf_Columns, sizeof(envbuf_Columns),
4211 "COLUMNS=%ld", columns); 4222 "COLUMNS=%ld", columns);
4212 putenv(envbuf_Columns); 4223 putenv(envbuf_Columns);
4213 vim_snprintf(envbuf_Colors, sizeof(envbuf_Colors), "COLORS=%ld", colors); 4224 vim_snprintf(envbuf_Colors, sizeof(envbuf_Colors), "COLORS=%ld", colors);
4214 putenv(envbuf_Colors); 4225 putenv(envbuf_Colors);
4215 vim_snprintf(envbuf_Version, sizeof(envbuf_Version), "VIM_TERMINAL=%ld", 4226 # ifdef FEAT_TERMINAL
4216 get_vim_var_nr(VV_VERSION)); 4227 if (is_terminal)
4217 putenv(envbuf_Version); 4228 {
4229 vim_snprintf(envbuf_Version, sizeof(envbuf_Version),
4230 "VIM_TERMINAL=%ld", get_vim_var_nr(VV_VERSION));
4231 putenv(envbuf_Version);
4232 }
4233 # endif
4218 # ifdef FEAT_CLIENTSERVER 4234 # ifdef FEAT_CLIENTSERVER
4219 vim_snprintf(envbuf_Servername, sizeof(envbuf_Servername), 4235 vim_snprintf(envbuf_Servername, sizeof(envbuf_Servername),
4220 "VIM_SERVERNAME=%s", serverName == NULL ? "" : (char *)serverName); 4236 "VIM_SERVERNAME=%s", serverName == NULL ? "" : (char *)serverName);
4221 putenv(envbuf_Servername); 4237 putenv(envbuf_Servername);
4222 # endif 4238 # endif
4223 # endif 4239 # endif
4224 } 4240 }
4225 4241
4226 static void 4242 static void
4227 set_default_child_environment(void) 4243 set_default_child_environment(int is_terminal)
4228 { 4244 {
4229 set_child_environment(Rows, Columns, "dumb"); 4245 set_child_environment(Rows, Columns, "dumb", is_terminal);
4230 } 4246 }
4231 #endif 4247 #endif
4232 4248
4233 #if defined(FEAT_GUI) || defined(FEAT_JOB_CHANNEL) 4249 #if defined(FEAT_GUI) || defined(FEAT_JOB_CHANNEL)
4234 /* 4250 /*
4687 * unless run by root) */ 4703 * unless run by root) */
4688 ioctl(pty_slave_fd, TIOCSCTTY, (char *)NULL); 4704 ioctl(pty_slave_fd, TIOCSCTTY, (char *)NULL);
4689 # endif 4705 # endif
4690 } 4706 }
4691 # endif 4707 # endif
4692 set_default_child_environment(); 4708 set_default_child_environment(FALSE);
4693 4709
4694 /* 4710 /*
4695 * stderr is only redirected when using the GUI, so that a 4711 * stderr is only redirected when using the GUI, so that a
4696 * program like gpg can still access the terminal to get a 4712 * program like gpg can still access the terminal to get a
4697 * passphrase using stderr. 4713 * passphrase using stderr.
5365 #endif 5381 #endif
5366 } 5382 }
5367 5383
5368 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) 5384 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO)
5369 void 5385 void
5370 mch_job_start(char **argv, job_T *job, jobopt_T *options) 5386 mch_job_start(char **argv, job_T *job, jobopt_T *options, int is_terminal)
5371 { 5387 {
5372 pid_t pid; 5388 pid_t pid;
5373 int fd_in[2] = {-1, -1}; /* for stdin */ 5389 int fd_in[2] = {-1, -1}; /* for stdin */
5374 int fd_out[2] = {-1, -1}; /* for stdout */ 5390 int fd_out[2] = {-1, -1}; /* for stdout */
5375 int fd_err[2] = {-1, -1}; /* for stderr */ 5391 int fd_err[2] = {-1, -1}; /* for stderr */
5513 if (term == NULL || *term == NUL || STRNCMP(term, "xterm", 5) != 0) 5529 if (term == NULL || *term == NUL || STRNCMP(term, "xterm", 5) != 0)
5514 term = "xterm"; 5530 term = "xterm";
5515 set_child_environment( 5531 set_child_environment(
5516 (long)options->jo_term_rows, 5532 (long)options->jo_term_rows,
5517 (long)options->jo_term_cols, 5533 (long)options->jo_term_cols,
5518 term); 5534 term,
5535 is_terminal);
5519 } 5536 }
5520 else 5537 else
5521 # endif 5538 # endif
5522 set_default_child_environment(); 5539 set_default_child_environment(is_terminal);
5523 5540
5524 if (options->jo_env != NULL) 5541 if (options->jo_env != NULL)
5525 { 5542 {
5526 dict_T *dict = options->jo_env; 5543 dict_T *dict = options->jo_env;
5527 hashitem_T *hi; 5544 hashitem_T *hi;