unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#1107: #1107 - 23.0.60; Emacs --daemon crashes when emacsclient tries to establish a connection on OS X - Emacs bug report logs
@ 2008-11-25  4:17 Adrian Robert
  2008-11-25  6:20 ` Dan Nicolaescu
  0 siblings, 1 reply; 14+ messages in thread
From: Adrian Robert @ 2008-11-25  4:17 UTC (permalink / raw)
  To: 1107; +Cc: Dan Nicolaescu, William Farrington

I just tried to replicate this locally and failed.  No crash.   
However, it also doesn't work -- emacsclient just always says "can't  
find socket; have you started the server?".

This is new.  Emacsclient always worked before, up to and including  
multi-tty.  Could something in the new daemon support have affected  
this?  Was there anything in particular that changed as far as how the  
client and server communicate?

gnuserv, which I use, still works.







^ permalink raw reply	[flat|nested] 14+ messages in thread
* bug#1107: #1107 - 23.0.60; Emacs --daemon crashes when emacsclient tries to establish a connection on OS X - Emacs bug report logs
@ 2008-12-10  4:18 Adrian Robert
  2008-12-10  6:58 ` Dan Nicolaescu
  2008-12-11 16:21 ` Stefan Monnier
  0 siblings, 2 replies; 14+ messages in thread
From: Adrian Robert @ 2008-12-10  4:18 UTC (permalink / raw)
  To: 1107

[-- 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 --]





^ permalink raw reply	[flat|nested] 14+ messages in thread
* bug#1107: #1107 - 23.0.60; Emacs --daemon crashes when emacsclient tries to establish a connection on OS X - Emacs bug report logs
@ 2008-11-25  3:47 Adrian Robert
  0 siblings, 0 replies; 14+ messages in thread
From: Adrian Robert @ 2008-11-25  3:47 UTC (permalink / raw)
  To: 1107; +Cc: Dan Nicolaescu, William Farrington

I just tried to replicate this locally and failed.  No crash.   
However, it also doesn't work -- emacsclient just always says "can't  
find socket; have you started the server?".

This is new.  Emacsclient always worked before, up to and including  
multi-tty.  Could something in the new daemon support have affected  
this?  Was there anything in particular that changed as far as how the  
client and server communicate?

gnuserv, which I use, still works.







^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2008-12-11 16:22 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-25  4:17 bug#1107: #1107 - 23.0.60; Emacs --daemon crashes when emacsclient tries to establish a connection on OS X - Emacs bug report logs 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
  -- strict thread matches above, loose matches on Subject: below --
2008-12-10  4:18 Adrian Robert
2008-12-10  6:58 ` Dan Nicolaescu
2008-12-10 15:27   ` Adrian Robert
2008-12-11 16:22     ` Stefan Monnier
2008-12-11 16:21 ` Stefan Monnier
2008-11-25  3:47 Adrian Robert

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).