From: Adrian Robert <adrian.b.robert@gmail.com>
To: 1107@emacsbugs.donarmstrong.com
Subject: bug#1107: #1107 - 23.0.60; Emacs --daemon crashes when emacsclient tries to establish a connection on OS X - Emacs bug report logs
Date: Tue, 9 Dec 2008 23:18:01 -0500 [thread overview]
Message-ID: <FC0ADEC7-383A-4B9F-9354-AC1FFDA5ABA2@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2940 bytes --]
I have not had the chance to refine my fix so I'm attaching my patch
here in hopes that someone else can work on it. It uses exec()
instead of fork() to launch the child, using a daemon name argument to
differentiate the child. This prevents normal use of the name
argument. Moreover, the pipe connection does not work (not sure why),
so it is disabled.
Index: src/emacs.c
===================================================================
RCS file: /sources/emacs/emacs/src/emacs.c,v
retrieving revision 1.456
diff -u -p -r1.456 emacs.c
--- src/emacs.c 8 Dec 2008 16:22:40 -0000 1.456
+++ src/emacs.c 10 Dec 2008 04:16:16 -0000
@@ -1102,21 +1102,26 @@ main (int argc, char **argv)
use a pipe for synchronization. The parent waits for the child
to close its end of the pipe (using `daemon-initialized')
before exiting. */
+#ifndef HAVE_NS
if (pipe (daemon_pipe) == -1)
{
fprintf (stderr, "Cannot pipe!\n");
exit (1);
}
-
f = fork ();
+#else
+ if (!dname_arg || strcmp (dname_arg, "child"))
+ f = fork ();
+ else
+ f = 0;
+#endif
if (f > 0)
{
int retval;
char buf[1];
-
+#ifndef HAVE_NS
/* Close unused writing end of the pipe. */
close (daemon_pipe[1]);
-
/* Just wait for the child to close its end of the pipe. */
do
{
@@ -1131,6 +1136,9 @@ main (int argc, char **argv)
}
close (daemon_pipe[0]);
+#else
+ sleep(5);
+#endif
exit (0);
}
if (f < 0)
@@ -1139,13 +1147,30 @@ main (int argc, char **argv)
exit (1);
}
+#ifdef HAVE_NS
+ {
+ char *empty[1] = { NULL };
+ char *newargs[4] = {argv[0], "--daemon=child", "-Q", NULL};
+ if (!dname_arg || strcmp (dname_arg, "child")) {
+ int c = execve(argv[0], newargs, empty);
+ fprintf(stderr, "SHOULDN'T BE HERE: %d\t%d\n",c,errno);
+ exit(1);
+ }
+ daemon_pipe[1] = 1; // hack to get IS_DAEMON to work
+ if (dname_arg && !strcmp(dname_arg, "child"))
+ dname_arg = NULL;
+ }
+#endif
+
if (dname_arg)
daemon_name = xstrdup (dname_arg);
+#ifndef HAVE_NS
/* Close unused reading end of the pipe. */
close (daemon_pipe[0]);
/* Make sure that the used end of the pipe is closed on exec, so
that it is not accessible to programs started from .emacs. */
fcntl (daemon_pipe[1], F_SETFD, FD_CLOEXEC);
+#endif
#ifdef HAVE_SETSID
setsid();
@@ -2484,10 +2509,13 @@ from the parent process and its tty file
Instead, we should probably close the pipe in start-process and
call-process to make sure the pipe is never inherited by
subprocesses. */
+#ifndef HAVE_NS
write (daemon_pipe[1], "\n", 1);
close (daemon_pipe[1]);
+#endif
/* Set it to an invalid value so we know we've already run this
function. */
daemon_pipe[1] = -1;
+
return Qt;
}
[-- Attachment #2: daemon_20081209.patch --]
[-- Type: application/octet-stream, Size: 2529 bytes --]
Index: src/emacs.c
===================================================================
RCS file: /sources/emacs/emacs/src/emacs.c,v
retrieving revision 1.456
diff -u -p -r1.456 emacs.c
--- src/emacs.c 8 Dec 2008 16:22:40 -0000 1.456
+++ src/emacs.c 10 Dec 2008 04:16:16 -0000
@@ -1102,21 +1102,26 @@ main (int argc, char **argv)
use a pipe for synchronization. The parent waits for the child
to close its end of the pipe (using `daemon-initialized')
before exiting. */
+#ifndef HAVE_NS
if (pipe (daemon_pipe) == -1)
{
fprintf (stderr, "Cannot pipe!\n");
exit (1);
}
-
f = fork ();
+#else
+ if (!dname_arg || strcmp (dname_arg, "child"))
+ f = fork ();
+ else
+ f = 0;
+#endif
if (f > 0)
{
int retval;
char buf[1];
-
+#ifndef HAVE_NS
/* Close unused writing end of the pipe. */
close (daemon_pipe[1]);
-
/* Just wait for the child to close its end of the pipe. */
do
{
@@ -1131,6 +1136,9 @@ main (int argc, char **argv)
}
close (daemon_pipe[0]);
+#else
+ sleep(5);
+#endif
exit (0);
}
if (f < 0)
@@ -1139,13 +1147,30 @@ main (int argc, char **argv)
exit (1);
}
+#ifdef HAVE_NS
+ {
+ char *empty[1] = { NULL };
+ char *newargs[4] = {argv[0], "--daemon=child", "-Q", NULL};
+ if (!dname_arg || strcmp (dname_arg, "child")) {
+ int c = execve(argv[0], newargs, empty);
+ fprintf(stderr, "SHOULDN'T BE HERE: %d\t%d\n",c,errno);
+ exit(1);
+ }
+ daemon_pipe[1] = 1; // hack to get IS_DAEMON to work
+ if (dname_arg && !strcmp(dname_arg, "child"))
+ dname_arg = NULL;
+ }
+#endif
+
if (dname_arg)
daemon_name = xstrdup (dname_arg);
+#ifndef HAVE_NS
/* Close unused reading end of the pipe. */
close (daemon_pipe[0]);
/* Make sure that the used end of the pipe is closed on exec, so
that it is not accessible to programs started from .emacs. */
fcntl (daemon_pipe[1], F_SETFD, FD_CLOEXEC);
+#endif
#ifdef HAVE_SETSID
setsid();
@@ -2484,10 +2509,13 @@ from the parent process and its tty file
Instead, we should probably close the pipe in start-process and
call-process to make sure the pipe is never inherited by
subprocesses. */
+#ifndef HAVE_NS
write (daemon_pipe[1], "\n", 1);
close (daemon_pipe[1]);
+#endif
/* Set it to an invalid value so we know we've already run this function. */
daemon_pipe[1] = -1;
+
return Qt;
}
[-- Attachment #3: Type: text/plain, Size: 3 bytes --]
next reply other threads:[~2008-12-10 4:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-10 4:18 Adrian Robert [this message]
2008-12-10 6:58 ` bug#1107: #1107 - 23.0.60; Emacs --daemon crashes when emacsclient tries to establish a connection on OS X - Emacs bug report logs Dan Nicolaescu
2008-12-10 15:27 ` Adrian Robert
2008-12-11 16:22 ` Stefan Monnier
2008-12-11 16:21 ` Stefan Monnier
-- strict thread matches above, loose matches on Subject: below --
2008-11-25 4:17 Adrian Robert
2008-11-25 6:20 ` Dan Nicolaescu
2008-11-25 14:47 ` Adrian Robert
2008-11-25 15:27 ` Dan Nicolaescu
2008-11-25 20:08 ` Adrian Robert
2008-11-25 20:34 ` Dan Nicolaescu
2008-11-25 21:15 ` Adrian Robert
2008-11-25 21:24 ` Adrian Robert
2008-11-25 3:47 Adrian Robert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=FC0ADEC7-383A-4B9F-9354-AC1FFDA5ABA2@gmail.com \
--to=adrian.b.robert@gmail.com \
--cc=1107@emacsbugs.donarmstrong.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.