aboutsummaryrefslogtreecommitdiffstats
path: root/src/callproc.c
diff options
context:
space:
mode:
authorPaul Eggert2012-12-02 11:16:45 -0800
committerPaul Eggert2012-12-02 11:16:45 -0800
commit21e54a94d7527e07ddc37066c8cb488f478339c9 (patch)
tree714c6cb2b4170123769e70a62d295cc24ed998f3 /src/callproc.c
parent010db6da6527d16736fd3c2b607058dd35a70c9a (diff)
downloademacs-21e54a94d7527e07ddc37066c8cb488f478339c9.tar.gz
emacs-21e54a94d7527e07ddc37066c8cb488f478339c9.zip
Use execve to avoid need to munge environ.
* callproc.c (Fcall_process): * process.c (create_process): Don't save and restore environ; no longer needed. * callproc.c (child_setup): Use execve, not execvp, to preserve environ. Fixes: debbugs:13054
Diffstat (limited to 'src/callproc.c')
-rw-r--r--src/callproc.c17
1 files changed, 1 insertions, 16 deletions
diff --git a/src/callproc.c b/src/callproc.c
index 167663a45c6..0242755eb5f 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -488,9 +488,6 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
488 } 488 }
489 489
490 { 490 {
491 /* child_setup must clobber environ in systems with true vfork.
492 Protect it from permanent change. */
493 char **save_environ = environ;
494 int fd_error = fd1; 491 int fd_error = fd1;
495 492
496 if (fd_output >= 0) 493 if (fd_output >= 0)
@@ -594,7 +591,6 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
594 ptrdiff_t volatile count_volatile = count; 591 ptrdiff_t volatile count_volatile = count;
595 ptrdiff_t volatile sa_count_volatile = sa_count; 592 ptrdiff_t volatile sa_count_volatile = sa_count;
596 char **volatile new_argv_volatile = new_argv; 593 char **volatile new_argv_volatile = new_argv;
597 char **volatile new_save_environ = save_environ;
598 594
599 pid = vfork (); 595 pid = vfork ();
600 596
@@ -612,7 +608,6 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
612 count = count_volatile; 608 count = count_volatile;
613 sa_count = sa_count_volatile; 609 sa_count = sa_count_volatile;
614 new_argv = new_argv_volatile; 610 new_argv = new_argv_volatile;
615 save_environ = new_save_environ;
616 } 611 }
617 612
618 if (pid == 0) 613 if (pid == 0)
@@ -638,8 +633,6 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
638 emacs_close (fd_error); 633 emacs_close (fd_error);
639#endif /* not MSDOS */ 634#endif /* not MSDOS */
640 635
641 environ = save_environ;
642
643 /* Close most of our file descriptors, but not fd0 636 /* Close most of our file descriptors, but not fd0
644 since we will use that to read input from. */ 637 since we will use that to read input from. */
645 emacs_close (filefd); 638 emacs_close (filefd);
@@ -1092,10 +1085,6 @@ add_env (char **env, char **new_env, char *string)
1092 Initialize inferior's priority, pgrp, connected dir and environment. 1085 Initialize inferior's priority, pgrp, connected dir and environment.
1093 then exec another program based on new_argv. 1086 then exec another program based on new_argv.
1094 1087
1095 This function may change environ for the superior process.
1096 Therefore, the superior process must save and restore the value
1097 of environ around the vfork and the call to this function.
1098
1099 If SET_PGRP, put the subprocess into a separate process group. 1088 If SET_PGRP, put the subprocess into a separate process group.
1100 1089
1101 CURRENT_DIR is an elisp string giving the path of the current 1090 CURRENT_DIR is an elisp string giving the path of the current
@@ -1298,11 +1287,7 @@ child_setup (int in, int out, int err, char **new_argv, bool set_pgrp,
1298 setpgid (0, 0); 1287 setpgid (0, 0);
1299 tcsetpgrp (0, pid); 1288 tcsetpgrp (0, pid);
1300 1289
1301 /* execvp does not accept an environment arg so the only way 1290 execve (new_argv[0], new_argv, env);
1302 to pass this environment is to set environ. Our caller
1303 is responsible for restoring the ambient value of environ. */
1304 environ = env;
1305 execvp (new_argv[0], new_argv);
1306 1291
1307 emacs_write (1, "Can't exec program: ", 20); 1292 emacs_write (1, "Can't exec program: ", 20);
1308 emacs_write (1, new_argv[0], strlen (new_argv[0])); 1293 emacs_write (1, new_argv[0], strlen (new_argv[0]));