From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dan Nicolaescu Newsgroups: gmane.emacs.bugs Subject: bug#1058: 23.0.60; emacs --daemon should not return until socket is ready Date: Thu, 2 Oct 2008 11:40:24 -0700 (PDT) Message-ID: <200810021840.m92IeOTT017793@mothra.ics.uci.edu> 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> Reply-To: Dan Nicolaescu , 1058@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1222974718 4261 80.91.229.12 (2 Oct 2008 19:11:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 2 Oct 2008 19:11:58 +0000 (UTC) Cc: trentbuck@gmail.com, 1058@emacsbugs.donarmstrong.com To: Romain Francoise Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Oct 02 21:12:56 2008 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KlTZu-0002l1-KV for geb-bug-gnu-emacs@m.gmane.org; Thu, 02 Oct 2008 21:11:10 +0200 Original-Received: from localhost ([127.0.0.1]:58196 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KlTYr-0000GE-EL for geb-bug-gnu-emacs@m.gmane.org; Thu, 02 Oct 2008 15:10:05 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KlTYn-0000Fu-V4 for bug-gnu-emacs@gnu.org; Thu, 02 Oct 2008 15:10:02 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KlTYn-0000Fg-9K for bug-gnu-emacs@gnu.org; Thu, 02 Oct 2008 15:10:01 -0400 Original-Received: from [199.232.76.173] (port=53852 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KlTYn-0000Fd-2J for bug-gnu-emacs@gnu.org; Thu, 02 Oct 2008 15:10:01 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:47201) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KlTYm-0002ZN-DC for bug-gnu-emacs@gnu.org; Thu, 02 Oct 2008 15:10:00 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m92J9u2E008436; Thu, 2 Oct 2008 12:09:56 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.13.8/8.13.8/Submit) id m92Io2Gq003086; Thu, 2 Oct 2008 11:50:02 -0700 X-Loop: don@donarmstrong.com Resent-From: Dan Nicolaescu Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Thu, 02 Oct 2008 18:50:02 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 1058 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by 1058-submit@emacsbugs.donarmstrong.com id=B1058.12229728431821 (code B ref 1058); Thu, 02 Oct 2008 18:50:02 +0000 Original-Received: (at 1058) by emacsbugs.donarmstrong.com; 2 Oct 2008 18:40:43 +0000 Original-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 Original-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) Original-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) In-Reply-To: <87myhmdgr8.fsf@elegiac.orebokech.com> (Romain Francoise's message of "Thu, 02 Oct 2008 19:54:51 +0200") Original-Lines: 73 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 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Resent-Date: Thu, 02 Oct 2008 15:10:01 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:20994 Archived-At: 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...