diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/emacs.c | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/src/emacs.c b/src/emacs.c index 9a9309546ab..7b643f5226f 100644 --- a/src/emacs.c +++ b/src/emacs.c | |||
| @@ -161,6 +161,22 @@ static void *my_heap_start; | |||
| 161 | static uprintmax_t heap_bss_diff; | 161 | static uprintmax_t heap_bss_diff; |
| 162 | #endif | 162 | #endif |
| 163 | 163 | ||
| 164 | /* To run as a daemon under Cocoa or Windows, we must do a fork+exec, | ||
| 165 | not a simple fork. | ||
| 166 | |||
| 167 | On Cocoa, CoreFoundation lib fails in forked process: | ||
| 168 | http://developer.apple.com/ReleaseNotes/ | ||
| 169 | CoreFoundation/CoreFoundation.html) | ||
| 170 | |||
| 171 | On Windows, a Cygwin fork child cannot access the USER subsystem. | ||
| 172 | |||
| 173 | We mark being in the exec'd process by a daemon name argument of | ||
| 174 | form "--daemon=\nFD0,FD1\nNAME" where FD are the pipe file descriptors, | ||
| 175 | NAME is the original daemon name, if any. */ | ||
| 176 | #if defined (NS_IMPL_COCOA) || defined (HAVE_NTGUI) | ||
| 177 | # define DAEMON_MUST_EXEC | ||
| 178 | #endif | ||
| 179 | |||
| 164 | /* Nonzero means running Emacs without interactive terminal. */ | 180 | /* Nonzero means running Emacs without interactive terminal. */ |
| 165 | int noninteractive; | 181 | int noninteractive; |
| 166 | 182 | ||
| @@ -694,9 +710,9 @@ main (int argc, char **argv) | |||
| 694 | int no_loadup = 0; | 710 | int no_loadup = 0; |
| 695 | char *junk = 0; | 711 | char *junk = 0; |
| 696 | char *dname_arg = 0; | 712 | char *dname_arg = 0; |
| 697 | #ifdef NS_IMPL_COCOA | 713 | #ifdef DAEMON_MUST_EXEC |
| 698 | char dname_arg2[80]; | 714 | char dname_arg2[80]; |
| 699 | #endif | 715 | #endif /* DAEMON_MUST_EXEC */ |
| 700 | char *ch_to_dir; | 716 | char *ch_to_dir; |
| 701 | 717 | ||
| 702 | #if GC_MARK_STACK | 718 | #if GC_MARK_STACK |
| @@ -998,25 +1014,19 @@ main (int argc, char **argv) | |||
| 998 | exit (1); | 1014 | exit (1); |
| 999 | } | 1015 | } |
| 1000 | 1016 | ||
| 1001 | #ifndef NS_IMPL_COCOA | 1017 | #ifndef DAEMON_MUST_EXEC |
| 1002 | #ifdef USE_GTK | 1018 | #ifdef USE_GTK |
| 1003 | fprintf (stderr, "\nWarning: due to a long standing Gtk+ bug\nhttp://bugzilla.gnome.org/show_bug.cgi?id=85715\n\ | 1019 | fprintf (stderr, "\nWarning: due to a long standing Gtk+ bug\nhttp://bugzilla.gnome.org/show_bug.cgi?id=85715\n\ |
| 1004 | Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost.\n\ | 1020 | Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost.\n\ |
| 1005 | Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.\n"); | 1021 | Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.\n"); |
| 1006 | #endif | 1022 | #endif /* USE_GTK */ |
| 1007 | f = fork (); | 1023 | f = fork (); |
| 1008 | #else /* NS_IMPL_COCOA */ | 1024 | #else /* DAEMON_MUST_EXEC */ |
| 1009 | /* Under Cocoa we must do fork+exec as CoreFoundation lib fails in | ||
| 1010 | forked process: http://developer.apple.com/ReleaseNotes/ | ||
| 1011 | CoreFoundation/CoreFoundation.html) | ||
| 1012 | We mark being in the exec'd process by a daemon name argument of | ||
| 1013 | form "--daemon=\nFD0,FD1\nNAME" where FD are the pipe file descriptors, | ||
| 1014 | NAME is the original daemon name, if any. */ | ||
| 1015 | if (!dname_arg || !strchr (dname_arg, '\n')) | 1025 | if (!dname_arg || !strchr (dname_arg, '\n')) |
| 1016 | f = fork (); /* in orig */ | 1026 | f = fork (); /* in orig */ |
| 1017 | else | 1027 | else |
| 1018 | f = 0; /* in exec'd */ | 1028 | f = 0; /* in exec'd */ |
| 1019 | #endif /* NS_IMPL_COCOA */ | 1029 | #endif /* !DAEMON_MUST_EXEC */ |
| 1020 | if (f > 0) | 1030 | if (f > 0) |
| 1021 | { | 1031 | { |
| 1022 | int retval; | 1032 | int retval; |
| @@ -1052,7 +1062,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem | |||
| 1052 | exit (1); | 1062 | exit (1); |
| 1053 | } | 1063 | } |
| 1054 | 1064 | ||
| 1055 | #ifdef NS_IMPL_COCOA | 1065 | #ifdef DAEMON_MUST_EXEC |
| 1056 | { | 1066 | { |
| 1057 | /* In orig process, forked as child, OR in exec'd. */ | 1067 | /* In orig process, forked as child, OR in exec'd. */ |
| 1058 | if (!dname_arg || !strchr (dname_arg, '\n')) | 1068 | if (!dname_arg || !strchr (dname_arg, '\n')) |
| @@ -1088,7 +1098,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem | |||
| 1088 | dname_arg2); | 1098 | dname_arg2); |
| 1089 | dname_arg = *dname_arg2 ? dname_arg2 : NULL; | 1099 | dname_arg = *dname_arg2 ? dname_arg2 : NULL; |
| 1090 | } | 1100 | } |
| 1091 | #endif /* NS_IMPL_COCOA */ | 1101 | #endif /* DAEMON_MUST_EXEC */ |
| 1092 | 1102 | ||
| 1093 | if (dname_arg) | 1103 | if (dname_arg) |
| 1094 | daemon_name = xstrdup (dname_arg); | 1104 | daemon_name = xstrdup (dname_arg); |