From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#13054: Assume POSIX 1003.1-1988 or later for execve. Date: Sat, 01 Dec 2012 22:37:39 -0600 Message-ID: <50BADB13.1040301@cs.ucla.edu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------070807080707080400070308" X-Trace: ger.gmane.org 1354423134 7983 80.91.229.3 (2 Dec 2012 04:38:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 2 Dec 2012 04:38:54 +0000 (UTC) To: 13054@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Dec 02 05:39:06 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Tf1Ka-0001nI-AJ for geb-bug-gnu-emacs@m.gmane.org; Sun, 02 Dec 2012 05:39:04 +0100 Original-Received: from localhost ([::1]:41562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tf1KO-00043s-LZ for geb-bug-gnu-emacs@m.gmane.org; Sat, 01 Dec 2012 23:38:52 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:56890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tf1KL-00043j-8P for bug-gnu-emacs@gnu.org; Sat, 01 Dec 2012 23:38:50 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tf1KJ-0003PZ-OR for bug-gnu-emacs@gnu.org; Sat, 01 Dec 2012 23:38:49 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:38873) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tf1KJ-0003PV-L9 for bug-gnu-emacs@gnu.org; Sat, 01 Dec 2012 23:38:47 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1Tf1MU-0001GB-0Q for bug-gnu-emacs@gnu.org; Sat, 01 Dec 2012 23:41:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 02 Dec 2012 04:41:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 13054 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.13544232204791 (code B ref -1); Sun, 02 Dec 2012 04:41:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 2 Dec 2012 04:40:20 +0000 Original-Received: from localhost ([127.0.0.1]:49124 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tf1Lo-0001FD-7Y for submit@debbugs.gnu.org; Sat, 01 Dec 2012 23:40:20 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:49344) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tf1Lk-0001F1-6d for submit@debbugs.gnu.org; Sat, 01 Dec 2012 23:40:18 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tf1JY-0003Lq-6L for submit@debbugs.gnu.org; Sat, 01 Dec 2012 23:38:01 -0500 Original-Received: from lists.gnu.org ([208.118.235.17]:51137) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tf1JY-0003Ll-2y for submit@debbugs.gnu.org; Sat, 01 Dec 2012 23:38:00 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:56853) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tf1JW-00041f-Qf for bug-gnu-emacs@gnu.org; Sat, 01 Dec 2012 23:38:00 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tf1JV-0003Kd-71 for bug-gnu-emacs@gnu.org; Sat, 01 Dec 2012 23:37:58 -0500 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:33232) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tf1JU-0003KQ-Um; Sat, 01 Dec 2012 23:37:57 -0500 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 911D1A60001; Sat, 1 Dec 2012 20:37:49 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3lBp8udptsXm; Sat, 1 Dec 2012 20:37:48 -0800 (PST) Original-Received: from [10.128.212.47] (unknown [12.234.23.143]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id D532939E8105; Sat, 1 Dec 2012 20:37:47 -0800 (PST) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Thunderbird/17.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:67767 Archived-At: This is a multi-part message in MIME format. --------------070807080707080400070308 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Attached is a patch to simplify Emacs that I discovered while looking into the putenv/setenv problem. It affects the NT port so I'm CC'ing this to Eli to give him a heads-up. --------------070807080707080400070308 Content-Type: text/plain; charset=UTF-8; name="execve.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="execve.txt" === modified file 'lib-src/ChangeLog' --- lib-src/ChangeLog 2012-12-02 01:47:56 +0000 +++ lib-src/ChangeLog 2012-12-02 04:32:26 +0000 @@ -1,3 +1,8 @@ +2012-12-02 Paul Eggert + + Assume POSIX 1003.1-1988 or later for execve. + * ntlib.h (execve): New macro. + 2012-12-02 Kevin Ryde * etags.c (Lisp_functions): Skip (defvar foo) declarations unless === modified file 'lib-src/ntlib.h' --- lib-src/ntlib.h 2012-01-19 07:21:25 +0000 +++ lib-src/ntlib.h 2012-12-02 04:32:26 +0000 @@ -79,6 +79,7 @@ /* map to MSVC names */ #define execlp _execlp +#define execve _execve #define execvp _execvp #define fdopen _fdopen #ifndef fileno @@ -104,4 +105,3 @@ #undef _WINSOCK_H /* end of ntlib.h */ - === modified file 'nt/ChangeLog' --- nt/ChangeLog 2012-12-01 20:09:30 +0000 +++ nt/ChangeLog 2012-12-02 04:32:26 +0000 @@ -1,3 +1,8 @@ +2012-12-02 Paul Eggert + + Assume POSIX 1003.1-1988 or later for execve. + * inc/ms-w32.h (execve): New macro. + 2012-12-01 Juanma Barranquero * config.nt: Sync with autogen/config.in. === modified file 'nt/inc/ms-w32.h' --- nt/inc/ms-w32.h 2012-11-27 03:10:32 +0000 +++ nt/inc/ms-w32.h 2012-12-02 04:32:26 +0000 @@ -204,6 +204,7 @@ /* Map to MSVC names. */ #define execlp _execlp +#define execve _execve #define execvp _execvp #define fdopen _fdopen #ifndef fileno === modified file 'src/ChangeLog' --- src/ChangeLog 2012-12-01 23:06:14 +0000 +++ src/ChangeLog 2012-12-02 04:32:26 +0000 @@ -1,3 +1,12 @@ +2012-12-02 Paul Eggert + + Assume POSIX 1003.1-1988 or later for execve. + * 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. + 2012-12-01 Paul Eggert * xterm.c (x_draw_image_relief): Remove unused locals (Bug#10500). === modified file 'src/callproc.c' --- src/callproc.c 2012-11-29 00:36:22 +0000 +++ src/callproc.c 2012-12-02 04:32:26 +0000 @@ -488,9 +488,6 @@ } { - /* child_setup must clobber environ in systems with true vfork. - Protect it from permanent change. */ - char **save_environ = environ; int fd_error = fd1; if (fd_output >= 0) @@ -594,7 +591,6 @@ ptrdiff_t volatile count_volatile = count; ptrdiff_t volatile sa_count_volatile = sa_count; char **volatile new_argv_volatile = new_argv; - char **volatile new_save_environ = save_environ; pid = vfork (); @@ -612,7 +608,6 @@ count = count_volatile; sa_count = sa_count_volatile; new_argv = new_argv_volatile; - save_environ = new_save_environ; } if (pid == 0) @@ -638,8 +633,6 @@ emacs_close (fd_error); #endif /* not MSDOS */ - environ = save_environ; - /* Close most of our file descriptors, but not fd0 since we will use that to read input from. */ emacs_close (filefd); @@ -1092,10 +1085,6 @@ Initialize inferior's priority, pgrp, connected dir and environment. then exec another program based on new_argv. - This function may change environ for the superior process. - Therefore, the superior process must save and restore the value - of environ around the vfork and the call to this function. - If SET_PGRP, put the subprocess into a separate process group. CURRENT_DIR is an elisp string giving the path of the current @@ -1298,11 +1287,7 @@ setpgid (0, 0); tcsetpgrp (0, pid); - /* execvp does not accept an environment arg so the only way - to pass this environment is to set environ. Our caller - is responsible for restoring the ambient value of environ. */ - environ = env; - execvp (new_argv[0], new_argv); + execve (new_argv[0], new_argv, env); emacs_write (1, "Can't exec program: ", 20); emacs_write (1, new_argv[0], strlen (new_argv[0])); === modified file 'src/process.c' --- src/process.c 2012-11-27 05:17:07 +0000 +++ src/process.c 2012-12-02 04:32:26 +0000 @@ -1586,9 +1586,6 @@ volatile int pty_flag = 0; volatile Lisp_Object lisp_pty_name = Qnil; volatile Lisp_Object encoded_current_dir; -#if HAVE_WORKING_VFORK - char **volatile save_environ; -#endif inchannel = outchannel = -1; @@ -1688,12 +1685,6 @@ pthread_sigmask (SIG_BLOCK, &blocked, 0); #endif -#if HAVE_WORKING_VFORK - /* child_setup must clobber environ on systems with true vfork. - Protect it from permanent change. */ - save_environ = environ; -#endif - #ifndef WINDOWSNT pid = vfork (); if (pid == 0) @@ -1819,10 +1810,6 @@ /* Back in the parent process. */ -#if HAVE_WORKING_VFORK - environ = save_environ; -#endif - XPROCESS (process)->pid = pid; if (0 <= pid) XPROCESS (process)->alive = 1; @@ -1874,7 +1861,7 @@ /* Wait for child_setup to complete in case that vfork is actually defined as fork. The descriptor wait_child_setup[1] of a pipe is closed at the child side either by close-on-exec - on successful execvp or the _exit call in child_setup. */ + on successful execve or the _exit call in child_setup. */ { char dummy; --------------070807080707080400070308--