From unknown Fri Jun 20 05:23:16 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#1058 <1058@debbugs.gnu.org> To: bug#1058 <1058@debbugs.gnu.org> Subject: Status: 23.0.60; emacs --daemon should not return until socket is ready Reply-To: bug#1058 <1058@debbugs.gnu.org> Date: Fri, 20 Jun 2025 12:23:16 +0000 retitle 1058 23.0.60; emacs --daemon should not return until socket is ready reassign 1058 emacs submitter 1058 SRS0+wOMF+22+gmail.com=3Dtrentbuck@internode.on.net severity 1058 normal thanks From SRS0+wOMF+22+gmail.com=trentbuck@internode.on.net Tue Sep 30 07:01:32 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-7.9 required=4.0 tests=BAYES_00,FOURLA, RCVD_IN_DNSWL_MED autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at submit) by emacsbugs.donarmstrong.com; 30 Sep 2008 14:01:32 +0000 Received: from fencepost.gnu.org (fencepost.gnu.org [140.186.70.10]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m8UE1N8C003652 for ; Tue, 30 Sep 2008 07:01:24 -0700 Received: from mail.gnu.org ([199.232.76.166]:47012 helo=mx10.gnu.org) by fencepost.gnu.org with esmtp (Exim 4.67) (envelope-from ) id 1Kkfkr-0001s6-US for emacs-pretest-bug@gnu.org; Tue, 30 Sep 2008 09:59:10 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Kkfmx-0006pu-UA for emacs-pretest-bug@gnu.org; Tue, 30 Sep 2008 10:01:21 -0400 Received: from bld-mail07.adl2.internode.on.net ([203.16.214.71]:52355 helo=mail.internode.on.net) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Kkfmx-0006pG-7L for emacs-pretest-bug@gnu.org; Tue, 30 Sep 2008 10:01:19 -0400 Received: from localhost (unverified [118.208.170.75]) by mail.internode.on.net (SurgeMail 3.8f2) with ESMTP id 46131888-1849793 for multiple; Tue, 30 Sep 2008 23:13:54 +0930 (CST) To: emacs-pretest-bug@gnu.org CC: rfrancoise@debian.org, trentbuck@gmail.com Subject: 23.0.60; emacs --daemon should not return until socket is ready Date: Tue, 30 Sep 2008 23:13:54 +0930 (CST) Message-ID: <1222782234_2281@mail.internode.on.net> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) From: SRS0+wOMF+22+gmail.com=trentbuck@internode.on.net >From this transcript, you can see that after starting 'emacs --daemon', it takes five seconds before the socket is actually available for emacsclient to talk to it. $ emacs --daemon; while ! ls /tmp/emacs1187/; do sleep 1; done emacs: no process killed ls: cannot access /tmp/emacs1187/: No such file or directory ls: cannot access /tmp/emacs1187/: No such file or directory ls: cannot access /tmp/emacs1187/: No such file or directory ls: cannot access /tmp/emacs1187/: No such file or directory server This is evil; it means that making $ALTERNATE_EDITOR a script that just does emacs --daemon && emacsclient results in a loop, because the socket isn't ready when emacsclient starts -- so emacsclient runs the above script again. For --daemon to be useful to me, it really must not exit until the socket is ready. A filthy workaround might look something like this. #!/bin/bash -e emacs --daemon while ! test -e /tmp/emacs$EUID/server do sleep 1 done emacsclient In GNU Emacs 23.0.60.1 (i486-pc-linux-gnu, GTK+ Version 2.12.11) of 2008-09-28 on elegiac, modified by Debian (emacs-snapshot package, version 1:20080928-1) configured using `configure '--build' 'i486-linux-gnu' '--host' 'i486-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--enable-locallisppath=/etc/emacs-snapshot:/etc/emacs:/usr/local/share/emacs/23.0.60/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/23.0.60/site-lisp:/usr/share/emacs/site-lisp' '--with-x=yes' '--with-x-toolkit=gtk' 'build_alias=i486-linux-gnu' 'host_alias=i486-linux-gnu' 'CFLAGS=-DDEBIAN -DSITELOAD_PURESIZE_EXTRA=5000 -g -O2' 'LDFLAGS=-g -Wl,--as-needed' 'CPPFLAGS='' Important settings: value of $LC_ALL: nil value of $LC_COLLATE: C value of $LC_CTYPE: nil value of $LC_MESSAGES: nil value of $LC_MONETARY: nil value of $LC_NUMERIC: nil value of $LC_TIME: nil value of $LANG: en_AU.utf8 value of $XMODIFIERS: nil locale-coding-system: utf-8-unix default-enable-multibyte-characters: t Major mode: Lisp Interaction Minor modes in effect: tooltip-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t global-auto-composition-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t line-number-mode: t transient-mark-mode: t Recent input: ESC x r e p o r t SPC e m a c s SPC b u TAB RET Recent messages: ("emacs" "-Q") For information about GNU Emacs and the GNU system, type C-h C-a. From dann@mothra.ics.uci.edu Wed Oct 1 09:51:55 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.3 required=4.0 tests=AWL,BAYES_00,FOURLA, HAS_BUG_NUMBER,MURPHY_DRUGS_REL8 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 1 Oct 2008 16:51:55 +0000 Received: from barrelv2.ics.uci.edu (barrelv2.ics.uci.edu [128.195.1.114]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m91GpquG002973 for <1058@emacsbugs.donarmstrong.com>; Wed, 1 Oct 2008 09:51:53 -0700 Received: from mothra.ics.uci.edu (mothra.ics.uci.edu [128.195.6.93]) by barrelv2.ics.uci.edu (8.13.7+Sun/8.13.7) with ESMTP id m91GpCY1010114; Wed, 1 Oct 2008 09:51:15 -0700 (PDT) Received: (from dann@localhost) by mothra.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id m91GpAZQ010333; Wed, 1 Oct 2008 09:51:10 -0700 (PDT) Date: Wed, 1 Oct 2008 09:51:10 -0700 (PDT) Message-Id: <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> From: Dan Nicolaescu To: SRS0+wOMF+22+gmail.com=trentbuck@internode.on.net Cc: 1058@debbugs.gnu.org, trentbuck@gmail.com, rfrancoise@debian.org Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready References: <1222782234_2281@mail.internode.on.net> In-Reply-To: <1222782234_2281@mail.internode.on.net> (SRS0's message of "Tue, 30 Sep 2008 23:13:54 +0930 (CST)") Lines: 31 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: m91GpCY1010114 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=-1.44, required 5, autolearn=disabled, ALL_TRUSTED -1.44) X-ICS-MailScanner-From: dann@mothra.ics.uci.edu SRS0+wOMF+22+gmail.com=trentbuck@internode.on.net writes: > From this transcript, you can see that after starting 'emacs > --daemon', it takes five seconds before the socket is actually > available for emacsclient to talk to it. > > $ emacs --daemon; while ! ls /tmp/emacs1187/; do sleep 1; done Just curious, what do you get if you do: emacs -Q --daemon; while ! ls /tmp/emacs1187/; do sleep 1; done > emacs: no process killed > ls: cannot access /tmp/emacs1187/: No such file or directory > ls: cannot access /tmp/emacs1187/: No such file or directory > ls: cannot access /tmp/emacs1187/: No such file or directory > ls: cannot access /tmp/emacs1187/: No such file or directory > server > > This is evil; it means that making $ALTERNATE_EDITOR a script that > just does > > emacs --daemon && emacsclient > > results in a loop, because the socket isn't ready when emacsclient > starts -- so emacsclient runs the above script again. For --daemon to > be useful to me, it really must not exit until the socket is ready. Unfortunately ATM I don't see an easy way to do that. Ideas/patches are certainly welcome. From romain@orebokech.com Wed Oct 1 12:39:46 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-7.1 required=4.0 tests=AWL,BAYES_00,FOURLA, FVGT_m_MULTI_ODD,HAS_BUG_NUMBER,IMPRONONCABLE_2,MURPHY_DRUGS_REL8 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 1 Oct 2008 19:39:46 +0000 Received: from smtp1-g19.free.fr (smtp1-g19.free.fr [212.27.42.27]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m91JdggD012350 for <1058@emacsbugs.donarmstrong.com>; Wed, 1 Oct 2008 12:39:43 -0700 Received: from smtp1-g19.free.fr (localhost.localdomain [127.0.0.1]) by smtp1-g19.free.fr (Postfix) with ESMTP id 77ACC1AB31F; Wed, 1 Oct 2008 21:39:41 +0200 (CEST) Received: from elegiac.orebokech.com (home.orebokech.com [82.67.41.165]) by smtp1-g19.free.fr (Postfix) with ESMTP id 1EDD01AB39E; Wed, 1 Oct 2008 21:39:40 +0200 (CEST) Received: by elegiac.orebokech.com (Postfix, from userid 1000) id 2F8CB3B1DF; Wed, 1 Oct 2008 21:39:40 +0200 (CEST) From: Romain Francoise To: Dan Nicolaescu Cc: 1058@debbugs.gnu.org, trentbuck@gmail.com Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Organization: orebokech dot com References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> X-Face: }9mYu,e_@+e!`Z-P5kVXa3\_b:hdJ"B)ww[&=b<2=awG:GOIM (Dan Nicolaescu's message of "Wed, 1 Oct 2008 09:51:10 -0700 (PDT)") Message-ID: <87k5csds03.fsf@elegiac.orebokech.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Hi Dan, Trent, Dan Nicolaescu writes: > Just curious, what do you get if you do: > emacs -Q --daemon; while ! ls /tmp/emacs1187/; do sleep 1; done Yes, the delay is caused by my change to load the init file before starting the server. > Unfortunately ATM I don't see an easy way to do that. > Ideas/patches are certainly welcome. It's easy to do, but not very clean. WDYT? diff --git a/lisp/startup.el b/lisp/startup.el index 5bd73f9..d9e37be 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -1224,7 +1224,8 @@ opening the first frame (e.g. open a connection to an X server).") ;; processing all command line arguments to allow e.g. `server-name' ;; to be changed before the server starts. (when (daemonp) - (server-start)) + (server-start) + (daemon-detach-parent)) ;; Run emacs-session-restore (session management) if started by ;; the session manager and we have a session manager connection. diff --git a/src/emacs.c b/src/emacs.c index f94d2d3..a2842d4 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -235,6 +235,10 @@ int noninteractive1; /* Nonzero means Emacs was started as a daemon. */ int is_daemon = 0; +/* Pipe used to send exit notification to the daemon parent at + startup. */ +int daemon_pipe[2]; + /* Save argv and argc. */ char **initial_argv; int initial_argc; @@ -1074,16 +1078,31 @@ main (int argc, char **argv) if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)) { #ifndef DOS_NT + if (pipe (daemon_pipe) == -1) + { + fprintf (stderr, "Cannot pipe!\n"); + exit (1); + } pid_t f = fork (); int nfd; if (f > 0) - exit (0); + { + char buf[2]; + close (daemon_pipe[1]); + /* Wait for the child to close its end of the pipe before + exiting. */ + while (read (daemon_pipe[0], &buf, 1) < 0) + sleep (0.1); + close (daemon_pipe[0]); + exit (0); + } if (f < 0) { fprintf (stderr, "Cannot fork!\n"); exit (1); } + close (daemon_pipe[0]); nfd = open ("/dev/null", O_RDWR); dup2 (nfd, 0); dup2 (nfd, 1); @@ -2389,6 +2408,16 @@ DEFUN ("daemonp", Fdaemonp, Sdaemonp, 0, 0, 0, return is_daemon ? Qt : Qnil; } +DEFUN ("daemon-detach-parent", Fdaemon_detach_parent, Sdaemon_detach_parent, + 0, 0, 0, + doc: /* Detach Emacs from its invocation parent if it was started as a daemon. */) + () +{ + if (is_daemon) + close (daemon_pipe[1]); + return Qt; +} + void syms_of_emacs () { @@ -2408,6 +2437,7 @@ syms_of_emacs () defsubr (&Sinvocation_name); defsubr (&Sinvocation_directory); defsubr (&Sdaemonp); + defsubr (&Sdaemon_detach_parent); DEFVAR_LISP ("command-line-args", &Vcommand_line_args, doc: /* Args passed by shell to Emacs, as a list of strings. From schwab@suse.de Wed Oct 1 13:19:10 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-10.6 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER, RCVD_IN_DNSWL_MED autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 1 Oct 2008 20:19:11 +0000 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m91KJ7sG022538 for <1058@emacsbugs.donarmstrong.com>; Wed, 1 Oct 2008 13:19:08 -0700 Received: from Relay1.suse.de (mail2.suse.de [195.135.221.8]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 0B68645C52; Wed, 1 Oct 2008 22:19:06 +0200 (CEST) From: Andreas Schwab To: Romain Francoise Cc: 1058@debbugs.gnu.org, Dan Nicolaescu , trentbuck@gmail.com Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> X-Yow: FIRST, I was in a TRUCK...THEN, I was in a DINER... Date: Wed, 01 Oct 2008 22:19:05 +0200 In-Reply-To: <87k5csds03.fsf@elegiac.orebokech.com> (Romain Francoise's message of "Wed, 01 Oct 2008 21:39:40 +0200") Message-ID: User-Agent: Gnus/5.110009 (No Gnus v0.9) Emacs/22.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Romain Francoise writes: > + while (read (daemon_pipe[0], &buf, 1) < 0) > + sleep (0.1); sleep takes an integer, not a float. Andreas. -- Andreas Schwab, SuSE Labs, schwab@suse.de SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different." From dann@mothra.ics.uci.edu Wed Oct 1 16:32:37 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.3 required=4.0 tests=AWL,BAYES_00,FOURLA, HAS_BUG_NUMBER,MURPHY_DRUGS_REL8 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 1 Oct 2008 23:32:37 +0000 Received: from sallyv2.ics.uci.edu (sallyv2.ics.uci.edu [128.195.1.120]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m91NWYL2005881 for <1058@emacsbugs.donarmstrong.com>; Wed, 1 Oct 2008 16:32:35 -0700 Received: from mothra.ics.uci.edu (mothra.ics.uci.edu [128.195.6.93]) by sallyv2.ics.uci.edu (8.13.7+Sun/8.13.7) with ESMTP id m91NWK0K011523; Wed, 1 Oct 2008 16:32:20 -0700 (PDT) Received: (from dann@localhost) by mothra.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id m91NWJ4s014658; Wed, 1 Oct 2008 16:32:19 -0700 (PDT) Date: Wed, 1 Oct 2008 16:32:19 -0700 (PDT) Message-Id: <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> From: Dan Nicolaescu To: Romain Francoise Cc: 1058@debbugs.gnu.org, trentbuck@gmail.com Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> In-Reply-To: <87k5csds03.fsf@elegiac.orebokech.com> (Romain Francoise's message of "Wed, 01 Oct 2008 21:39:40 +0200") Lines: 19 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: m91NWK0K011523 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=-1.44, required 5, autolearn=disabled, ALL_TRUSTED -1.44) X-ICS-MailScanner-From: dann@mothra.ics.uci.edu Romain Francoise writes: > Hi Dan, Trent, > > Dan Nicolaescu writes: > > > Just curious, what do you get if you do: > > emacs -Q --daemon; while ! ls /tmp/emacs1187/; do sleep 1; done > > Yes, the delay is caused by my change to load the init file before > starting the server. > > > Unfortunately ATM I don't see an easy way to do that. > > Ideas/patches are certainly welcome. > > It's easy to do, but not very clean. WDYT? It would be much better if this could be done without a state changing function callable from elisp. From trentbuck@gmail.com Wed Oct 1 17:43:15 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-7.0 required=4.0 tests=BAYES_00,HAS_BUG_NUMBER autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 2 Oct 2008 00:43:15 +0000 Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.178]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m920hCeu023082 for <1058@emacsbugs.donarmstrong.com>; Wed, 1 Oct 2008 17:43:13 -0700 Received: by wa-out-1112.google.com with SMTP id j40so491157wah.1 for <1058@emacsbugs.donarmstrong.com>; Wed, 01 Oct 2008 17:43:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=bV8IBshqykCu45YVQm5n0dramrFtBpzIgfNJbb0Rrxg=; b=wJslz0rFLAAcMHFjQJzZWEh/UP5xIq4zSU3vVpzg4d5qzSnswKZ9AeFz+Yu9G8KRQ0 ah9x+vuewCO7GRObW+c3QNBJ3oQ6s2xQKB7oh6r7dAdQt7O9nkQ6XRdPqx8BlrwDsl7A uoR60pTaFQbzpDRaTQV9z0YymQsfukZKpsQSI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=QTMjrEvGyZ8c+KiJR723T8fdXZG9TM2MfIii5nrml1uWX/WPGa5fhll9irPV4DcdUH 3ShedLNPz1O7mu0F1Zly+CtBJQpEt3LJH7A2tqnlUXQUcTl7iHVT9YOSh/oquptw8J6u vxwFinOhdkKKWtNWkuheERawGHhTiJVBw1iqk= Received: by 10.114.57.15 with SMTP id f15mr10079980waa.116.1222908191868; Wed, 01 Oct 2008 17:43:11 -0700 (PDT) Received: from localhost ([203.7.155.64]) by mx.google.com with ESMTPS id m29sm694541poh.7.2008.10.01.17.43.09 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 01 Oct 2008 17:43:11 -0700 (PDT) Date: Thu, 2 Oct 2008 10:43:24 +1000 From: "Trent W. Buck" To: Dan Nicolaescu Cc: 1058@debbugs.gnu.org, rfrancoise@debian.org Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Message-ID: <20081002004323.GA2400@Clio.twb.ath.cx> References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> User-Agent: Mutt/1.5.18 (2008-05-17) On Wed, Oct 01, 2008 at 09:51:10AM -0700, Dan Nicolaescu wrote: >> From this transcript, you can see that after starting 'emacs >> --daemon', it takes five seconds before the socket is actually >> available for emacsclient to talk to it. >> >> $ emacs --daemon; while ! ls /tmp/emacs1187/; do sleep 1; done > > Just curious, what do you get if you do: > > emacs -Q --daemon; while ! ls /tmp/emacs1187/; do sleep 1; done I get the same problem. Running c++ elsewhere and starting Emacs nicely, I managed to get the delay up to 17 seconds. $ nice -n 19 emacs -Q --daemon; until ls /tmp/emacs1187/; do sleep 1; done ls: cannot access /tmp/emacs1187/: No such file or directory [repeats 16 times] server From trentbuck@gmail.com Wed Oct 1 17:50:11 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-7.0 required=4.0 tests=BAYES_00,HAS_BUG_NUMBER autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 2 Oct 2008 00:50:12 +0000 Received: from rv-out-0506.google.com (rv-out-0506.google.com [209.85.198.237]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m920o8LV024959 for <1058@emacsbugs.donarmstrong.com>; Wed, 1 Oct 2008 17:50:09 -0700 Received: by rv-out-0506.google.com with SMTP id k40so877708rvb.1 for <1058@emacsbugs.donarmstrong.com>; Wed, 01 Oct 2008 17:50:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=VsgKsmSnNWqt6yoBH0fIogOf11tzYNGj8+dZ6pdLnJw=; b=rFR6QfzwXoyqazLXGXo1n/THmXiu4k/pD7z4/mWo0dilPyn6cn1BeLfVKgA1B0YlG7 GFnzR8lZS+gonlgXnSppGZZeJ7XLBxk7ZAM0af3l/EepkR5xGrNBfSasH3/ZYU0aLs6f kVJDUhqI/1gZLjxag//FwvPafoI4lc2RYClsI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=b7lL5dEDph99gGKtQWYi/CUBdbaXlFTMTpWIbpAU0yvXyh1B4krN9IwFCTEtjKlVjc 4Am7tuiL3laQcZpTi5h/JnK3eot6BtIrY1VuZgAzUg78F/OW5CtUne2z6dDfxxtK+H46 4TUYZ9Z3K1VkmFM9jU8D/Ou7kfEsSzTZq14/k= Received: by 10.115.76.1 with SMTP id d1mr10050941wal.207.1222908608246; Wed, 01 Oct 2008 17:50:08 -0700 (PDT) Received: from localhost ([203.7.155.64]) by mx.google.com with ESMTPS id t1sm699402poh.13.2008.10.01.17.50.06 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 01 Oct 2008 17:50:07 -0700 (PDT) Date: Thu, 2 Oct 2008 10:50:21 +1000 From: "Trent W. Buck" To: Romain Francoise Cc: Dan Nicolaescu , 1058@debbugs.gnu.org Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Message-ID: <20081002005020.GB2400@Clio.twb.ath.cx> References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87k5csds03.fsf@elegiac.orebokech.com> User-Agent: Mutt/1.5.18 (2008-05-17) On Wed, Oct 01, 2008 at 09:39:40PM +0200, Romain Francoise wrote: >> Just curious, what do you get if you do: emacs -Q --daemon; while ! >> ls /tmp/emacs1187/; do sleep 1; done > > Yes, the delay is caused by my change to load the init file before > starting the server. It's vaguely relevant that I have this in my .emacs: (progn (unless (< emacs-major-version 22) ;; Support multiple, concurrent Emacs servers. (setq server-name (format "server%d" (emacs-pid))) ;; Allow child processes to find the correct one. (setenv "EMACS_SOCKET_FILE" server-name) ;; Have other processes use the youngest server. (defadvice server-start (after multiple-server-start) (make-symbolic-link server-name (concat server-socket-dir "/server") t)) (ad-activate 'server-start)) (server-start)) and an emacsclient wrapper that includes ## In M-x shell always use the focused emacs, even if there are ## other Emacs servers. Requires non-standard $EMACS_SOCKET_FILE, ## which is set in my .emacs. Needs Emacs 22 or better. if [[ $EMACS_SOCKET_FILE && $INSIDE_EMACS && $v -ge 22 ]] ## With DISPLAY emacsclient tries to pop up an X frame. then exec env -u DISPLAY emacsclient -s "$EMACS_SOCKET_FILE" "$@" fi From romain@orebokech.com Wed Oct 1 23:05:48 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-7.3 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 2 Oct 2008 06:05:48 +0000 Received: from smtp6-g19.free.fr (smtp6-g19.free.fr [212.27.42.36]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m9265j53006722 for <1058@emacsbugs.donarmstrong.com>; Wed, 1 Oct 2008 23:05:46 -0700 Received: from smtp6-g19.free.fr (localhost.localdomain [127.0.0.1]) by smtp6-g19.free.fr (Postfix) with ESMTP id 4878E197B5; Thu, 2 Oct 2008 08:05:44 +0200 (CEST) Received: from elegiac.orebokech.com (home.orebokech.com [82.67.41.165]) by smtp6-g19.free.fr (Postfix) with ESMTP id 256551970C; Thu, 2 Oct 2008 08:05:44 +0200 (CEST) Received: by elegiac.orebokech.com (Postfix, from userid 1000) id D0A3D3B1DF; Thu, 2 Oct 2008 08:05:43 +0200 (CEST) From: Romain Francoise To: Andreas Schwab Cc: 1058@debbugs.gnu.org, Dan Nicolaescu , trentbuck@gmail.com Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Organization: orebokech dot com References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> X-Face: }9mYu,e_@+e!`Z-P5kVXa3\_b:hdJ"B)ww[&=b<2=awG:GOIM (Andreas Schwab's message of "Wed, 01 Oct 2008 22:19:05 +0200") Message-ID: <878wt7edl4.fsf@elegiac.orebokech.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Andreas Schwab writes: > sleep takes an integer, not a float. Hrm, yeah. And the detach function should be guarded otherwise it would close random fds on each call, which is probably not what we want. And the while-sleep loop should be done differently. But anyway, this was just a quick proof of concept, it happened to compile and work on the first try, so... From romain@orebokech.com Wed Oct 1 23:07:05 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-7.3 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 2 Oct 2008 06:07:05 +0000 Received: from smtp8-g19.free.fr (smtp8-g19.free.fr [212.27.42.65]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m92672S1006731 for <1058@emacsbugs.donarmstrong.com>; Wed, 1 Oct 2008 23:07:03 -0700 Received: from smtp8-g19.free.fr (localhost [127.0.0.1]) by smtp8-g19.free.fr (Postfix) with ESMTP id 69DD132A7D6; Thu, 2 Oct 2008 08:07:01 +0200 (CEST) Received: from elegiac.orebokech.com (home.orebokech.com [82.67.41.165]) by smtp8-g19.free.fr (Postfix) with ESMTP id 4F07732A78B; Thu, 2 Oct 2008 08:07:01 +0200 (CEST) Received: by elegiac.orebokech.com (Postfix, from userid 1000) id 1CE5B3B1DF; Thu, 2 Oct 2008 08:07:01 +0200 (CEST) From: Romain Francoise To: Dan Nicolaescu Cc: 1058@debbugs.gnu.org, trentbuck@gmail.com Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Organization: orebokech dot com References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> X-Face: }9mYu,e_@+e!`Z-P5kVXa3\_b:hdJ"B)ww[&=b<2=awG:GOIM (Dan Nicolaescu's message of "Wed, 1 Oct 2008 16:32:19 -0700 (PDT)") Message-ID: <874p3vediy.fsf@elegiac.orebokech.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Dan Nicolaescu writes: > It would be much better if this could be done without a state > changing function callable from elisp. I agree, but given that control passes to Lisp pretty early, I don't see how it can be done. From dann@mothra.ics.uci.edu Thu Oct 2 01:14:56 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.4 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER, MURPHY_DRUGS_REL8 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 2 Oct 2008 08:14:56 +0000 Received: from sallyv2.ics.uci.edu (sallyv2.ics.uci.edu [128.195.1.120]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m928Es6m005342 for <1058@emacsbugs.donarmstrong.com>; Thu, 2 Oct 2008 01:14:55 -0700 Received: from mothra.ics.uci.edu (mothra.ics.uci.edu [128.195.6.93]) by sallyv2.ics.uci.edu (8.13.7+Sun/8.13.7) with ESMTP id m928Edg9016974; Thu, 2 Oct 2008 01:14:39 -0700 (PDT) Received: (from dann@localhost) by mothra.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id m928Ed1C016380; Thu, 2 Oct 2008 01:14:39 -0700 (PDT) Date: Thu, 2 Oct 2008 01:14:39 -0700 (PDT) Message-Id: <200810020814.m928Ed1C016380@mothra.ics.uci.edu> From: Dan Nicolaescu To: Romain Francoise Cc: 1058@debbugs.gnu.org, trentbuck@gmail.com Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> In-Reply-To: <874p3vediy.fsf@elegiac.orebokech.com> (Romain Francoise's message of "Thu, 02 Oct 2008 08:07:01 +0200") Lines: 24 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: m928Edg9016974 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=-1.44, required 5, autolearn=disabled, ALL_TRUSTED -1.44) X-ICS-MailScanner-From: dann@mothra.ics.uci.edu Romain Francoise writes: > Dan Nicolaescu writes: > > > It would be much better if this could be done without a state > > changing function callable from elisp. > > I agree, but given that control passes to Lisp pretty early, I don't > see how it can be done. That's exactly the reason for my initial reply... Anyway, your patch probably needs an approval from a maintainer. And a better name and docstring for daemon-detach-parent would be needed. Also daemon-detach-parent should throw an error if called in the non-daemon case, and when called more than once. More comments explaining what's going on would also be nic. Maybe use select instead of read+sleep? Or signals? Should also do something in case the child dies before it calls daemon-detach-parent. From monnier@iro.umontreal.ca Thu Oct 2 05:39:02 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-5.3 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER, MURPHY_DRUGS_REL8 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 2 Oct 2008 12:39:02 +0000 Received: from ironport2-out.teksavvy.com (ironport2-out.pppoe.ca [206.248.154.182]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m92CcwZ5007534 for <1058@emacsbugs.donarmstrong.com>; Thu, 2 Oct 2008 05:39:00 -0700 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApsEAP5d5EjO+KVj/2dsb2JhbACBZrsXgWqBBoIe X-IronPort-AV: E=Sophos;i="4.33,351,1220241600"; d="scan'208";a="27857894" Received: from 206-248-165-99.dsl.teksavvy.com (HELO pastel.home) ([206.248.165.99]) by ironport2-out.teksavvy.com with ESMTP; 02 Oct 2008 08:38:53 -0400 Received: by pastel.home (Postfix, from userid 20848) id 17DB080D0; Thu, 2 Oct 2008 08:38:53 -0400 (EDT) From: Stefan Monnier To: Dan Nicolaescu Cc: 1058@debbugs.gnu.org, Romain Francoise , trentbuck@gmail.com Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Message-ID: References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> Date: Thu, 02 Oct 2008 08:38:53 -0400 In-Reply-To: <200810020814.m928Ed1C016380@mothra.ics.uci.edu> (Dan Nicolaescu's message of "Thu, 2 Oct 2008 01:14:39 -0700 (PDT)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii >> > It would be much better if this could be done without a state >> > changing function callable from elisp. >> I agree, but given that control passes to Lisp pretty early, I don't >> see how it can be done. > That's exactly the reason for my initial reply... > Anyway, your patch probably needs an approval from a maintainer. I could accept a similar patch, maybe, but first I need to understand why/where we currently "detach" so early. Stefan From dann@mothra.ics.uci.edu Thu Oct 2 10:27:04 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.4 required=4.0 tests=AWL,BAYES_00,FOURLA, HAS_BUG_NUMBER,MURPHY_DRUGS_REL8 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 2 Oct 2008 17:27:04 +0000 Received: from barrelv2.ics.uci.edu (barrelv2.ics.uci.edu [128.195.1.114]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m92HR16q016044 for <1058@emacsbugs.donarmstrong.com>; Thu, 2 Oct 2008 10:27:02 -0700 Received: from mothra.ics.uci.edu (mothra.ics.uci.edu [128.195.6.93]) by barrelv2.ics.uci.edu (8.13.7+Sun/8.13.7) with ESMTP id m92HQdG6011699; Thu, 2 Oct 2008 10:26:43 -0700 (PDT) Received: (from dann@localhost) by mothra.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id m92HQcTQ017644; Thu, 2 Oct 2008 10:26:38 -0700 (PDT) Date: Thu, 2 Oct 2008 10:26:38 -0700 (PDT) Message-Id: <200810021726.m92HQcTQ017644@mothra.ics.uci.edu> From: Dan Nicolaescu To: Stefan Monnier Cc: 1058@debbugs.gnu.org, Romain Francoise , trentbuck@gmail.com Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> In-Reply-To: (Stefan Monnier's message of "Thu, 02 Oct 2008 08:38:53 -0400") Lines: 27 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: m92HQdG6011699 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=-1.44, required 5, autolearn=disabled, ALL_TRUSTED -1.44) X-ICS-MailScanner-From: dann@mothra.ics.uci.edu Stefan Monnier writes: > >> > It would be much better if this could be done without a state > >> > changing function callable from elisp. > >> I agree, but given that control passes to Lisp pretty early, I don't > >> see how it can be done. > > That's exactly the reason for my initial reply... > > Anyway, your patch probably needs an approval from a maintainer. > > I could accept a similar patch, maybe, but first I need to understand > why/where we currently "detach" so early. Where? in emacs.c:main, look for: if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)) { #ifndef DOS_NT pid_t f = fork (); Why? - mainly because I never thought about the emacs --daemon && emacsclient use-case. - in order to not make detaching an elisp function, and have to deal with users trying to call it from different contexts - the `fork' call for detaching needs to happen before some of the initialization is run (although after my 2008-09-28 change it might be possible to push it later), and also before .emacs is run and before the server is started. From romain@orebokech.com Thu Oct 2 10:55:39 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.7 required=4.0 tests=AWL,BAYES_00,FOURLA, FVGT_m_MULTI_ODD,HAS_BUG_NUMBER,IMPRONONCABLE_2,MURPHY_DRUGS_REL8 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 2 Oct 2008 17:55:39 +0000 Received: from smtp6-g19.free.fr (smtp6-g19.free.fr [212.27.42.36]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m92Htaop023031 for <1058@emacsbugs.donarmstrong.com>; Thu, 2 Oct 2008 10:55:37 -0700 Received: from smtp6-g19.free.fr (localhost.localdomain [127.0.0.1]) by smtp6-g19.free.fr (Postfix) with ESMTP id 7229A17299; Thu, 2 Oct 2008 19:55:35 +0200 (CEST) Received: from elegiac.orebokech.com (home.orebokech.com [82.67.41.165]) by smtp6-g19.free.fr (Postfix) with ESMTP id 8BAED17280; Thu, 2 Oct 2008 19:55:11 +0200 (CEST) Received: by elegiac.orebokech.com (Postfix, from userid 1000) id 8F21F3B1DF; Thu, 2 Oct 2008 19:54:51 +0200 (CEST) From: Romain Francoise To: Dan Nicolaescu Cc: Stefan Monnier , 1058@debbugs.gnu.org, trentbuck@gmail.com Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Organization: orebokech dot com References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> X-Face: }9mYu,e_@+e!`Z-P5kVXa3\_b:hdJ"B)ww[&=b<2=awG:GOIM (Dan Nicolaescu's message of "Thu, 2 Oct 2008 01:14:39 -0700 (PDT)") Message-ID: <87myhmdgr8.fsf@elegiac.orebokech.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Here's version one of a patch for this, please let me know what you think. diff --git a/lisp/startup.el b/lisp/startup.el index 5bd73f9..22c92c5 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -1224,7 +1224,8 @@ opening the first frame (e.g. open a connection to an X server).") ;; processing all command line arguments to allow e.g. `server-name' ;; to be changed before the server starts. (when (daemonp) - (server-start)) + (server-start) + (daemon-initialized)) ;; Run emacs-session-restore (session management) if started by ;; the session manager and we have a session manager connection. diff --git a/src/emacs.c b/src/emacs.c index f94d2d3..d4d16b7 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -235,6 +235,13 @@ int noninteractive1; /* Nonzero means Emacs was started as a daemon. */ int is_daemon = 0; +/* Set nonzero after the daemon has finished initializing. */ +int daemon_initialized = 0; + +/* Pipe used to send exit notification to the daemon parent at + startup. */ +int daemon_pipe[2]; + /* Save argv and argc. */ char **initial_argv; int initial_argc; @@ -1074,16 +1081,56 @@ main (int argc, char **argv) if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)) { #ifndef DOS_NT - pid_t f = fork (); + pid_t f; int nfd; + + /* Start as a daemon: fork a new child process which will run the + rest of the initialization code, then exit. + + We want to avoid exiting before the server socket is ready, so + use a pipe for synchronization. The parent waits for the child + to close its end of the pipe (using `daemon-initialized') + before exiting. */ + if (pipe (daemon_pipe) == -1) + { + fprintf (stderr, "Cannot pipe!\n"); + exit (1); + } + + f = fork (); if (f > 0) - exit (0); + { + int retval; + char buf[1]; + + /* Close unused writing end of the pipe. */ + close (daemon_pipe[1]); + + /* Just wait for the child to close its end of the pipe. */ + do + { + retval = read (daemon_pipe[0], &buf, 1); + } + while (retval == -1 && errno == EINTR); + + if (retval < 0) + { + fprintf (stderr, "Error reading status from child\n"); + exit (1); + } + + close (daemon_pipe[0]); + exit (0); + } if (f < 0) { fprintf (stderr, "Cannot fork!\n"); exit (1); } + /* Close unused reading end of the pipe. */ + close (daemon_pipe[0]); + nfd = open ("/dev/null", O_RDWR); dup2 (nfd, 0); dup2 (nfd, 1); @@ -2389,6 +2436,24 @@ DEFUN ("daemonp", Fdaemonp, Sdaemonp, 0, 0, 0, return is_daemon ? Qt : Qnil; } +DEFUN ("daemon-initialized", Fdaemon_initialized, Sdaemon_initialized, 0, 0, 0, + doc: /* Mark the Emacs daemon as being initialized. */) + () +{ + if (is_daemon) + { + if (! daemon_initialized) + { + /* Closing the pipe will notify the parent that it can exit. */ + close (daemon_pipe[1]); + daemon_initialized = 1; + } + } + else + error ("Emacs was not started as a daemon"); + return daemon_initialized ? Qt : Qnil; +} + void syms_of_emacs () { @@ -2408,6 +2473,7 @@ syms_of_emacs () defsubr (&Sinvocation_name); defsubr (&Sinvocation_directory); defsubr (&Sdaemonp); + defsubr (&Sdaemon_initialized); DEFVAR_LISP ("command-line-args", &Vcommand_line_args, doc: /* Args passed by shell to Emacs, as a list of strings. From dann@mothra.ics.uci.edu Thu Oct 2 11:40:43 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-5.9 required=4.0 tests=AWL,BAYES_00,FOURLA, HAS_BUG_NUMBER,IMPRONONCABLE_2,MURPHY_DRUGS_REL8 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 2 Oct 2008 18:40:43 +0000 Received: from sallyv2.ics.uci.edu (sallyv2.ics.uci.edu [128.195.1.120]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m92IeeFG001815 for <1058@emacsbugs.donarmstrong.com>; Thu, 2 Oct 2008 11:40:41 -0700 Received: from mothra.ics.uci.edu (mothra.ics.uci.edu [128.195.6.93]) by sallyv2.ics.uci.edu (8.13.7+Sun/8.13.7) with ESMTP id m92IeQtQ029236; Thu, 2 Oct 2008 11:40:26 -0700 (PDT) Received: (from dann@localhost) by mothra.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id m92IeOTT017793; Thu, 2 Oct 2008 11:40:24 -0700 (PDT) Date: Thu, 2 Oct 2008 11:40:24 -0700 (PDT) Message-Id: <200810021840.m92IeOTT017793@mothra.ics.uci.edu> From: Dan Nicolaescu To: Romain Francoise Cc: Stefan Monnier , 1058@debbugs.gnu.org, trentbuck@gmail.com Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <87myhmdgr8.fsf@elegiac.orebokech.com> In-Reply-To: <87myhmdgr8.fsf@elegiac.orebokech.com> (Romain Francoise's message of "Thu, 02 Oct 2008 19:54:51 +0200") Lines: 73 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: m92IeQtQ029236 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=-1.363, required 5, autolearn=disabled, ALL_TRUSTED -1.44, TW_RG 0.08) X-ICS-MailScanner-From: dann@mothra.ics.uci.edu Romain Francoise writes: > Here's version one of a patch for this, please let me know what you > think. Looks good to me (assuming it works), I found some nits: > @@ -1224,7 +1224,8 @@ opening the first frame (e.g. open a connection to an X server).") > ;; processing all command line arguments to allow e.g. `server-name' > ;; to be changed before the server starts. > (when (daemonp) > - (server-start)) > + (server-start) > + (daemon-initialized)) Maybe "notify-daemon-initialized"? > ;; Run emacs-session-restore (session management) if started by > ;; the session manager and we have a session manager connection. > diff --git a/src/emacs.c b/src/emacs.c > index f94d2d3..d4d16b7 100644 > --- a/src/emacs.c > +++ b/src/emacs.c > @@ -235,6 +235,13 @@ int noninteractive1; > /* Nonzero means Emacs was started as a daemon. */ > int is_daemon = 0; > > +/* Set nonzero after the daemon has finished initializing. */ > +int daemon_initialized = 0; Make it a static inside the only user? > +/* Pipe used to send exit notification to the daemon parent at > + startup. */ > +int daemon_pipe[2]; > + > /* Save argv and argc. */ > char **initial_argv; > int initial_argc; > @@ -1074,16 +1081,56 @@ main (int argc, char **argv) > if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)) > { > #ifndef DOS_NT > - pid_t f = fork (); > + pid_t f; > int nfd; > + > + /* Start as a daemon: fork a new child process which will run the > + rest of the initialization code, then exit. The child runs everything, not only the initialization. Maybe say "exit in order to detach from the terminal" or some such? > +DEFUN ("daemon-initialized", Fdaemon_initialized, Sdaemon_initialized, 0, 0, 0, > + doc: /* Mark the Emacs daemon as being initialized. */) > + () > +{ > + if (is_daemon) > + { > + if (! daemon_initialized) > + { > + /* Closing the pipe will notify the parent that it can exit. */ > + close (daemon_pipe[1]); > + daemon_initialized = 1; > + } else error ("Can only do this once"); BTW, ideally the parent would exit when it detects that the server is started, but that's much more complicated to implement... From monnier@IRO.UMontreal.CA Thu Oct 2 14:32:37 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.3 required=4.0 tests=AWL,BAYES_00,FOURLA, HAS_BUG_NUMBER,MURPHY_DRUGS_REL8 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 2 Oct 2008 21:32:37 +0000 Received: from pruche.dit.umontreal.ca (pruche.dit.umontreal.ca [132.204.246.22]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m92LWYJ9011433 for <1058@emacsbugs.donarmstrong.com>; Thu, 2 Oct 2008 14:32:35 -0700 Received: from ceviche.home (vpn-132-204-232-44.acd.umontreal.ca [132.204.232.44]) by pruche.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id m92LX4km024127; Thu, 2 Oct 2008 17:33:04 -0400 Received: by ceviche.home (Postfix, from userid 20848) id 76B71B4283; Thu, 2 Oct 2008 17:32:32 -0400 (EDT) From: Stefan Monnier To: Dan Nicolaescu Cc: 1058@debbugs.gnu.org, Romain Francoise , trentbuck@gmail.com Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Message-ID: References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <200810021726.m92HQcTQ017644@mothra.ics.uci.edu> Date: Thu, 02 Oct 2008 17:32:32 -0400 In-Reply-To: <200810021726.m92HQcTQ017644@mothra.ics.uci.edu> (Dan Nicolaescu's message of "Thu, 2 Oct 2008 10:26:38 -0700 (PDT)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV3117=0 >> I could accept a similar patch, maybe, but first I need to understand >> why/where we currently "detach" so early. > Where? in emacs.c:main, look for: > if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)) > { > #ifndef DOS_NT > pid_t f = fork (); Oh, thanks. I somehow overlooked it. > - in order to not make detaching an elisp function, and have to deal > with users trying to call it from different contexts > - the `fork' call for detaching needs to happen before some of the > initialization is run (although after my 2008-09-28 change it might be > possible to push it later), and also before .emacs is run and before > the server is started. I see what you mean. But I think forking so early is wrong: all the --eval and .emacs processing should take place "in the foreground" with input/output from stdin/stdout (like --batch). That means that detaching needs indeed to be done late if we want to do it right. Of course, that means it's more difficult to implement since it can be called in many more different contexts (we can/should reject most of them, but we still need to test/detect the undesirable ones). I see 3 different solutions: 1 - Someone fixes the code so as to do it right. 2 - we don't touch anything for now postpone the fix to 23.2. 3 - we drop the `fork' for now (so it doesn't behave like an actual daemon, more like a --batch); waiting for a `daemonize' Elisp function to be added in 23.2. I'm not sure if 1 can be done in a way appropriate for 23.1. What happens to messages resulting from executing .emacs in solution nb 2 are they sent to stdout or are they silently dropped? Stefan PS: Currently "emacs --daemon" doesn't do anything for me: it immediately (as in "I've never seen Emacs start or stop so fast") returns with no output and no remaining process. From dann@mothra.ics.uci.edu Thu Oct 2 15:34:57 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.5 required=4.0 tests=AWL,BAYES_00,FOURLA, HAS_BUG_NUMBER,MURPHY_DRUGS_REL8 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 2 Oct 2008 22:34:57 +0000 Received: from sallyv2.ics.uci.edu (sallyv2.ics.uci.edu [128.195.1.120]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m92MYsKc026208 for <1058@emacsbugs.donarmstrong.com>; Thu, 2 Oct 2008 15:34:55 -0700 Received: from mothra.ics.uci.edu (mothra.ics.uci.edu [128.195.6.93]) by sallyv2.ics.uci.edu (8.13.7+Sun/8.13.7) with ESMTP id m92MYhkn027014; Thu, 2 Oct 2008 15:34:43 -0700 (PDT) Received: (from dann@localhost) by mothra.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id m92MYgYp018688; Thu, 2 Oct 2008 15:34:42 -0700 (PDT) Date: Thu, 2 Oct 2008 15:34:42 -0700 (PDT) Message-Id: <200810022234.m92MYgYp018688@mothra.ics.uci.edu> From: Dan Nicolaescu To: Stefan Monnier Cc: 1058@debbugs.gnu.org, trentbuck@gmail.com, Romain Francoise Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <200810021726.m92HQcTQ017644@mothra.ics.uci.edu> Lines: 52 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: m92MYhkn027014 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=-1.44, required 5, autolearn=disabled, ALL_TRUSTED -1.44) X-ICS-MailScanner-From: dann@mothra.ics.uci.edu Stefan Monnier writes: > > - in order to not make detaching an elisp function, and have to deal > > with users trying to call it from different contexts > > - the `fork' call for detaching needs to happen before some of the > > initialization is run (although after my 2008-09-28 change it might be > > possible to push it later), and also before .emacs is run and before > > the server is started. > > I see what you mean. But I think forking so early is wrong: all > the --eval and .emacs processing should take place "in the foreground" > with input/output from stdin/stdout (like --batch). Is that desirable? We seem to be looking at this from different points of view. I want the daemon to start the server early, and that should be the only way to interact with it. You want to have a full blown emacs until the server is started... IMHO if someone's .emacs wants to chat during startup, then he needs to fix his .emacs if he wants to use --daemon. Chatty deamons are evil (or devils?). :-) > That means that detaching needs indeed to be done late if we want to do > it right. Of course, that means it's more difficult to implement since > it can be called in many more different contexts (we can/should reject > most of them, but we still need to test/detect the undesirable ones). Looking at it again, it should not be too bad, tedious, but not complicated. > I see 3 different solutions: > 1 - Someone fixes the code so as to do it right. > 2 - we don't touch anything for now postpone the fix to 23.2. > 3 - we drop the `fork' for now (so it doesn't behave like an actual > daemon, more like a --batch); waiting for a `daemonize' Elisp > function to be added in 23.2. > > I'm not sure if 1 can be done in a way appropriate for 23.1. Depending on what the definition if "right" is... If it means enabling interaction before detaching, then you might be right (haven't checked). If it means the patch that Romain posted, that should be fine to go in now. > What happens to messages resulting from executing .emacs in solution nb > 2 are they sent to stdout or are they silently dropped? deamon's stdin/stdout/stderr go to /dev/null. > PS: Currently "emacs --daemon" doesn't do anything for me: it > immediately (as in "I've never seen Emacs start or stop so fast") > returns with no output and no remaining process. How about "emacs -Q --daemon" ? Is this CVS HEAD, or your famous patched tree? From trentbuck@gmail.com Thu Oct 2 15:42:27 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.9 required=4.0 tests=BAYES_00,FOURLA, HAS_BUG_NUMBER,MURPHY_DRUGS_REL8 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 2 Oct 2008 22:42:27 +0000 Received: from rv-out-0506.google.com (rv-out-0506.google.com [209.85.198.236]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m92MgOXm028557 for <1058@emacsbugs.donarmstrong.com>; Thu, 2 Oct 2008 15:42:25 -0700 Received: by rv-out-0506.google.com with SMTP id k40so1370427rvb.1 for <1058@emacsbugs.donarmstrong.com>; Thu, 02 Oct 2008 15:42:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=h1nnLPylghGYToYi2weCH98oF0f+0tXYHUxKNz5e9qM=; b=EfDYLWIiCxVwj1DE6LNY2xVygwV0pBY+/E2kFSgb1J10rHtYL6hcbJYQC4SYDii9fl ZDYTVDWFAww/JpNwODdDr/0E9Cyu80PfLA8KYrGB61yF8kwDUJGM8xaqCFw+OyJf6Sg1 iGJhV743lfHRNcbi3gGYevHMO8pkqGTpT7v1o= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=GtrkD7EXSI/zFId4EZ1mqGscH7qGmkyjesLUIwOM4nLfa2wjYjhGMCAnSRwaTS6H4g hT1dXcdUsMS7zs8GzCjBWwfd1ESGEcX19V6a1Cylk5e/92fJdtRPBwO5OLhb1ZWl9MEN OphGYPSrP73wSwLBUlMTMMa/J6xHV2O6J8uwA= Received: by 10.114.13.10 with SMTP id 10mr335700wam.106.1222987344123; Thu, 02 Oct 2008 15:42:24 -0700 (PDT) Received: from localhost (ppp121-44-196-87.lns10.mel4.internode.on.net [121.44.196.87]) by mx.google.com with ESMTPS id l30sm7918432waf.25.2008.10.02.15.42.22 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 02 Oct 2008 15:42:23 -0700 (PDT) Date: Fri, 3 Oct 2008 08:42:38 +1000 From: "Trent W. Buck" To: Stefan Monnier Cc: Dan Nicolaescu , 1058@debbugs.gnu.org, Romain Francoise Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Message-ID: <20081002224236.GA29467@Clio.twb.ath.cx> References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <200810021726.m92HQcTQ017644@mothra.ics.uci.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) On Thu, Oct 02, 2008 at 05:32:32PM -0400, Stefan Monnier wrote: > >> I could accept a similar patch, maybe, but first I need to understand > >> why/where we currently "detach" so early. > > > Where? in emacs.c:main, look for: > > if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)) > > { > > #ifndef DOS_NT > > pid_t f = fork (); > > Oh, thanks. I somehow overlooked it. > > > - in order to not make detaching an elisp function, and have to > > deal with users trying to call it from different contexts - the > > `fork' call for detaching needs to happen before some of the > > initialization is run (although after my 2008-09-28 change it > > might be possible to push it later), and also before .emacs is run > > and before the server is started. > > I see what you mean. But I think forking so early is wrong: all > the --eval and .emacs processing should take place "in the foreground" > with input/output from stdin/stdout (like --batch). What happens if .emacs asks questions? Does 'emacs --daemon' require a terminal? Also, I'm currently using the following test to check whether the running Emacs supports --daemon. If you break it, please make some other test work. emacs --batch -q --no-site-file --daemon &>/dev/null From trentbuck@gmail.com Thu Oct 2 15:46:00 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.9 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER, MURPHY_DRUGS_REL8 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 2 Oct 2008 22:46:00 +0000 Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.179]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m92Mjvki029721 for <1058@emacsbugs.donarmstrong.com>; Thu, 2 Oct 2008 15:45:58 -0700 Received: by wa-out-1112.google.com with SMTP id j40so830046wah.1 for <1058@emacsbugs.donarmstrong.com>; Thu, 02 Oct 2008 15:45:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=NmeEt44fSmG74YntgU6Tferxbp8X/9J/GRHELYqYT34=; b=jUoERd9grgyNE0e7irVSJDL/sHOafUvLU17borQSD2VhovbWfuskobjVYmjvcahVuI 8N7seSWYFgl2BNcx8uqkrvA25gquhnKrGcCKfe25LyB4Ls68aECQuwURN4efSzPV4vg2 BC3tVY6mx2lD9nTKbP4lztQYsD5So5WI2rWQY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=IwYpsVqs1sxPF2OMKQJ/DYKhPL/JxIgecnlHW4V2Gf2KI10VSCsEisLp/GHixs07gc T9LGE5jzTa0TwgJRCBAJLGdE1bb/x9BZS1VggciCTOJuuyOd5izjlRmt7V214LvTFDyH PRONi7tu1d8OOIh1OWkWmRJ+OS6IdmL1R8/Hk= Received: by 10.114.179.1 with SMTP id b1mr389687waf.1.1222987557220; Thu, 02 Oct 2008 15:45:57 -0700 (PDT) Received: from localhost (ppp121-44-196-87.lns10.mel4.internode.on.net [121.44.196.87]) by mx.google.com with ESMTPS id n30sm7958038wag.13.2008.10.02.15.45.55 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 02 Oct 2008 15:45:56 -0700 (PDT) Date: Fri, 3 Oct 2008 08:46:11 +1000 From: "Trent W. Buck" To: Dan Nicolaescu Cc: Stefan Monnier , 1058@debbugs.gnu.org, Romain Francoise Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Message-ID: <20081002224609.GB29467@Clio.twb.ath.cx> References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <200810021726.m92HQcTQ017644@mothra.ics.uci.edu> <200810022234.m92MYgYp018688@mothra.ics.uci.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200810022234.m92MYgYp018688@mothra.ics.uci.edu> User-Agent: Mutt/1.5.18 (2008-05-17) On Thu, Oct 02, 2008 at 03:34:42PM -0700, Dan Nicolaescu wrote: > Depending on what the definition if "right" is... If it means enabling > interaction before detaching, then you might be right (haven't checked). > If it means the patch that Romain posted, that should be fine to go in > now. Currently if you "emacs --daemon" and .emacs contains a syntax error, you don't get any warning of this. Currently if you do something like "emacs --daemon -f irc -f gnus", any minibuffer prompts will appear when you connect a client. I think I'd prefer the first to change and the latter to stay the same, but I haven't had any coffee yet. From monnier@iro.umontreal.ca Thu Oct 2 18:12:12 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-5.3 required=4.0 tests=AWL,BAYES_00,FOURLA, HAS_BUG_NUMBER,MURPHY_DRUGS_REL8 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 3 Oct 2008 01:12:12 +0000 Received: from ironport2-out.teksavvy.com (ironport2-out.pppoe.ca [206.248.154.182]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m931C89f000845 for <1058@emacsbugs.donarmstrong.com>; Thu, 2 Oct 2008 18:12:10 -0700 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqAEAMcN5UjO+KVj/2dsb2JhbACBcbsYgWiBBYIb X-IronPort-AV: E=Sophos;i="4.33,353,1220241600"; d="scan'208";a="27908722" Received: from 206-248-165-99.dsl.teksavvy.com (HELO pastel.home) ([206.248.165.99]) by ironport2-out.teksavvy.com with ESMTP; 02 Oct 2008 21:12:02 -0400 Received: by pastel.home (Postfix, from userid 20848) id 90F5C80D0; Thu, 2 Oct 2008 21:12:02 -0400 (EDT) From: Stefan Monnier To: Dan Nicolaescu Cc: 1058@debbugs.gnu.org, trentbuck@gmail.com, Romain Francoise Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Message-ID: References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <200810021726.m92HQcTQ017644@mothra.ics.uci.edu> <200810022234.m92MYgYp018688@mothra.ics.uci.edu> Date: Thu, 02 Oct 2008 21:12:02 -0400 In-Reply-To: <200810022234.m92MYgYp018688@mothra.ics.uci.edu> (Dan Nicolaescu's message of "Thu, 2 Oct 2008 15:34:42 -0700 (PDT)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii > Is that desirable? We seem to be looking at this from different points > of view. I want the daemon to start the server early, and that should > be the only way to interact with it. You want to have a full blown > emacs until the server is started... I think we agree: I also want a full blown Emacs until the server is started. But I also want to run some Elisp code (especially the .emacs) before the server is started. > IMHO if someone's .emacs wants to chat during startup, then he needs to > fix his .emacs if he wants to use --daemon. Agreed. > Chatty deamons are evil (or devils?). :-) But daemons which fork before detecting if there's an error somewhere and hence don't report such errors are even more evil. >> That means that detaching needs indeed to be done late if we want to do >> it right. Of course, that means it's more difficult to implement since >> it can be called in many more different contexts (we can/should reject >> most of them, but we still need to test/detect the undesirable ones). > Looking at it again, it should not be too bad, tedious, but not complicated. Could be. > Depending on what the definition if "right" is... If it means enabling > interaction before detaching, then you might be right (haven't checked). > If it means the patch that Romain posted, that should be fine to go in > now. I can't tell yet whether Romain's patch does the right thing: do errors in .emacs get properly reported to stdout? >> What happens to messages resulting from executing .emacs in solution nb >> 2 are they sent to stdout or are they silently dropped? > deamon's stdin/stdout/stderr go to /dev/null. That's mostly OK, but not before the .emacs (and --eval) get processed. >> PS: Currently "emacs --daemon" doesn't do anything for me: it >> immediately (as in "I've never seen Emacs start or stop so fast") >> returns with no output and no remaining process. > How about "emacs -Q --daemon" ? Same thing. > Is this CVS HEAD, or your famous patched tree? ;-) CVS HEAD. Stefan From dann@mothra.ics.uci.edu Thu Oct 2 21:52:18 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.6 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER, MURPHY_DRUGS_REL8 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 3 Oct 2008 04:52:18 +0000 Received: from sallyv2.ics.uci.edu (sallyv2.ics.uci.edu [128.195.1.120]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m934qFXQ021911 for <1058@emacsbugs.donarmstrong.com>; Thu, 2 Oct 2008 21:52:16 -0700 Received: from mothra.ics.uci.edu (mothra.ics.uci.edu [128.195.6.93]) by sallyv2.ics.uci.edu (8.13.7+Sun/8.13.7) with ESMTP id m934q4m1002462; Thu, 2 Oct 2008 21:52:04 -0700 (PDT) Received: (from dann@localhost) by mothra.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id m934q2YN021262; Thu, 2 Oct 2008 21:52:02 -0700 (PDT) Date: Thu, 2 Oct 2008 21:52:02 -0700 (PDT) Message-Id: <200810030452.m934q2YN021262@mothra.ics.uci.edu> From: Dan Nicolaescu To: Stefan Monnier Cc: 1058@debbugs.gnu.org, trentbuck@gmail.com, Romain Francoise Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <200810021726.m92HQcTQ017644@mothra.ics.uci.edu> <200810022234.m92MYgYp018688@mothra.ics.uci.edu> In-Reply-To: (Stefan Monnier's message of "Thu, 02 Oct 2008 21:12:02 -0400") Lines: 35 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: m934q4m1002462 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=-1.44, required 5, autolearn=disabled, ALL_TRUSTED -1.44) X-ICS-MailScanner-From: dann@mothra.ics.uci.edu Stefan Monnier writes: > > Depending on what the definition if "right" is... If it means enabling > > interaction before detaching, then you might be right (haven't checked). > > If it means the patch that Romain posted, that should be fine to go in > > now. > > I can't tell yet whether Romain's patch does the right thing: do errors > in .emacs get properly reported to stdout? Romain's patch solves the other problem: the fact that the initial parent process returns before the server is started, so that emacs --daemon && emacsclient -c does not work. I am not sure if moving the code that forks/disconnects from the terminal later solves the reporting errors problem. (and I can't really try at the moment). > >> What happens to messages resulting from executing .emacs in solution nb > >> 2 are they sent to stdout or are they silently dropped? > > deamon's stdin/stdout/stderr go to /dev/null. > > That's mostly OK, but not before the .emacs (and --eval) get processed. > > >> PS: Currently "emacs --daemon" doesn't do anything for me: it > >> immediately (as in "I've never seen Emacs start or stop so fast") > >> returns with no output and no remaining process. > > > How about "emacs -Q --daemon" ? > > Same thing. Hmm, you mean that after "emacs -Q --daemon" if you look with ps there's no emacs process at all? And "emacsclient -t" does not connect to it? From monnier@iro.umontreal.ca Fri Oct 3 06:00:48 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-5.4 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 3 Oct 2008 13:00:48 +0000 Received: from ironport2-out.teksavvy.com (ironport2-out.teksavvy.com [206.248.154.182]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m93D0iMZ014114 for <1058@emacsbugs.donarmstrong.com>; Fri, 3 Oct 2008 06:00:46 -0700 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqAEAPOz5UjO+KVj/2dsb2JhbACBcbomgWiBBYIb X-IronPort-AV: E=Sophos;i="4.33,356,1220241600"; d="scan'208";a="27936954" Received: from 206-248-165-99.dsl.teksavvy.com (HELO pastel.home) ([206.248.165.99]) by ironport2-out.teksavvy.com with ESMTP; 03 Oct 2008 09:00:39 -0400 Received: by pastel.home (Postfix, from userid 20848) id 2381C80D0; Fri, 3 Oct 2008 09:00:39 -0400 (EDT) From: Stefan Monnier To: Dan Nicolaescu Cc: 1058@debbugs.gnu.org, trentbuck@gmail.com, Romain Francoise Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Message-ID: References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <200810021726.m92HQcTQ017644@mothra.ics.uci.edu> <200810022234.m92MYgYp018688@mothra.ics.uci.edu> <200810030452.m934q2YN021262@mothra.ics.uci.edu> Date: Fri, 03 Oct 2008 09:00:39 -0400 In-Reply-To: <200810030452.m934q2YN021262@mothra.ics.uci.edu> (Dan Nicolaescu's message of "Thu, 2 Oct 2008 21:52:02 -0700 (PDT)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii > Hmm, you mean that after "emacs -Q --daemon" if you look with ps there's > no emacs process at all? And "emacsclient -t" does not connect to it? Exactly. But I haven't investigated further yet. Most likely it's a simple error somewhere that causes Emacs to exit but the message is throw away. That's exactly for these kinds of reasons that it's important to keep sending messages to stdout at least until after the server is started: otherwise debugging is a pain. Stefan From dann@mothra.ics.uci.edu Fri Oct 3 10:44:40 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.6 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 3 Oct 2008 17:44:40 +0000 Received: from sallyv2.ics.uci.edu (sallyv2.ics.uci.edu [128.195.1.120]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m93Hibjd020544 for <1058@emacsbugs.donarmstrong.com>; Fri, 3 Oct 2008 10:44:38 -0700 Received: from mothra.ics.uci.edu (mothra.ics.uci.edu [128.195.6.93]) by sallyv2.ics.uci.edu (8.13.7+Sun/8.13.7) with ESMTP id m93HiBDc027328; Fri, 3 Oct 2008 10:44:11 -0700 (PDT) Received: (from dann@localhost) by mothra.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id m93HiAhf023661; Fri, 3 Oct 2008 10:44:10 -0700 (PDT) Date: Fri, 3 Oct 2008 10:44:10 -0700 (PDT) Message-Id: <200810031744.m93HiAhf023661@mothra.ics.uci.edu> From: Dan Nicolaescu To: Stefan Monnier Cc: 1058@debbugs.gnu.org, trentbuck@gmail.com, Romain Francoise Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <200810021726.m92HQcTQ017644@mothra.ics.uci.edu> <200810022234.m92MYgYp018688@mothra.ics.uci.edu> <200810030452.m934q2YN021262@mothra.ics.uci.edu> In-Reply-To: (Stefan Monnier's message of "Fri, 03 Oct 2008 09:00:39 -0400") Lines: 30 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: m93HiBDc027328 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=-1.44, required 5, autolearn=disabled, ALL_TRUSTED -1.44) X-ICS-MailScanner-From: dann@mothra.ics.uci.edu Stefan Monnier writes: > > Hmm, you mean that after "emacs -Q --daemon" if you look with ps there's > > no emacs process at all? And "emacsclient -t" does not connect to it? > > Exactly. But I haven't investigated further yet. Most likely it's > a simple error somewhere that causes Emacs to exit but the message is > throw away. If this is with an up to date pristine tree, then please debug it, it's very bad. I have not seen anything like this on any of the systems that I use. > That's exactly for these kinds of reasons that it's important to > keep sending messages to stdout at least until after the server is > started: otherwise debugging is a pain. Well, but that is not how things work when using emacs normally (i.e. interactive session without --daemon). - Errors in .emacs are shown in the *Messages* buffer. That still happens with --daemon. - Interactive questions (like a y-or-n-p in .emacs) get asked in the first emacs frame that appears. I think we agree that something like this is ill formed for --daemon. It would be nice if it failed more graciously, but I am not sure it can be easily done within the current constraints. BTW, the splash screen covers that *Messages* buffer quite fast, so errors at startup are not displayed for too long ... From dann@mothra.ics.uci.edu Mon Oct 6 14:00:01 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-8.2 required=4.0 tests=AWL,BAYES_00,FOURLA, FVGT_m_MULTI_ODD,HAS_BUG_NUMBER,MURPHY_DRUGS_REL8,X_DEBBUGS_NO_ACK autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 6 Oct 2008 21:00:01 +0000 Received: from sallyv2.ics.uci.edu (sallyv2.ics.uci.edu [128.195.1.120]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m96KxvtR014199 for <1058@emacsbugs.donarmstrong.com>; Mon, 6 Oct 2008 13:59:58 -0700 Received: from mothra.ics.uci.edu (mothra.ics.uci.edu [128.195.6.93]) by sallyv2.ics.uci.edu (8.13.7+Sun/8.13.7) with ESMTP id m96KxbfV026377; Mon, 6 Oct 2008 13:59:39 -0700 (PDT) Received: (from dann@localhost) by mothra.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id m96KxaXM004646; Mon, 6 Oct 2008 13:59:36 -0700 (PDT) Date: Mon, 6 Oct 2008 13:59:36 -0700 (PDT) Message-Id: <200810062059.m96KxaXM004646@mothra.ics.uci.edu> From: Dan Nicolaescu To: Romain Francoise Cc: 1058@debbugs.gnu.org, trentbuck@gmail.com Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <87myhmdgr8.fsf@elegiac.orebokech.com> X-Debbugs-No-Ack: yes In-Reply-To: <87myhmdgr8.fsf@elegiac.orebokech.com> (Romain Francoise's message of "Thu, 02 Oct 2008 19:54:51 +0200") Lines: 168 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: m96KxbfV026377 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=-0.263, required 5, autolearn=disabled, ALL_TRUSTED -1.44, FM_MULTI_ODD2 1.10, TW_RG 0.08) X-ICS-MailScanner-From: dann@mothra.ics.uci.edu Romain Francoise writes: > Here's version one of a patch for this, please let me know what you > think. Here's a version based on your code that also moves detaching from the terminal later. emacs --daemon && emacsclient -c works. Errors in ~/.emacs show up in the *Messages* buffer (as they do when starting up normally). Only lightly tested. Looking at the patch again, I there aren't any new features here, so it can go in as a bug fix. Index: lisp/startup.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/startup.el,v retrieving revision 1.508 diff -u -3 -p -r1.508 startup.el --- lisp/startup.el 6 Oct 2008 16:16:30 -0000 1.508 +++ lisp/startup.el 6 Oct 2008 20:18:41 -0000 @@ -1219,7 +1219,7 @@ opening the first frame (e.g. open a con ;; processing all command line arguments to allow e.g. `server-name' ;; to be changed before the server starts. (when (daemonp) - (server-start)) + (daemon-detach-and-start-server)) ;; Run emacs-session-restore (session management) if started by ;; the session manager and we have a session manager connection. Index: src/emacs.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/emacs.c,v retrieving revision 1.448 diff -u -3 -p -r1.448 emacs.c --- src/emacs.c 6 Oct 2008 16:16:56 -0000 1.448 +++ src/emacs.c 6 Oct 2008 20:18:41 -0000 @@ -238,6 +238,10 @@ int noninteractive1; /* Nonzero means Emacs was started as a daemon. */ int is_daemon = 0; +/* Pipe used to send exit notification to the daemon parent at + startup. */ +static int daemon_pipe[2]; + /* Save argv and argc. */ char **initial_argv; int initial_argc; @@ -1078,25 +1082,7 @@ main (int argc, char **argv) if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)) { #ifndef DOS_NT - pid_t f = fork (); - int nfd; - if (f > 0) - exit (0); - if (f < 0) - { - fprintf (stderr, "Cannot fork!\n"); - exit (1); - } - - nfd = open ("/dev/null", O_RDWR); - dup2 (nfd, 0); - dup2 (nfd, 1); - dup2 (nfd, 2); - close (nfd); is_daemon = 1; -#ifdef HAVE_SETSID - setsid(); -#endif #else /* DOS_NT */ fprintf (stderr, "This platform does not support the -daemon flag.\n"); exit (1); @@ -2393,6 +2379,87 @@ DEFUN ("daemonp", Fdaemonp, Sdaemonp, 0, return is_daemon ? Qt : Qnil; } + +DEFUN ("daemon-detach-and-start-server", Fdaemon_detach_and_start_server, Sdaemon_detach_and_start_server, 0, 0, 0, + doc: /* Detach from terminal and start the server */) + () +{ + static char daemon_initialized = 0; + pid_t f; + int nfd; + + if (!is_daemon) + error ("This function can only be called if emacs is run as a daemon"); + + if (daemon_initialized) + error ("The daemon has already been initialized"); + + if (NILP (Vafter_init_time)) + error ("This function can only be called after loading the init files"); + + /* Start as a daemon: fork a new child process which will run the + rest of the initialization code, then exit. + + We want to avoid exiting before the server socket is ready, so + use a pipe for synchronization. The parent waits for the child + to close its end of the pipe (using `daemon-initialized') + before exiting. */ + if (pipe (daemon_pipe) == -1) + { + fprintf (stderr, "Cannot pipe!\n"); + exit (1); + } + + f = fork (); + if (f > 0) + { + int retval; + char buf[1]; + + /* Close unused writing end of the pipe. */ + close (daemon_pipe[1]); + + /* Just wait for the child to close its end of the pipe. */ + do + { + retval = read (daemon_pipe[0], &buf, 1); + } + while (retval == -1 && errno == EINTR); + + if (retval < 0) + { + fprintf (stderr, "Error reading status from child\n"); + exit (1); + } + + close (daemon_pipe[0]); + exit (0); + } + if (f < 0) + { + fprintf (stderr, "Cannot fork!\n"); + exit (1); + } + + /* Close unused reading end of the pipe. */ + close (daemon_pipe[0]); + + nfd = open ("/dev/null", O_RDWR); + dup2 (nfd, 0); + dup2 (nfd, 1); + dup2 (nfd, 2); + close (nfd); + is_daemon = 1; +#ifdef HAVE_SETSID + setsid(); +#endif + call0 (intern ("server-start")); + + /* Closing the pipe will notify the parent that it can exit. */ + close (daemon_pipe[1]); + daemon_initialized = 1; +} + void syms_of_emacs () { @@ -2412,6 +2479,7 @@ syms_of_emacs () defsubr (&Sinvocation_name); defsubr (&Sinvocation_directory); defsubr (&Sdaemonp); + defsubr (&Sdaemon_detach_and_start_server); DEFVAR_LISP ("command-line-args", &Vcommand_line_args, doc: /* Args passed by shell to Emacs, as a list of strings. From monnier@IRO.UMontreal.CA Tue Oct 7 07:26:53 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-6.4 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 7 Oct 2008 14:26:53 +0000 Received: from pruche.dit.umontreal.ca (pruche.dit.umontreal.ca [132.204.246.22]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m97EQm3g016341 for <1058@emacsbugs.donarmstrong.com>; Tue, 7 Oct 2008 07:26:50 -0700 Received: from alfajor.home (vpn-132-204-232-40.acd.umontreal.ca [132.204.232.40]) by pruche.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id m97ERInW027135; Tue, 7 Oct 2008 10:27:18 -0400 Received: by alfajor.home (Postfix, from userid 20848) id 74E501C54B; Tue, 7 Oct 2008 10:26:46 -0400 (EDT) From: Stefan Monnier To: Dan Nicolaescu Cc: 1058@debbugs.gnu.org, Romain Francoise , trentbuck@gmail.com Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Message-ID: References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <87myhmdgr8.fsf@elegiac.orebokech.com> <200810062059.m96KxaXM004646@mothra.ics.uci.edu> Date: Tue, 07 Oct 2008 10:26:46 -0400 In-Reply-To: <200810062059.m96KxaXM004646@mothra.ics.uci.edu> (Dan Nicolaescu's message of "Mon, 6 Oct 2008 13:59:36 -0700 (PDT)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV3119=0 > Errors in ~/.emacs show up in the *Messages* buffer (as they do when > starting up normally). But is the *Messages* buffer automatically displayed (as is done when starting up normally)? This is the main reason why I think that .emacs messages should go to stdout. Especially since the error might even be something that breaks the server, so you can't connect later on to take a look at the *Messages* buffer. Stefan From dann@mothra.ics.uci.edu Tue Oct 7 08:32:09 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-8.3 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER, MURPHY_DRUGS_REL8,X_DEBBUGS_NO_ACK autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 7 Oct 2008 15:32:09 +0000 Received: from barrelv2.ics.uci.edu (barrelv2.ics.uci.edu [128.195.1.114]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m97FW08e032614 for <1058@emacsbugs.donarmstrong.com>; Tue, 7 Oct 2008 08:32:01 -0700 Received: from mothra.ics.uci.edu (mothra.ics.uci.edu [128.195.6.93]) by barrelv2.ics.uci.edu (8.13.7+Sun/8.13.7) with ESMTP id m97FVmJD013365; Tue, 7 Oct 2008 08:31:49 -0700 (PDT) Received: (from dann@localhost) by mothra.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id m97FVlPt007507; Tue, 7 Oct 2008 08:31:47 -0700 (PDT) Date: Tue, 7 Oct 2008 08:31:47 -0700 (PDT) Message-Id: <200810071531.m97FVlPt007507@mothra.ics.uci.edu> From: Dan Nicolaescu To: Stefan Monnier Cc: 1058@debbugs.gnu.org, Romain Francoise , trentbuck@gmail.com Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <87myhmdgr8.fsf@elegiac.orebokech.com> <200810062059.m96KxaXM004646@mothra.ics.uci.edu> X-Debbugs-No-Ack: yes In-Reply-To: (Stefan Monnier's message of "Tue, 07 Oct 2008 10:26:46 -0400") Lines: 56 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: m97FVmJD013365 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=-1.44, required 5, autolearn=disabled, ALL_TRUSTED -1.44) X-ICS-MailScanner-From: dann@mothra.ics.uci.edu Stefan Monnier writes: > > Errors in ~/.emacs show up in the *Messages* buffer (as they do when > > starting up normally). There are multiple issues being discussed here. 1. > But is the *Messages* buffer automatically displayed (as is done when > starting up normally)? Not yet, but it just takes one extra `if' to do it: --- server.el.~1.168.~ 2008-09-24 17:34:59.000000000 -0700 +++ server.el 2008-10-07 08:09:16.000000000 -0700 @@ -606,7 +606,9 @@ Server mode runs a process that accepts (process-put proc 'terminal (frame-terminal frame)) ;; Display *scratch* by default. - (switch-to-buffer (get-buffer-create "*scratch*") 'norecord) + (switch-to-buffer + (get-buffer-create + (if init-file-had-error "*Messages*" "*scratch*")) 'norecord) ;; Reply with our pid. (server-send-string proc (concat "-emacs-pid " 2. During the normal interactive startup the splash screen nowadays covers the *Messages* buffer too fast, so the user can miss the error. I should file a bug about this... > This is the main reason why I think that .emacs messages should go > to stdout. 3. There's no code in emacs now that can do that for interactive sessions, and when I looked at this it did not look that it can be a small change acceptable during the feature freeze. The `noninteractive' code has it's claws in too many places. > Especially since the error might even be something that breaks the > server, so you can't connect later on to take a look at the > *Messages* buffer. 5. Making the output go to stdout does not avoid this problem at all, it reduces the possibility somewhat, but it does not avoid it. 6. But my original code to start the server early minimizes the window of opportunity for problems in starting the server, the more .emacs, default.el, site-start.el code you run, the more potential for problems in starting the server later. Yes, starting the server early was entirely intentional. 7. This bug report is about something else: emacs --daemon && emacsclient -c not working. Romain's patch looks good, it does not add features, it's just a bug fix, so I don't see any reason it cannot go in right now. From romain@orebokech.com Tue Oct 7 11:45:26 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-7.1 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER, MURPHY_DRUGS_REL8 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 7 Oct 2008 18:45:26 +0000 Received: from smtp7-g19.free.fr (smtp7-g19.free.fr [212.27.42.64]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m97IjNf9015893 for <1058@emacsbugs.donarmstrong.com>; Tue, 7 Oct 2008 11:45:24 -0700 Received: from smtp7-g19.free.fr (localhost [127.0.0.1]) by smtp7-g19.free.fr (Postfix) with ESMTP id 603DFB01BD; Tue, 7 Oct 2008 20:45:22 +0200 (CEST) Received: from elegiac.orebokech.com (home.orebokech.com [82.67.41.165]) by smtp7-g19.free.fr (Postfix) with ESMTP id 2A52EB017A; Tue, 7 Oct 2008 20:45:22 +0200 (CEST) Received: by elegiac.orebokech.com (Postfix, from userid 1000) id CD8C13B1B2; Tue, 7 Oct 2008 20:45:21 +0200 (CEST) From: Romain Francoise To: Dan Nicolaescu Cc: 1058@debbugs.gnu.org, trentbuck@gmail.com Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Organization: orebokech dot com References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <87myhmdgr8.fsf@elegiac.orebokech.com> <200810062059.m96KxaXM004646@mothra.ics.uci.edu> X-Face: }9mYu,e_@+e!`Z-P5kVXa3\_b:hdJ"B)ww[&=b<2=awG:GOIM (Dan Nicolaescu's message of "Mon, 6 Oct 2008 13:59:36 -0700 (PDT)") Message-ID: <87bpxwutvi.fsf@elegiac.orebokech.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Dan Nicolaescu writes: > Here's a version based on your code that also moves detaching from the > terminal later. Hmm, but the initial frame doesn't get created anyway because `is_daemon' is still set early like before, so it doesn't really change much. I'm unsure which problems this patch addresses. From dann@mothra.ics.uci.edu Tue Oct 7 12:01:56 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-8.4 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER, MURPHY_DRUGS_REL8,X_DEBBUGS_NO_ACK autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 7 Oct 2008 19:01:57 +0000 Received: from sallyv2.ics.uci.edu (sallyv2.ics.uci.edu [128.195.1.120]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m97J1rv6019874 for <1058@emacsbugs.donarmstrong.com>; Tue, 7 Oct 2008 12:01:54 -0700 Received: from mothra.ics.uci.edu (mothra.ics.uci.edu [128.195.6.93]) by sallyv2.ics.uci.edu (8.13.7+Sun/8.13.7) with ESMTP id m97J1h8n000754; Tue, 7 Oct 2008 12:01:43 -0700 (PDT) Received: (from dann@localhost) by mothra.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id m97J1hbR008344; Tue, 7 Oct 2008 12:01:43 -0700 (PDT) Date: Tue, 7 Oct 2008 12:01:43 -0700 (PDT) Message-Id: <200810071901.m97J1hbR008344@mothra.ics.uci.edu> From: Dan Nicolaescu To: Romain Francoise Cc: 1058@debbugs.gnu.org, trentbuck@gmail.com Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <87myhmdgr8.fsf@elegiac.orebokech.com> <200810062059.m96KxaXM004646@mothra.ics.uci.edu> <87bpxwutvi.fsf@elegiac.orebokech.com> X-Debbugs-No-Ack: yes In-Reply-To: <87bpxwutvi.fsf@elegiac.orebokech.com> (Romain Francoise's message of "Tue, 07 Oct 2008 20:45:21 +0200") Lines: 16 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: m97J1h8n000754 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=-1.44, required 5, autolearn=disabled, ALL_TRUSTED -1.44) X-ICS-MailScanner-From: dann@mothra.ics.uci.edu Romain Francoise writes: > Dan Nicolaescu writes: > > > Here's a version based on your code that also moves detaching from the > > terminal later. > > Hmm, but the initial frame doesn't get created anyway because Not sure why you mention that. > `is_daemon' is still set early like before, so it doesn't really > change much. I'm unsure which problems this patch addresses. It moves detaching from the terminal to later, so if emacs ever gets to use stdout/stdin durin startup, it will just work (hopefully). From trentbuck@gmail.com Tue Oct 7 16:13:02 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-7.0 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER, MURPHY_DRUGS_REL8 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 7 Oct 2008 23:13:03 +0000 Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.250]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m97NCxZ8017809 for <1058@emacsbugs.donarmstrong.com>; Tue, 7 Oct 2008 16:13:00 -0700 Received: by an-out-0708.google.com with SMTP id b20so197923ana.9 for <1058@emacsbugs.donarmstrong.com>; Tue, 07 Oct 2008 16:12:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=JQmMRFzqRaXrza6oHT5xTqMNFaN0mn8p2QmDYCZctBI=; b=aVRKBe/iCApZ2Es2W2mKhwUd77q3yc3I5H13tApX7pK9oY42jKzJKSm8jLTmpGeVol 0yxxNEdNHy08ehSFDAXXWMI/8+CbQnDHE2q7U/j9w897/YXgnFvBjuhWVUUgEQC5stPl hSxRGHZgs6h+6kTOvYWqshmA3hot6q0XFyHYc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=HuiJ8LkVANIgslB6ms2qwb7xfUBe42G434Okmi5f1A/oZRU6UAgBflOMDeb+DPEfpl 5BrsCYw40T6xqClt11LjrY4kmt3ItSfvzPd0UUfqzb714FgV48u3+W6Y5quvzrInhOEm 0eVWdBsV/TLAotwkSsx/g1vyyK4LGYzqVQ5gI= Received: by 10.100.94.14 with SMTP id r14mr732258anb.68.1223421179127; Tue, 07 Oct 2008 16:12:59 -0700 (PDT) Received: from localhost (nat064.cyber.com.au [203.7.155.64]) by mx.google.com with ESMTPS id b18sm18779932ana.5.2008.10.07.16.12.56 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 07 Oct 2008 16:12:58 -0700 (PDT) Date: Wed, 8 Oct 2008 10:13:16 +1100 From: "Trent W. Buck" To: Dan Nicolaescu Cc: Stefan Monnier , 1058@debbugs.gnu.org, Romain Francoise Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Message-ID: <20081007231314.GD2288@Clio.twb.ath.cx> References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <87myhmdgr8.fsf@elegiac.orebokech.com> <200810062059.m96KxaXM004646@mothra.ics.uci.edu> <200810071531.m97FVlPt007507@mothra.ics.uci.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200810071531.m97FVlPt007507@mothra.ics.uci.edu> User-Agent: Mutt/1.5.18 (2008-05-17) On Tue, Oct 07, 2008 at 08:31:47AM -0700, Dan Nicolaescu wrote: >> But is the *Messages* buffer automatically displayed (as is done when >> starting up normally)? > > Not yet, but it just takes one extra `if' to do it: > > --- server.el.~1.168.~ 2008-09-24 17:34:59.000000000 -0700 > +++ server.el 2008-10-07 08:09:16.000000000 -0700 > @@ -606,7 +606,9 @@ Server mode runs a process that accepts > (process-put proc 'terminal (frame-terminal frame)) > > ;; Display *scratch* by default. > - (switch-to-buffer (get-buffer-create "*scratch*") 'norecord) > + (switch-to-buffer > + (get-buffer-create > + (if init-file-had-error "*Messages*" "*scratch*")) 'norecord) > > ;; Reply with our pid. > (server-send-string proc (concat "-emacs-pid " Will this result in *Messages* being shown in all emacsclients, or only the first one? > 2. During the normal interactive startup the splash screen nowadays > covers the *Messages* buffer too fast, so the user can miss the error. > I should file a bug about this... > >> This is the main reason why I think that .emacs messages should go >> to stdout. Wouldn't it be better to address the actual issue (splash screen hides *Messages* when something went wrong) rather than side effects (*Messages* is hidden when --daemon, too)? > 7. This bug report is about something else: emacs --daemon && > emacsclient -c not working. Romain's patch looks good, it does not > add features, it's just a bug fix, so I don't see any reason it > cannot go in right now. Correct; stdout / splash screen stuff should be forked to a separate bug. From monnier@iro.umontreal.ca Tue Oct 7 19:03:25 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-5.5 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER, MURPHY_DRUGS_REL8 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 8 Oct 2008 02:03:25 +0000 Received: from ironport2-out.teksavvy.com (ironport2-out.pppoe.ca [206.248.154.182]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m9823Ljr027143 for <1058@emacsbugs.donarmstrong.com>; Tue, 7 Oct 2008 19:03:23 -0700 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AowFAEmx60jO+IH3/2dsb2JhbACBcrxngWqBBw X-IronPort-AV: E=Sophos;i="4.33,376,1220241600"; d="scan'208";a="28131503" Received: from 206-248-129-247.dsl.teksavvy.com (HELO pastel.home) ([206.248.129.247]) by ironport2-out.teksavvy.com with ESMTP; 07 Oct 2008 22:03:15 -0400 Received: by pastel.home (Postfix, from userid 20848) id 81BD68568; Tue, 7 Oct 2008 22:03:15 -0400 (EDT) From: Stefan Monnier To: "Trent W. Buck" Cc: Dan Nicolaescu , 1058@debbugs.gnu.org, Romain Francoise Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Message-ID: References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <87myhmdgr8.fsf@elegiac.orebokech.com> <200810062059.m96KxaXM004646@mothra.ics.uci.edu> <200810071531.m97FVlPt007507@mothra.ics.uci.edu> <20081007231314.GD2288@Clio.twb.ath.cx> Date: Tue, 07 Oct 2008 22:03:15 -0400 In-Reply-To: <20081007231314.GD2288@Clio.twb.ath.cx> (Trent W. Buck's message of "Wed, 8 Oct 2008 10:13:16 +1100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii >> 2. During the normal interactive startup the splash screen nowadays >> covers the *Messages* buffer too fast, so the user can miss the error. >> I should file a bug about this... >> >>> This is the main reason why I think that .emacs messages should go >>> to stdout. > Wouldn't it be better to address the actual issue (splash screen hides > *Messages* when something went wrong) rather than side effects > (*Messages* is hidden when --daemon, too)? The splash screen issue is completely separate. >> 7. This bug report is about something else: emacs --daemon && >> emacsclient -c not working. Romain's patch looks good, it does not >> add features, it's just a bug fix, so I don't see any reason it >> cannot go in right now. > Correct; stdout / splash screen stuff should be forked to a separate bug. Yes and no: the right fix for one is also the right fix for the other, AFAICT. Stefan From monnier@iro.umontreal.ca Tue Oct 7 19:25:53 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-5.4 required=4.0 tests=AWL,BAYES_00,FOURLA, HAS_BUG_NUMBER,MURPHY_DRUGS_REL8 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 8 Oct 2008 02:25:53 +0000 Received: from ironport2-out.teksavvy.com (ironport2-out.teksavvy.com [206.248.154.182]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m982PoRW001313 for <1058@emacsbugs.donarmstrong.com>; Tue, 7 Oct 2008 19:25:51 -0700 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AowFAB+360jO+IH3/2dsb2JhbACBcrxigWqBB4Id X-IronPort-AV: E=Sophos;i="4.33,376,1220241600"; d="scan'208";a="28132099" Received: from 206-248-129-247.dsl.teksavvy.com (HELO pastel.home) ([206.248.129.247]) by ironport2-out.teksavvy.com with ESMTP; 07 Oct 2008 22:25:44 -0400 Received: by pastel.home (Postfix, from userid 20848) id 538ED8568; Tue, 7 Oct 2008 22:25:44 -0400 (EDT) From: Stefan Monnier To: Dan Nicolaescu Cc: 1058@debbugs.gnu.org, Romain Francoise , trentbuck@gmail.com Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Message-ID: References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <87myhmdgr8.fsf@elegiac.orebokech.com> <200810062059.m96KxaXM004646@mothra.ics.uci.edu> <200810071531.m97FVlPt007507@mothra.ics.uci.edu> Date: Tue, 07 Oct 2008 22:25:44 -0400 In-Reply-To: <200810071531.m97FVlPt007507@mothra.ics.uci.edu> (Dan Nicolaescu's message of "Tue, 7 Oct 2008 08:31:47 -0700 (PDT)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii > 1. >> But is the *Messages* buffer automatically displayed (as is done when >> starting up normally)? > Not yet, but it just takes one extra `if' to do it: Actually, I don't care much that issue right now. I'd rather remove the issue altogether than try and fix it. >> This is the main reason why I think that .emacs messages should go >> to stdout. > 3. There's no code in emacs now that can do that for interactive > sessions, and when I looked at this it did not look that it can be a > small change acceptable during the feature freeze. The `noninteractive' > code has it's claws in too many places. I'm not sure it's the case: my Emacs does send the .emacs's messages to stdout before opening the initial X11 frame and I can't remember having to make many significant changes for that, mostly I introduced a new var `uninitialized' (set to nil before loading .emacs and to t afterwards) and then changed a bunch of places that check `noninteractive' to check `noninteractive || uninintialized'. >> Especially since the error might even be something that breaks the >> server, so you can't connect later on to take a look at the >> *Messages* buffer. > 5. Making the output go to stdout does not avoid this problem at all, it > reduces the possibility somewhat, but it does not avoid it. To the contrary, it eliminates the problem altogether: no need to access the *Messages* buffer since you already get the relevant info straight from stdout. > 6. But my original code to start the server early minimizes the window > of opportunity for problems in starting the server, the more .emacs, > default.el, site-start.el code you run, the more potential for problems > in starting the server later. Yes, starting the server early was > entirely intentional. I see what you mean. It might indeed make things simpler, but it eliminates a lot of flexibility. > 7. This bug report is about something else: > emacs --daemon && emacsclient -c > not working. Romain's patch looks good, it does not add features, it's > just a bug fix, so I don't see any reason it cannot go in right now. Looking at your patch again, I think it's indeed going in the right direction. A few notes/questions, tho: I'd rather have just a `daemon-detach' and then be able to call server-start separately from startup.el. Maybe a way to get that is to leave the fork in emacs.c and to turn daemon-detach into little more than close (daemon_pipe[1]). WDYT? Stefan From dann@mothra.ics.uci.edu Sun Oct 12 19:03:55 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-8.5 required=4.0 tests=AWL,BAYES_00,FOURLA, FVGT_m_MULTI_ODD,HAS_BUG_NUMBER,MURPHY_DRUGS_REL8,X_DEBBUGS_NO_ACK autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 13 Oct 2008 02:03:55 +0000 Received: from barrelv2.ics.uci.edu (barrelv2.ics.uci.edu [128.195.1.114]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m9D23qUE021857 for <1058@emacsbugs.donarmstrong.com>; Sun, 12 Oct 2008 19:03:53 -0700 Received: from mothra.ics.uci.edu (mothra.ics.uci.edu [128.195.6.93]) by barrelv2.ics.uci.edu (8.13.7+Sun/8.13.7) with ESMTP id m9D23fQV010787; Sun, 12 Oct 2008 19:03:41 -0700 (PDT) Received: (from dann@localhost) by mothra.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id m9D23eul000572; Sun, 12 Oct 2008 19:03:40 -0700 (PDT) Date: Sun, 12 Oct 2008 19:03:40 -0700 (PDT) Message-Id: <200810130203.m9D23eul000572@mothra.ics.uci.edu> From: Dan Nicolaescu To: Stefan Monnier Cc: 1058@debbugs.gnu.org, trentbuck@gmail.com, Romain Francoise Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <200810021726.m92HQcTQ017644@mothra.ics.uci.edu> <200810022234.m92MYgYp018688@mothra.ics.uci.edu> X-Debbugs-No-Ack: yes In-Reply-To: (Stefan Monnier's message of "Thu, 02 Oct 2008 21:12:02 -0400") Lines: 113 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: m9D23fQV010787 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=0.437, required 5, autolearn=disabled, ALL_TRUSTED -1.44, FM_MULTI_ODD2 1.10, FM_MULTI_ODD3 0.70, TW_RG 0.08) X-ICS-MailScanner-From: dann@mothra.ics.uci.edu Here's a patch that adds support for --daemon=SERVER_NAME Using --daemon=SERVER_NAME for scripts is much nicer than: --daemon --eval '(setq server-name "SERVER_NAME")' So IMVHO something like this could go in now... Index: lisp/server.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/server.el,v retrieving revision 1.168 diff -u -3 -p -r1.168 server.el --- lisp/server.el 24 Sep 2008 20:12:02 -0000 1.168 +++ lisp/server.el 13 Oct 2008 00:15:28 -0000 @@ -446,7 +446,7 @@ Creates the directory if necessary and m (error "The directory %s is unsafe" dir)))) ;;;###autoload -(defun server-start (&optional leave-dead) +(defun server-start (&optional leave-dead server-arg) "Allow this Emacs process to be a server for client processes. This starts a server communications subprocess through which client \"editors\" can send your editing commands to this Emacs @@ -463,6 +463,8 @@ kill any existing server communications (when server-process ;; kill it dead! (ignore-errors (delete-process server-process))) + (when (stringp server-arg) + (setq server-name server-arg)) ;; Delete the socket files made by previous server invocations. (condition-case () (delete-file (expand-file-name server-name server-socket-dir)) Index: lisp/startup.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/startup.el,v retrieving revision 1.513 diff -u -3 -p -r1.513 startup.el --- lisp/startup.el 12 Oct 2008 16:59:01 -0000 1.513 +++ lisp/startup.el 13 Oct 2008 00:15:28 -0000 @@ -1212,8 +1212,8 @@ the `--debug-init' option to view a comp ;; This is done after loading the user's init file and after ;; processing all command line arguments to allow e.g. `server-name' ;; to be changed before the server starts. - (when (daemonp) - (server-start)) + (let ((dn (daemonp))) + (when dn (server-start nil dn))) ;; Run emacs-session-restore (session management) if started by ;; the session manager and we have a session manager connection. Index: src/emacs.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/emacs.c,v retrieving revision 1.448 diff -u -3 -p -r1.448 emacs.c --- src/emacs.c 6 Oct 2008 16:16:56 -0000 1.448 +++ src/emacs.c 13 Oct 2008 00:15:28 -0000 @@ -237,6 +237,8 @@ int noninteractive1; /* Nonzero means Emacs was started as a daemon. */ int is_daemon = 0; +/* Name for the server started by the daemon.*/ +static char *daemon_name; /* Save argv and argc. */ char **initial_argv; @@ -792,6 +794,7 @@ main (int argc, char **argv) #endif int no_loadup = 0; char *junk = 0; + char *dname_arg = 0; #if GC_MARK_STACK extern Lisp_Object *stack_base; @@ -1074,8 +1077,8 @@ main (int argc, char **argv) printf (USAGE4, bug_reporting_address ()); exit (0); } - - if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)) + if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args) + || argmatch (argv, argc, "-daemon", "--daemon", 5, &dname_arg, &skip_args)) { #ifndef DOS_NT pid_t f = fork (); @@ -1088,6 +1091,8 @@ main (int argc, char **argv) exit (1); } + if (dname_arg) + daemon_name = xstrdup (dname_arg); nfd = open ("/dev/null", O_RDWR); dup2 (nfd, 0); dup2 (nfd, 1); @@ -2387,10 +2392,17 @@ decode_env_path (evarname, defalt) } DEFUN ("daemonp", Fdaemonp, Sdaemonp, 0, 0, 0, - doc: /* Return t if the current emacs process is a daemon. */) + doc: /* Return non-nil if the current emacs process is a daemon. +If the daemon was give a name argument, return that name. */) () { - return is_daemon ? Qt : Qnil; + if (is_daemon) + if (daemon_name) + return build_string (daemon_name); + else + return Qt; + else + return Qnil; } void From monnier@iro.umontreal.ca Mon Oct 13 08:16:51 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-5.6 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 13 Oct 2008 15:16:51 +0000 Received: from ironport2-out.teksavvy.com (ironport2-out.pppoe.ca [206.248.154.182]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m9DFGmaf026137 for <1058@emacsbugs.donarmstrong.com>; Mon, 13 Oct 2008 08:16:49 -0700 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4FAA0D80jO+IL0/2dsb2JhbACBcrpwgWyBCIIe X-IronPort-AV: E=Sophos;i="4.33,403,1220241600"; d="scan'208";a="28344458" Received: from 206-248-130-244.dsl.teksavvy.com (HELO ceviche.home) ([206.248.130.244]) by ironport2-out.teksavvy.com with ESMTP; 13 Oct 2008 11:16:41 -0400 Received: by ceviche.home (Postfix, from userid 20848) id 560E3701B6; Mon, 13 Oct 2008 11:16:41 -0400 (EDT) From: Stefan Monnier To: Dan Nicolaescu Cc: 1058@debbugs.gnu.org, trentbuck@gmail.com, Romain Francoise Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Message-ID: References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <200810021726.m92HQcTQ017644@mothra.ics.uci.edu> <200810022234.m92MYgYp018688@mothra.ics.uci.edu> <200810130203.m9D23eul000572@mothra.ics.uci.edu> Date: Mon, 13 Oct 2008 11:16:41 -0400 In-Reply-To: <200810130203.m9D23eul000572@mothra.ics.uci.edu> (Dan Nicolaescu's message of "Sun, 12 Oct 2008 19:03:40 -0700 (PDT)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii > -(defun server-start (&optional leave-dead) > +(defun server-start (&optional leave-dead server-arg) > "Allow this Emacs process to be a server for client processes. > This starts a server communications subprocess through which > client \"editors\" can send your editing commands to this Emacs > @@ -463,6 +463,8 @@ kill any existing server communications > (when server-process > ;; kill it dead! > (ignore-errors (delete-process server-process))) > + (when (stringp server-arg) > + (setq server-name server-arg)) Changing the global var like this is an ugly hack. I'd rather not add any feature in this direction for now anyway. Stefan From dann@mothra.ics.uci.edu Mon Oct 13 10:01:42 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-8.6 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER, MURPHY_DRUGS_REL8,X_DEBBUGS_NO_ACK autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 13 Oct 2008 17:01:42 +0000 Received: from sallyv2.ics.uci.edu (sallyv2.ics.uci.edu [128.195.1.120]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m9DH1d7S019290 for <1058@emacsbugs.donarmstrong.com>; Mon, 13 Oct 2008 10:01:40 -0700 Received: from mothra.ics.uci.edu (mothra.ics.uci.edu [128.195.6.93]) by sallyv2.ics.uci.edu (8.13.7+Sun/8.13.7) with ESMTP id m9DH1JZk018361; Mon, 13 Oct 2008 10:01:19 -0700 (PDT) Received: (from dann@localhost) by mothra.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id m9DH1ItS002005; Mon, 13 Oct 2008 10:01:18 -0700 (PDT) Date: Mon, 13 Oct 2008 10:01:18 -0700 (PDT) Message-Id: <200810131701.m9DH1ItS002005@mothra.ics.uci.edu> From: Dan Nicolaescu To: Stefan Monnier Cc: 1058@debbugs.gnu.org, trentbuck@gmail.com, Romain Francoise Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <200810021726.m92HQcTQ017644@mothra.ics.uci.edu> <200810022234.m92MYgYp018688@mothra.ics.uci.edu> <200810130203.m9D23eul000572@mothra.ics.uci.edu> X-Debbugs-No-Ack: yes In-Reply-To: (Stefan Monnier's message of "Mon, 13 Oct 2008 11:16:41 -0400") Lines: 23 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: m9DH1JZk018361 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=-1.44, required 5, autolearn=disabled, ALL_TRUSTED -1.44) X-ICS-MailScanner-From: dann@mothra.ics.uci.edu Stefan Monnier writes: > > -(defun server-start (&optional leave-dead) > > +(defun server-start (&optional leave-dead server-arg) > > "Allow this Emacs process to be a server for client processes. > > This starts a server communications subprocess through which > > client \"editors\" can send your editing commands to this Emacs > > @@ -463,6 +463,8 @@ kill any existing server communications > > (when server-process > > ;; kill it dead! > > (ignore-errors (delete-process server-process))) > > + (when (stringp server-arg) > > + (setq server-name server-arg)) > > Changing the global var like this is an ugly hack. Sure, it can be moved before the call to `sever-start' I also wanted to make that variable obsolete and make the functional interface the preferred method. But that is a separate issue, and it's quite orthogonal to the point of this patch. > I'd rather not add any feature in this direction for now anyway. From monnier@iro.umontreal.ca Mon Oct 13 12:08:13 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-5.6 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER, MURPHY_DRUGS_REL8 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 13 Oct 2008 19:08:13 +0000 Received: from ironport2-out.teksavvy.com (ironport2-out.pppoe.ca [206.248.154.182]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m9DJ86BJ018519 for <1058@emacsbugs.donarmstrong.com>; Mon, 13 Oct 2008 12:08:07 -0700 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4FAAI580jO+IL0/2dsb2JhbACBcrtFgWyBCIIe X-IronPort-AV: E=Sophos;i="4.33,404,1220241600"; d="scan'208";a="28350040" Received: from 206-248-130-244.dsl.teksavvy.com (HELO ceviche.home) ([206.248.130.244]) by ironport2-out.teksavvy.com with ESMTP; 13 Oct 2008 15:08:00 -0400 Received: by ceviche.home (Postfix, from userid 20848) id 1115C7001C; Mon, 13 Oct 2008 15:08:00 -0400 (EDT) From: Stefan Monnier To: Dan Nicolaescu Cc: 1058@debbugs.gnu.org, trentbuck@gmail.com, Romain Francoise Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Message-ID: References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <200810021726.m92HQcTQ017644@mothra.ics.uci.edu> <200810022234.m92MYgYp018688@mothra.ics.uci.edu> <200810130203.m9D23eul000572@mothra.ics.uci.edu> <200810131701.m9DH1ItS002005@mothra.ics.uci.edu> Date: Mon, 13 Oct 2008 15:07:59 -0400 In-Reply-To: <200810131701.m9DH1ItS002005@mothra.ics.uci.edu> (Dan Nicolaescu's message of "Mon, 13 Oct 2008 10:01:18 -0700 (PDT)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii >> > -(defun server-start (&optional leave-dead) >> > +(defun server-start (&optional leave-dead server-arg) >> > "Allow this Emacs process to be a server for client processes. >> > This starts a server communications subprocess through which >> > client \"editors\" can send your editing commands to this Emacs >> > @@ -463,6 +463,8 @@ kill any existing server communications >> > (when server-process >> > ;; kill it dead! >> > (ignore-errors (delete-process server-process))) >> > + (when (stringp server-arg) >> > + (setq server-name server-arg)) >> >> Changing the global var like this is an ugly hack. > Sure, it can be moved before the call to `sever-start' > I also wanted to make that variable obsolete and make the functional > interface the preferred method. There's no need or reason to make it obsolete. You basically want to replace the last two lines above with (unless (stringp server-arg) (setq server-arg server-name)) and then pass server-arg where it's needed. > But that is a separate issue, and it's quite orthogonal to the point of > this patch. Since I'm basically not excited at the idea of adding yet more features at this point, it's good to try and make sure that any such proposal comes with the cleanest code possible, rather than with a quick fix. Stefan From dann@mothra.ics.uci.edu Tue Oct 14 00:26:44 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-8.6 required=4.0 tests=AWL,BAYES_00,FOURLA, FVGT_m_MULTI_ODD,HAS_BUG_NUMBER,MURPHY_DRUGS_REL8,X_DEBBUGS_NO_ACK autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 14 Oct 2008 07:26:44 +0000 Received: from sallyv2.ics.uci.edu (sallyv2.ics.uci.edu [128.195.1.120]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m9E7QeSQ007590 for <1058@emacsbugs.donarmstrong.com>; Tue, 14 Oct 2008 00:26:41 -0700 Received: from mothra.ics.uci.edu (mothra.ics.uci.edu [128.195.6.93]) by sallyv2.ics.uci.edu (8.13.7+Sun/8.13.7) with ESMTP id m9E7QIgJ011234; Tue, 14 Oct 2008 00:26:19 -0700 (PDT) Received: (from dann@localhost) by mothra.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id m9E7QHeb004332; Tue, 14 Oct 2008 00:26:17 -0700 (PDT) Date: Tue, 14 Oct 2008 00:26:17 -0700 (PDT) Message-Id: <200810140726.m9E7QHeb004332@mothra.ics.uci.edu> From: Dan Nicolaescu To: Stefan Monnier Cc: 1058@debbugs.gnu.org, trentbuck@gmail.com, Romain Francoise Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <200810021726.m92HQcTQ017644@mothra.ics.uci.edu> <200810022234.m92MYgYp018688@mothra.ics.uci.edu> <200810130203.m9D23eul000572@mothra.ics.uci.edu> <200810131701.m9DH1ItS002005@mothra.ics.uci.edu> X-Debbugs-No-Ack: yes In-Reply-To: (Stefan Monnier's message of "Mon, 13 Oct 2008 15:07:59 -0400") Lines: 164 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: m9E7QIgJ011234 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=0.437, required 5, autolearn=disabled, ALL_TRUSTED -1.44, FM_MULTI_ODD2 1.10, FM_MULTI_ODD3 0.70, TW_RG 0.08) X-ICS-MailScanner-From: dann@mothra.ics.uci.edu Stefan Monnier writes: > >> > -(defun server-start (&optional leave-dead) > >> > +(defun server-start (&optional leave-dead server-arg) > >> > "Allow this Emacs process to be a server for client processes. > >> > This starts a server communications subprocess through which > >> > client \"editors\" can send your editing commands to this Emacs > >> > @@ -463,6 +463,8 @@ kill any existing server communications > >> > (when server-process > >> > ;; kill it dead! > >> > (ignore-errors (delete-process server-process))) > >> > + (when (stringp server-arg) > >> > + (setq server-name server-arg)) > >> > >> Changing the global var like this is an ugly hack. > > > Sure, it can be moved before the call to `sever-start' > > I also wanted to make that variable obsolete and make the functional > > interface the preferred method. > > There's no need or reason to make it obsolete. You basically want to > replace the last two lines above with > > (unless (stringp server-arg) > (setq server-arg server-name)) > > and then pass server-arg where it's needed. Ah, OK. I had the impression that server-name was needed for other functions to work correctly, but that is not the case. Updated patch follows. Now it's your choice if you want this patch now or later. I'll update the docs when checking it in. Index: lisp/server.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/server.el,v retrieving revision 1.168 diff -u -3 -p -r1.168 server.el --- lisp/server.el 24 Sep 2008 20:12:02 -0000 1.168 +++ lisp/server.el 14 Oct 2008 07:16:41 -0000 @@ -446,7 +446,7 @@ Creates the directory if necessary and m (error "The directory %s is unsafe" dir)))) ;;;###autoload -(defun server-start (&optional leave-dead) +(defun server-start (&optional leave-dead server-arg) "Allow this Emacs process to be a server for client processes. This starts a server communications subprocess through which client \"editors\" can send your editing commands to this Emacs @@ -463,9 +463,11 @@ kill any existing server communications (when server-process ;; kill it dead! (ignore-errors (delete-process server-process))) + (unless (stringp server-arg) + (setq server-arg server-name)) ;; Delete the socket files made by previous server invocations. (condition-case () - (delete-file (expand-file-name server-name server-socket-dir)) + (delete-file (expand-file-name server-arg server-socket-dir)) (error nil)) ;; If this Emacs already had a server, clear out associated status. (while server-clients @@ -476,7 +478,7 @@ kill any existing server communications (server-log (message "Server stopped")) (setq server-process nil)) (let* ((server-dir (if server-use-tcp server-auth-dir server-socket-dir)) - (server-file (expand-file-name server-name server-dir))) + (server-file (expand-file-name server-arg server-dir))) ;; Make sure there is a safe directory in which to place the socket. (server-ensure-safe-dir server-dir) ;; Remove any leftover socket or authentication file. @@ -491,7 +493,7 @@ kill any existing server communications (add-hook 'kill-emacs-hook (lambda () (server-mode -1))) ;Cleanup upon exit. (setq server-process (apply #'make-network-process - :name server-name + :name server-arg :server t :noquery t :sentinel 'server-sentinel Index: lisp/startup.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/startup.el,v retrieving revision 1.513 diff -u -3 -p -r1.513 startup.el --- lisp/startup.el 12 Oct 2008 16:59:01 -0000 1.513 +++ lisp/startup.el 14 Oct 2008 07:16:41 -0000 @@ -1212,8 +1212,8 @@ the `--debug-init' option to view a comp ;; This is done after loading the user's init file and after ;; processing all command line arguments to allow e.g. `server-name' ;; to be changed before the server starts. - (when (daemonp) - (server-start)) + (let ((dn (daemonp))) + (when dn (server-start nil dn))) ;; Run emacs-session-restore (session management) if started by ;; the session manager and we have a session manager connection. Index: src/emacs.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/emacs.c,v retrieving revision 1.448 diff -u -3 -p -r1.448 emacs.c --- src/emacs.c 6 Oct 2008 16:16:56 -0000 1.448 +++ src/emacs.c 14 Oct 2008 07:16:41 -0000 @@ -237,6 +237,8 @@ int noninteractive1; /* Nonzero means Emacs was started as a daemon. */ int is_daemon = 0; +/* Name for the server started by the daemon.*/ +static char *daemon_name; /* Save argv and argc. */ char **initial_argv; @@ -792,6 +794,7 @@ main (int argc, char **argv) #endif int no_loadup = 0; char *junk = 0; + char *dname_arg = 0; #if GC_MARK_STACK extern Lisp_Object *stack_base; @@ -1074,8 +1077,8 @@ main (int argc, char **argv) printf (USAGE4, bug_reporting_address ()); exit (0); } - - if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)) + if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args) + || argmatch (argv, argc, "-daemon", "--daemon", 5, &dname_arg, &skip_args)) { #ifndef DOS_NT pid_t f = fork (); @@ -1088,6 +1091,8 @@ main (int argc, char **argv) exit (1); } + if (dname_arg) + daemon_name = xstrdup (dname_arg); nfd = open ("/dev/null", O_RDWR); dup2 (nfd, 0); dup2 (nfd, 1); @@ -2387,10 +2392,17 @@ decode_env_path (evarname, defalt) } DEFUN ("daemonp", Fdaemonp, Sdaemonp, 0, 0, 0, - doc: /* Return t if the current emacs process is a daemon. */) + doc: /* Return non-nil if the current emacs process is a daemon. +If the daemon was give a name argument, return that name. */) () { - return is_daemon ? Qt : Qnil; + if (is_daemon) + if (daemon_name) + return build_string (daemon_name); + else + return Qt; + else + return Qnil; } void From dann@mothra.ics.uci.edu Sun Oct 26 12:24:30 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-8.8 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER, MURPHY_DRUGS_REL8,X_DEBBUGS_NO_ACK autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 26 Oct 2008 19:24:30 +0000 Received: from sallyv2.ics.uci.edu (sallyv2.ics.uci.edu [128.195.1.120]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m9QJOSpt032754 for <1058@emacsbugs.donarmstrong.com>; Sun, 26 Oct 2008 12:24:29 -0700 Received: from mothra.ics.uci.edu (mothra.ics.uci.edu [128.195.6.93]) by sallyv2.ics.uci.edu (8.13.7+Sun/8.13.7) with ESMTP id m9QJOHf6003011; Sun, 26 Oct 2008 12:24:18 -0700 (PDT) Received: (from dann@localhost) by mothra.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id m9QJOHki019653; Sun, 26 Oct 2008 12:24:17 -0700 (PDT) Date: Sun, 26 Oct 2008 12:24:17 -0700 (PDT) Message-Id: <200810261924.m9QJOHki019653@mothra.ics.uci.edu> From: Dan Nicolaescu To: Romain Francoise Cc: 1058@debbugs.gnu.org, trentbuck@gmail.com Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <87myhmdgr8.fsf@elegiac.orebokech.com> X-Debbugs-No-Ack: yes In-Reply-To: <87myhmdgr8.fsf@elegiac.orebokech.com> (Romain Francoise's message of "Thu, 02 Oct 2008 19:54:51 +0200") Lines: 7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: m9QJOHf6003011 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=-1.44, required 5, autolearn=disabled, ALL_TRUSTED -1.44) X-ICS-MailScanner-From: dann@mothra.ics.uci.edu Romain Francoise writes: > Here's version one of a patch for this, please let me know what you > think. I checked this in with some changes requested by Stefan. From dann@mothra.ics.uci.edu Mon Oct 27 00:04:46 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-8.8 required=4.0 tests=AWL,BAYES_00,HAS_BUG_NUMBER, MURPHY_DRUGS_REL8,X_DEBBUGS_NO_ACK autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at 1058) by emacsbugs.donarmstrong.com; 27 Oct 2008 07:04:46 +0000 Received: from sallyv2.ics.uci.edu (sallyv2.ics.uci.edu [128.195.1.120]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m9R74h2B009822 for <1058@emacsbugs.donarmstrong.com>; Mon, 27 Oct 2008 00:04:44 -0700 Received: from mothra.ics.uci.edu (mothra.ics.uci.edu [128.195.6.93]) by sallyv2.ics.uci.edu (8.13.7+Sun/8.13.7) with ESMTP id m9R748BD003195; Mon, 27 Oct 2008 00:04:13 -0700 (PDT) Received: (from dann@localhost) by mothra.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id m9R747nG020937; Mon, 27 Oct 2008 00:04:07 -0700 (PDT) Date: Mon, 27 Oct 2008 00:04:07 -0700 (PDT) Message-Id: <200810270704.m9R747nG020937@mothra.ics.uci.edu> From: Dan Nicolaescu To: 1058@debbugs.gnu.org Cc: Stefan Monnier , trentbuck@gmail.com, Romain Francoise Subject: Re: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready References: <1222782234_2281@mail.internode.on.net> <200810011651.m91GpAZQ010333@mothra.ics.uci.edu> <87k5csds03.fsf@elegiac.orebokech.com> <200810012332.m91NWJ4s014658@mothra.ics.uci.edu> <874p3vediy.fsf@elegiac.orebokech.com> <200810020814.m928Ed1C016380@mothra.ics.uci.edu> <200810021726.m92HQcTQ017644@mothra.ics.uci.edu> <200810022234.m92MYgYp018688@mothra.ics.uci.edu> <200810130203.m9D23eul000572@mothra.ics.uci.edu> <200810131701.m9DH1ItS002005@mothra.ics.uci.edu> <200810140726.m9E7QHeb004332@mothra.ics.uci.edu> X-Debbugs-No-Ack: yes In-Reply-To: <200810140726.m9E7QHeb004332@mothra.ics.uci.edu> (Dan Nicolaescu's message of "Tue, 14 Oct 2008 00:26:17 -0700 (PDT)") Lines: 38 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: m9R748BD003195 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=-1.44, required 5, autolearn=disabled, ALL_TRUSTED -1.44) X-ICS-MailScanner-From: dann@mothra.ics.uci.edu Dan Nicolaescu writes: > Stefan Monnier writes: > > > >> > -(defun server-start (&optional leave-dead) > > >> > +(defun server-start (&optional leave-dead server-arg) > > >> > "Allow this Emacs process to be a server for client processes. > > >> > This starts a server communications subprocess through which > > >> > client \"editors\" can send your editing commands to this Emacs > > >> > @@ -463,6 +463,8 @@ kill any existing server communications > > >> > (when server-process > > >> > ;; kill it dead! > > >> > (ignore-errors (delete-process server-process))) > > >> > + (when (stringp server-arg) > > >> > + (setq server-name server-arg)) > > >> > > >> Changing the global var like this is an ugly hack. > > > > > Sure, it can be moved before the call to `sever-start' > > > I also wanted to make that variable obsolete and make the functional > > > interface the preferred method. > > > > There's no need or reason to make it obsolete. You basically want to > > replace the last two lines above with > > > > (unless (stringp server-arg) > > (setq server-arg server-name)) > > > > and then pass server-arg where it's needed. > > Ah, OK. I had the impression that server-name was needed for other > functions to work correctly, but that is not the case. > Updated patch follows. > > Now it's your choice if you want this patch now or later. I'll update > the docs when checking it in. I checked in a version of this changed as requested by Stefan. From cyd@stupidchicken.com Wed Nov 5 13:44:23 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3-bugs.debian.org_2005_01_02 (2007-08-08) on rzlab.ucr.edu X-Spam-Level: X-Spam-Status: No, score=-4.0 required=4.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3-bugs.debian.org_2005_01_02 Received: (at control) by emacsbugs.donarmstrong.com; 5 Nov 2008 21:44:23 +0000 Received: from cyd.mit.edu (CYD.MIT.EDU [18.115.2.24]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id mA5LiL4x015103 for ; Wed, 5 Nov 2008 13:44:22 -0800 Received: by cyd.mit.edu (Postfix, from userid 1000) id 9206D57E09E; Wed, 5 Nov 2008 16:44:30 -0500 (EST) From: Chong Yidong To: control@debbugs.gnu.org Subject: close 1058 Date: Wed, 05 Nov 2008 16:44:30 -0500 Message-ID: <87wsfhn8zl.fsf@cyd.mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii close 1058 thanks From unknown Fri Jun 20 05:23:16 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: $requester Subject: Internal Control Message-Id: bug archived. Date: Thu, 04 Dec 2008 15:24:03 +0000 User-Agent: Fakemail v42.6.9 # A New Hope # A log time ago, in a galaxy far, far away # something happened. # # Magically this resulted in the following # action being taken, but this fake control # message doesn't tell you why it happened # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator