From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Colascione Newsgroups: gmane.emacs.devel Subject: [PATCH 8/9] Generalize fork+exec logic, add DAEMON_MUST_EXEC Date: Tue, 07 Aug 2012 01:19:27 -0700 Message-ID: References: NNTP-Posting-Host: plane.gmane.org X-Trace: dough.gmane.org 1344327626 1156 80.91.229.3 (7 Aug 2012 08:20:26 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 7 Aug 2012 08:20:26 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Aug 07 10:20:26 2012 Return-path: Envelope-to: ged-emacs-devel@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 1Syf1d-0003qs-2X for ged-emacs-devel@m.gmane.org; Tue, 07 Aug 2012 10:20:25 +0200 Original-Received: from localhost ([::1]:53231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Syf1c-0002Zz-9n for ged-emacs-devel@m.gmane.org; Tue, 07 Aug 2012 04:20:24 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:57412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Syf0v-0000j8-6h for emacs-devel@gnu.org; Tue, 07 Aug 2012 04:19:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Syf0n-0007kB-TE for emacs-devel@gnu.org; Tue, 07 Aug 2012 04:19:41 -0400 Original-Received: from dancol.org ([96.126.100.184]:37136) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Syf0n-0007if-Lf for emacs-devel@gnu.org; Tue, 07 Aug 2012 04:19:33 -0400 Original-Received: from dancol by dancol.org with local (Exim 4.72) (envelope-from ) id 1Syf0h-0006qB-8K for emacs-devel@gnu.org; Tue, 07 Aug 2012 01:19:27 -0700 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 96.126.100.184 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:152243 Archived-At: --- src/emacs.c | 38 ++++++++++++++++++++++++-------------- 1 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/emacs.c b/src/emacs.c index a4fab12..022d46d 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -161,6 +161,22 @@ static void *my_heap_start; static uprintmax_t heap_bss_diff; #endif +/* To run as a daemon under Cocoa or Windows, we must do a fork+exec, + not a simple fork. + + On Cocoa, CoreFoundation lib fails in forked process: + http://developer.apple.com/ReleaseNotes/ + CoreFoundation/CoreFoundation.html) + + On Windows, a Cygwin fork child cannot access the USER subsystem. + + We mark being in the exec'd process by a daemon name argument of + form "--daemon=\nFD0,FD1\nNAME" where FD are the pipe file descriptors, + NAME is the original daemon name, if any. */ +#if defined (NS_IMPL_COCOA) || defined (HAVE_NTGUI) +# define DAEMON_MUST_EXEC +#endif + /* Nonzero means running Emacs without interactive terminal. */ int noninteractive; @@ -706,9 +722,9 @@ main (int argc, char **argv) int no_loadup = 0; char *junk = 0; char *dname_arg = 0; -#ifdef NS_IMPL_COCOA +#ifdef DAEMON_MUST_EXEC char dname_arg2[80]; -#endif +#endif /* DAEMON_MUST_EXEC */ char *ch_to_dir; #if GC_MARK_STACK @@ -1010,25 +1026,19 @@ main (int argc, char **argv) exit (1); } -#ifndef NS_IMPL_COCOA +#ifndef DAEMON_MUST_EXEC #ifdef USE_GTK fprintf (stderr, "\nWarning: due to a long standing Gtk+ bug\nhttp://bugzilla.gnome.org/show_bug.cgi?id=85715\n\ Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost.\n\ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.\n"); -#endif +#endif /* USE_GTK */ f = fork (); -#else /* NS_IMPL_COCOA */ - /* Under Cocoa we must do fork+exec as CoreFoundation lib fails in - forked process: http://developer.apple.com/ReleaseNotes/ - CoreFoundation/CoreFoundation.html) - We mark being in the exec'd process by a daemon name argument of - form "--daemon=\nFD0,FD1\nNAME" where FD are the pipe file descriptors, - NAME is the original daemon name, if any. */ +#else /* DAEMON_MUST_EXEC */ if (!dname_arg || !strchr (dname_arg, '\n')) f = fork (); /* in orig */ else f = 0; /* in exec'd */ -#endif /* NS_IMPL_COCOA */ +#endif /* !DAEMON_MUST_EXEC */ if (f > 0) { int retval; @@ -1064,7 +1074,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem exit (1); } -#ifdef NS_IMPL_COCOA +#ifdef DAEMON_MUST_EXEC { /* In orig process, forked as child, OR in exec'd. */ if (!dname_arg || !strchr (dname_arg, '\n')) @@ -1100,7 +1110,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem dname_arg2); dname_arg = *dname_arg2 ? dname_arg2 : NULL; } -#endif /* NS_IMPL_COCOA */ +#endif /* DAEMON_MUST_EXEC */ if (dname_arg) daemon_name = xstrdup (dname_arg); -- 1.7.2.5