From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Adrian Robert Newsgroups: gmane.emacs.bugs 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 Message-ID: Reply-To: Adrian Robert , 1107@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v929.2) Content-Type: multipart/mixed; boundary=Apple-Mail-12--680105112 X-Trace: ger.gmane.org 1228884303 7511 80.91.229.12 (10 Dec 2008 04:45:03 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 10 Dec 2008 04:45:03 +0000 (UTC) To: 1107@emacsbugs.donarmstrong.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Dec 10 05:46:09 2008 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LAGxY-0002lH-SN for geb-bug-gnu-emacs@m.gmane.org; Wed, 10 Dec 2008 05:46:05 +0100 Original-Received: from localhost ([127.0.0.1]:43430 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LAGwN-0007pX-4r for geb-bug-gnu-emacs@m.gmane.org; Tue, 09 Dec 2008 23:44:51 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LAGw1-0007Wr-BD for bug-gnu-emacs@gnu.org; Tue, 09 Dec 2008 23:44:29 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LAGvy-0007TH-PQ for bug-gnu-emacs@gnu.org; Tue, 09 Dec 2008 23:44:28 -0500 Original-Received: from [199.232.76.173] (port=41454 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LAGvy-0007Sl-5J for bug-gnu-emacs@gnu.org; Tue, 09 Dec 2008 23:44:26 -0500 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:56333) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LAGvx-0002Ch-Bw for bug-gnu-emacs@gnu.org; Tue, 09 Dec 2008 23:44:25 -0500 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id mBA4iHrB008034; Tue, 9 Dec 2008 20:44:18 -0800 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.13.8/8.13.8/Submit) id mBA4P3hA002835; Tue, 9 Dec 2008 20:25:03 -0800 X-Loop: don@donarmstrong.com Resent-From: Adrian Robert Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs , don@donarmstrong.com Resent-Date: Wed, 10 Dec 2008 04:25:03 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 1107 X-Emacs-PR-Package: emacs,ns X-Emacs-PR-Keywords: Original-Received: via spool by 1107-submit@emacsbugs.donarmstrong.com id=B1107.12288827611458 (code B ref 1107); Wed, 10 Dec 2008 04:25:03 +0000 X-Spam-Bayes: score:0.0000 Tokens: new, 83; hammy, 147; neutral, 73; spammy, 4. spammytokens:1.000-+--HERE, 0.972-6--hopes, 0.938-+--H*c:multipart, 0.929-+--chance hammytokens:0.000-+--emacs, 0.000-+--23.0.60, 0.000-+--23060, 0.000-+--Emacs, 0.000-+--H*r:TLSv1 Original-Received: (at 1107) by emacsbugs.donarmstrong.com; 10 Dec 2008 04:19:21 +0000 Original-Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.244]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id mBA4JHfa001452 for <1107@emacsbugs.donarmstrong.com>; Tue, 9 Dec 2008 20:19:19 -0800 Original-Received: by an-out-0708.google.com with SMTP id c38so156075ana.31 for <1107@emacsbugs.donarmstrong.com>; Tue, 09 Dec 2008 20:19:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:to:content-type :mime-version:subject:date:x-mailer:from; bh=gQghED1FHOK/0SXxfmIFWPTGImfLsamQ5WXaa8gSUK4=; b=NcRKEXMs8Ol4rmnvKR0X8zrFPBksvD2ruYzG6Xf3iii5jqnZDlVLzJW/Uvq46qRHG+ nbHJM41ZUm182Zh95OMahZ9yTjJamiQTaZdOecKUoXTCIzmvdE0jzRG78jEjRxjnUAjw X/f2q1DjrEJNk+BHgBM/pXS8nE62UTt5gIdTU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:to:content-type:mime-version:subject:date:x-mailer:from; b=GBFaW5i1pItMtaFSIqvM8MI6p51VvM3cTQf+bpWYYFoJrJMu3hJm7NBXuKIhM5qM24 joKU0E1zxb8ye5Rw22ygLGvDFRG9znu4z7Vn+ehLF0F/NnOzwKQKGk1wuj/yquicCcV1 OJskXGkv2e3lIpHuXondFzb3O2yAaJkdUEwAI= Original-Received: by 10.100.131.13 with SMTP id e13mr796393and.57.1228882757323; Tue, 09 Dec 2008 20:19:17 -0800 (PST) Original-Received: from ?10.0.1.198? ([72.169.150.82]) by mx.google.com with ESMTPS id c28sm1213056anc.27.2008.12.09.20.18.57 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 09 Dec 2008 20:19:16 -0800 (PST) X-Mailer: Apple Mail (2.929.2) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Resent-Date: Tue, 09 Dec 2008 23:44:28 -0500 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:23129 Archived-At: --Apple-Mail-12--680105112 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit 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; } --Apple-Mail-12--680105112 Content-Disposition: attachment; filename=daemon_20081209.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="daemon_20081209.patch" Content-Transfer-Encoding: 7bit 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; } --Apple-Mail-12--680105112 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit --Apple-Mail-12--680105112--