From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Markus Triska Newsgroups: gmane.emacs.bugs Subject: bug#554: OSX: with-temp-buffer kills unrelated processes Date: Wed, 16 Jul 2008 17:27:47 +0200 Message-ID: References: <20080713173957.65071954A3D@mt-computer.local> Reply-To: Markus Triska , 554@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1216223268 13414 80.91.229.12 (16 Jul 2008 15:47:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 16 Jul 2008 15:47:48 +0000 (UTC) Cc: 554@emacsbugs.donarmstrong.com To: YAMAMOTO Mitsuharu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Jul 16 17:48:36 2008 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KJ9Er-0001pG-4y for geb-bug-gnu-emacs@m.gmane.org; Wed, 16 Jul 2008 17:48:21 +0200 Original-Received: from localhost ([127.0.0.1]:36153 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KJ9Dy-0003vh-Cy for geb-bug-gnu-emacs@m.gmane.org; Wed, 16 Jul 2008 11:47:26 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KJ9Dt-0003v1-Lj for bug-gnu-emacs@gnu.org; Wed, 16 Jul 2008 11:47:21 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KJ9Dt-0003uZ-29 for bug-gnu-emacs@gnu.org; Wed, 16 Jul 2008 11:47:21 -0400 Original-Received: from [199.232.76.173] (port=52349 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KJ9Ds-0003uT-Us for bug-gnu-emacs@gnu.org; Wed, 16 Jul 2008 11:47:20 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:36150) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KJ9Ds-000620-B9 for bug-gnu-emacs@gnu.org; Wed, 16 Jul 2008 11:47:20 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m6GFlHDV012141; Wed, 16 Jul 2008 08:47:17 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.13.8/8.13.8/Submit) id m6GFZ3ZS008714; Wed, 16 Jul 2008 08:35:03 -0700 X-Loop: don@donarmstrong.com Resent-From: Markus Triska Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Wed, 16 Jul 2008 15:35:03 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 554 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by 554-submit@emacsbugs.donarmstrong.com id=B554.12162220867446 (code B ref 554); Wed, 16 Jul 2008 15:35:03 +0000 Original-Received: (at 554) by emacsbugs.donarmstrong.com; 16 Jul 2008 15:28:06 +0000 Original-Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with SMTP id m6GFS1Ra007440 for <554@emacsbugs.donarmstrong.com>; Wed, 16 Jul 2008 08:28:03 -0700 Original-Received: (qmail invoked by alias); 16 Jul 2008 15:27:55 -0000 Original-Received: from pnsgw1-client181.demo.tuwien.ac.at (EHLO pnsgw1-client181.demo.tuwien.ac.at) [128.131.200.181] by mail.gmx.net (mp024) with SMTP; 16 Jul 2008 17:27:55 +0200 X-Authenticated: #4064391 X-Provags-ID: V01U2FsdGVkX1+FgfQ71kGFgQiQj6qR0JBaxNmWvW2SJx+66KOy/4 ixwbzce6CwJ2KU Original-Received: by pnsgw1-client181.demo.tuwien.ac.at (Postfix, from userid 502) id ED561986FF3; Wed, 16 Jul 2008 17:27:47 +0200 (CEST) In-Reply-To: (YAMAMOTO Mitsuharu's message of "Wed, 16 Jul 2008 18:17:52 +0900") X-Y-GMX-Trusted: 0 X-FuHaFi: 0.41 X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Resent-Date: Wed, 16 Jul 2008 11:47:21 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:18739 Archived-At: YAMAMOTO Mitsuharu writes: > OK, close-on-exec seems to be usable for the `fork' case. How about > the patch below? Thank you very much; I've tested the following adapted version of your patch with the latest CVS trunk of Emacs, and the problem seems gone. All the best, Markus diff --git a/src/callproc.c b/src/callproc.c index a6de766..3d61e64 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -1047,8 +1047,8 @@ add_env (char **env, char **new_env, char *string) Therefore, the superior process must save and restore the value of environ around the vfork and the call to this function. - SET_PGRP is nonzero if we should put the subprocess into a separate - process group. + RET_ON_FAIL is nonzero if we should return from the function on + failure of execvp rather than calling _exit. CURRENT_DIR is an elisp string giving the path of the current directory the subprocess should have. Since we can't really signal @@ -1056,10 +1056,10 @@ add_env (char **env, char **new_env, char *string) executable directory by the parent. */ int -child_setup (in, out, err, new_argv, set_pgrp, current_dir) +child_setup (in, out, err, new_argv, ret_on_fail, current_dir) int in, out, err; register char **new_argv; - int set_pgrp; + int ret_on_fail; Lisp_Object current_dir; { char **env; @@ -1291,7 +1291,8 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir) emacs_write (1, "Can't exec program: ", 20); emacs_write (1, new_argv[0], strlen (new_argv[0])); emacs_write (1, "\n", 1); - _exit (1); + if (!ret_on_fail) + _exit (1); #endif /* not WINDOWSNT */ #endif /* not MSDOS */ } diff --git a/src/process.c b/src/process.c index c82584a..b0bebeb 100644 --- a/src/process.c +++ b/src/process.c @@ -1851,6 +1851,9 @@ create_process (process, new_argv, current_dir) int inchannel, outchannel; pid_t pid; int sv[2]; +#if !defined (WINDOWSNT) && defined (FD_CLOEXEC) + int wait_child_setup[2]; +#endif #ifdef POSIX_SIGNALS sigset_t procmask; sigset_t blocked; @@ -1893,12 +1896,6 @@ create_process (process, new_argv, current_dir) #endif if (forkin < 0) report_file_error ("Opening pty", Qnil); -#if defined (DONT_REOPEN_PTY) - /* In the case that vfork is defined as fork, the parent process - (Emacs) may send some data before the child process completes - tty options setup. So we setup tty before forking. */ - child_setup_tty (forkout); -#endif /* DONT_REOPEN_PTY */ #else forkin = forkout = -1; #endif /* not USG, or USG_SUBTTY_WORKS */ @@ -1924,6 +1921,25 @@ create_process (process, new_argv, current_dir) forkin = sv[0]; } +#if !defined (WINDOWSNT) && defined (FD_CLOEXEC) + { + int tem; + + tem = pipe (wait_child_setup); + if (tem < 0) + report_file_error ("Creating pipe", Qnil); + tem = fcntl (wait_child_setup[1], F_GETFD, 0); + if (tem >= 0) + tem = fcntl (wait_child_setup[1], F_SETFD, tem | FD_CLOEXEC); + if (tem < 0) + { + emacs_close (wait_child_setup[0]); + emacs_close (wait_child_setup[1]); + report_file_error ("Setting file descriptor flags", Qnil); + } + } +#endif + #if 0 /* Replaced by close_process_descs */ set_exclusive_use (inchannel); @@ -2150,16 +2166,21 @@ create_process (process, new_argv, current_dir) #endif /* SIGCHLD */ #endif /* !POSIX_SIGNALS */ -#if !defined (DONT_REOPEN_PTY) if (pty_flag) child_setup_tty (xforkout); -#endif /* not DONT_REOPEN_PTY */ #ifdef WINDOWSNT pid = child_setup (xforkin, xforkout, xforkout, new_argv, 1, current_dir); #else /* not WINDOWSNT */ +#ifdef FD_CLOEXEC + emacs_close (wait_child_setup[0]); +#endif child_setup (xforkin, xforkout, xforkout, new_argv, 1, current_dir); +#ifdef FD_CLOEXEC + emacs_close (wait_child_setup[0]); +#endif + _exit (1); #endif /* not WINDOWSNT */ } environ = save_environ; @@ -2211,6 +2232,21 @@ create_process (process, new_argv, current_dir) else #endif XPROCESS (process)->tty_name = Qnil; + +#if !defined (WINDOWSNT) && defined (FD_CLOEXEC) + /* 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 by the explicit emacs_close call + before _exit above. */ + { + char dummy; + + emacs_close (wait_child_setup[1]); + emacs_read (wait_child_setup[0], &dummy, 1); + emacs_close (wait_child_setup[0]); + } +#endif } /* Restore the signal state whether vfork succeeded or not.