aboutsummaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/ChangeLog9
-rw-r--r--src/callproc.c17
-rw-r--r--src/process.c15
3 files changed, 11 insertions, 30 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 11ddb114006..27453ab8a16 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,12 @@
12012-12-02 Paul Eggert <eggert@cs.ucla.edu>
2
3 Use execve to avoid need to munge environ (Bug#13054).
4 * callproc.c (Fcall_process):
5 * process.c (create_process):
6 Don't save and restore environ; no longer needed.
7 * callproc.c (child_setup):
8 Use execve, not execvp, to preserve environ.
9
12012-12-01 Paul Eggert <eggert@cs.ucla.edu> 102012-12-01 Paul Eggert <eggert@cs.ucla.edu>
2 11
3 * xterm.c (x_draw_image_relief): Remove unused locals (Bug#10500). 12 * xterm.c (x_draw_image_relief): Remove unused locals (Bug#10500).
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]));
diff --git a/src/process.c b/src/process.c
index b23f06fd025..c6139c9f929 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1586,9 +1586,6 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1586 volatile int pty_flag = 0; 1586 volatile int pty_flag = 0;
1587 volatile Lisp_Object lisp_pty_name = Qnil; 1587 volatile Lisp_Object lisp_pty_name = Qnil;
1588 volatile Lisp_Object encoded_current_dir; 1588 volatile Lisp_Object encoded_current_dir;
1589#if HAVE_WORKING_VFORK
1590 char **volatile save_environ;
1591#endif
1592 1589
1593 inchannel = outchannel = -1; 1590 inchannel = outchannel = -1;
1594 1591
@@ -1688,12 +1685,6 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1688 pthread_sigmask (SIG_BLOCK, &blocked, 0); 1685 pthread_sigmask (SIG_BLOCK, &blocked, 0);
1689#endif 1686#endif
1690 1687
1691#if HAVE_WORKING_VFORK
1692 /* child_setup must clobber environ on systems with true vfork.
1693 Protect it from permanent change. */
1694 save_environ = environ;
1695#endif
1696
1697#ifndef WINDOWSNT 1688#ifndef WINDOWSNT
1698 pid = vfork (); 1689 pid = vfork ();
1699 if (pid == 0) 1690 if (pid == 0)
@@ -1819,10 +1810,6 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1819 1810
1820 /* Back in the parent process. */ 1811 /* Back in the parent process. */
1821 1812
1822#if HAVE_WORKING_VFORK
1823 environ = save_environ;
1824#endif
1825
1826 XPROCESS (process)->pid = pid; 1813 XPROCESS (process)->pid = pid;
1827 if (0 <= pid) 1814 if (0 <= pid)
1828 XPROCESS (process)->alive = 1; 1815 XPROCESS (process)->alive = 1;
@@ -1874,7 +1861,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1874 /* Wait for child_setup to complete in case that vfork is 1861 /* Wait for child_setup to complete in case that vfork is
1875 actually defined as fork. The descriptor wait_child_setup[1] 1862 actually defined as fork. The descriptor wait_child_setup[1]
1876 of a pipe is closed at the child side either by close-on-exec 1863 of a pipe is closed at the child side either by close-on-exec
1877 on successful execvp or the _exit call in child_setup. */ 1864 on successful execve or the _exit call in child_setup. */
1878 { 1865 {
1879 char dummy; 1866 char dummy;
1880 1867