aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog4
-rw-r--r--src/emacs.c51
2 files changed, 55 insertions, 0 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index e662d87e8d9..953e1241c98 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
12009-01-23 Adrian Robert <Adrian.B.Robert@gmail.com>
2
3 * emacs.c (main): Do fork+exec under --daemon in Cocoa.
4
12009-01-23 Giorgos Keramidas <keramida@freebsd.org> (tiny change) 52009-01-23 Giorgos Keramidas <keramida@freebsd.org> (tiny change)
2 6
3 * alloc.c (mark_stack): Use "flushw" instead of "ta 3" assembly 7 * alloc.c (mark_stack): Use "flushw" instead of "ta 3" assembly
diff --git a/src/emacs.c b/src/emacs.c
index f2cb4ac6454..df5e4cdeeb4 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -797,6 +797,9 @@ main (int argc, char **argv)
797 int no_loadup = 0; 797 int no_loadup = 0;
798 char *junk = 0; 798 char *junk = 0;
799 char *dname_arg = 0; 799 char *dname_arg = 0;
800#ifdef NS_IMPL_COCOA
801 char dname_arg2[80];
802#endif
800 803
801#if GC_MARK_STACK 804#if GC_MARK_STACK
802 extern Lisp_Object *stack_base; 805 extern Lisp_Object *stack_base;
@@ -1108,7 +1111,19 @@ main (int argc, char **argv)
1108 exit (1); 1111 exit (1);
1109 } 1112 }
1110 1113
1114#ifndef NS_IMPL_COCOA
1111 f = fork (); 1115 f = fork ();
1116#else
1117 /* Under Cocoa we must do fork+exec:
1118 (http://developer.apple.com/ReleaseNotes/CoreFoundation/CoreFoundation.html)
1119 We mark being in the exec'd process by a daemon name argument of
1120 form "--daemon=\nFD0,FD1\nNAME" where FD are the pipe file descriptors,
1121 NAME is the original daemon name, if any. */
1122 if (!dname_arg || !strchr (dname_arg, '\n'))
1123 f = fork (); /* in orig */
1124 else
1125 f = 0; /* in exec'd */
1126#endif
1112 if (f > 0) 1127 if (f > 0)
1113 { 1128 {
1114 int retval; 1129 int retval;
@@ -1144,6 +1159,42 @@ main (int argc, char **argv)
1144 exit (1); 1159 exit (1);
1145 } 1160 }
1146 1161
1162#ifdef NS_IMPL_COCOA
1163 {
1164 /* in orig process, forked as child, OR in exec'd */
1165 if (!dname_arg || !strchr (dname_arg, '\n'))
1166 { /* in orig, child: now exec w/special daemon name */
1167 char fdStr[80];
1168
1169 if (dname_arg && strlen (dname_arg) > 70)
1170 {
1171 fprintf (stderr, "daemon: child name too long\n");
1172 exit (1);
1173 }
1174
1175 sprintf (fdStr, "--daemon=\n%d,%d\n%s", daemon_pipe[0],
1176 daemon_pipe[1], dname_arg ? dname_arg : "");
1177 argv[skip_args] = fdStr;
1178
1179 execv (argv[0], argv);
1180 fprintf (stderr, "emacs daemon: exec failed: %d\t%d\n", errno);
1181 exit (1);
1182 }
1183
1184 /* in exec'd: parse special dname into pipe and name info */
1185 if (!dname_arg || !strchr (dname_arg, '\n')
1186 || strlen (dname_arg) < 1 || strlen (dname_arg) > 70)
1187 {
1188 fprintf (stderr, "emacs daemon: daemon name absent or too long\n");
1189 exit(1);
1190 }
1191 dname_arg2[0] = '\0';
1192 sscanf (dname_arg, "\n%d,%d\n%s", &(daemon_pipe[0]), &(daemon_pipe[1]),
1193 dname_arg2);
1194 dname_arg = strlen (dname_arg2) ? dname_arg2 : NULL;
1195 }
1196#endif
1197
1147 if (dname_arg) 1198 if (dname_arg)
1148 daemon_name = xstrdup (dname_arg); 1199 daemon_name = xstrdup (dname_arg);
1149 /* Close unused reading end of the pipe. */ 1200 /* Close unused reading end of the pipe. */