GNU bug report logs - #4944
23.1.50; starting a server without forking a daemon

Previous Next

Package: emacs;

Reported by: Kenny Stuart <kstuart <at> hotmail.co.uk>

Date: Tue, 17 Nov 2009 14:55:04 UTC

Severity: wishlist

Tags: patch

Merged with 2677

Fixed in version 26.1

Done: Glenn Morris <rgm <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 4944 in the body.
You can then email your comments to 4944 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#4944; Package emacs. (Tue, 17 Nov 2009 14:55:05 GMT) Full text and rfc822 format available.

Acknowledgement sent to Kenny Stuart <kstuart <at> hotmail.co.uk>:
New bug report received and forwarded. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Tue, 17 Nov 2009 14:55:05 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Kenny Stuart <kstuart <at> hotmail.co.uk>
To: <emacs-pretest-bug <at> gnu.org>
Subject: 23.1.50; starting a server without forking a daemon
Date: Tue, 17 Nov 2009 14:25:34 +0000
[Message part 1 (text/plain, inline)]
Please write in English if possible, because the Emacs maintainersusually do not have translators to read other languages for them.
Your bug report will be posted to the emacs-pretest-bug <at> gnu.org mailing list.
Please describe exactly what actions triggered the bugand the precise symptoms of the bug.  If you can, givea recipe starting from `emacs -Q':
This is a feature request to add the facility to start an emacs serverusing a command-line option that runs as a foreground process insteadof forking a daemon and exiting.
Motivation:
Forking a daemon then exiting the main process is incompatible withsystems that manage processes as services, such as launchd on OS X,therefore it is not possible to create an effective launchd serviceusing emacs in daemon mode.
Possible Solution:
For review I have included a patch that adds a --server command lineoption that does what the --daemon option does, except it runs theserver in the foreground process rather than forking a daemon andexiting.
Please note that I am new to emacs and nix based operating systems andin the short time I have had to spend on this was unable to add a SIGINThandler to gracefully shutdown the emacs server, not that it mattersto launchd since it should send SIGTERM, but a solution would be nice.
There appear to be issues on OS X with creating a new frame using the -c optionto emacsclient as emacs crashes (so far during garbage collection) whendoing this, however I am still learning the dev tools available to me on thisplatform and it will be a while before I could effectively report such bugs, sothis is just an FYI. 
As I'm using a debug build so I can investigate further, can you confirmthat the build configure options I've used are ok and not likely to becontributing to the instability, are there any other options I should beusing?
Please also note that this is the first time I have engaged with an opensource project so if I'm not doing it right let me know.
If Emacs crashed, and you have the Emacs process in the gdb debugger,please include the output from the following gdb commands:    `bt full' and `xbacktrace'.For information about debugging Emacs, please read the file/Applications/Emacs.app/Contents/Resources/etc/DEBUG.

In GNU Emacs 23.1.50.2 (x86_64-apple-darwin10.2.0, NS apple-appkit-1038.25) of 2009-11-17 on maverick.homeWindowing system distributor `Apple', version 10.3.1038configured using `configure  '--with-ns' '--enable-asserts' 'CFLAGS=-O0 -gdwarf-2 -g3 -Wno-pointer-sign''
Important settings:  value of $LC_ALL: nil  value of $LC_COLLATE: nil  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_GB.UTF-8  value of $XMODIFIERS: nil  locale-coding-system: utf-8-unix  default enable-multibyte-characters: t
Major mode: Text
Minor modes in effect:  tooltip-mode: t  mouse-wheel-mode: t  tool-bar-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:<backspace> <backspace> L i b r a r y / L a u n c h A g e n t s / <help-echo> o r g . g n u . e n <backspace> m a c s - s e r v e r . p l i s t <return> <help-echo> t e x t / x m l <return> ~ / L i b r a r y / L a u n c h A g e n t s SPC s c r i p t SPC o r <backspace> <backspace> f o r SPC e m a c s SPC s e r v e r <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <backspace> <backspace> <backspace> <backspace> <backspace> <backspace> p l s i t <backspace> <backspace> <backspace> i s t <return> a t t a c h m e n t <return> <backspace> <help-echo> <menu-bar> <file> <write-file> <help-echo> <backspace> <backspace> <backspace> <backspace> <backspace> <backspace> <backspace> <backspace> <backspace> <backspace> <backspace> <backspace> <backspace> <backspace> <backspace> <backspace> <backspace> D o <tab> c <tab> e m a c s - m a i l . t x t <return> <down-mouse-1> <mouse-1> <wheel-up> <double-wheel-up> <triple-wheel-up> <triple-wheel-up> <triple-wheel-up> <triple-wheel-up> <wheel-down> <double-wheel-down> <wheel-down> <double-wheel-down> <wheel-down> <double-wheel-down> <triple-wheel-down> <triple-wheel-down> <triple-wheel-down> <wheel-down> <double-wheel-down> <triple-wheel-down> <triple-wheel-down> <wheel-up> <double-wheel-up> <triple-wheel-up> <triple-wheel-up> <triple-wheel-up> <wheel-up> <double-wheel-up> <triple-wheel-up> <triple-wheel-up> <triple-wheel-up> <triple-wheel-up> <wheel-up> <double-wheel-up> <wheel-down> <double-wheel-down> <triple-wheel-down> <triple-wheel-down> <wheel-up> <double-wheel-up> <triple-wheel-up> <triple-wheel-up> <triple-wheel-up> <wheel-up> <wheel-up> <wheel-up> <down-mouse-1> <mouse-movement> <mouse-movement> <help-echo> <mouse-movement> <help-echo> <mouse-movement> <mouse-movement> <mouse-movement> <help-echo> <mouse-movement> <mouse-movement> <drag-mouse-1> <menu-bar> <edit> <copy> <down-mouse-1> <down-mouse-1> <down-mouse-1> <down-mouse-1> <down-mouse-1> <down-mouse-1> <down-mouse-1> <down-mouse-1> <down-mouse-1> <down-mouse-1> <down-mouse-1> <down-mouse-1> <down-mouse-1> <down-mouse-1> <down-mouse-1> <down-mouse-1> <down-mouse-1> <down-mouse-1> M-x r e p o r t - e m a c s - b u g <return>
Recent messages:Auto-saving...doneUndo!Auto-saving...doneMaking completion list...Saving file /Users/kstuart/Documents/emacs-mail.txt...Wrote /Users/kstuart/Documents/emacs-mail.txtbyte-code: Beginning of buffer [2 times]byte-code: End of buffer [2 times]byte-code: Beginning of buffer [8 times]Saved text from "Please write in English if possible, bec"
Load-path shadows:/Applications/Emacs.app/Contents/Resources/lisp/emacs-lisp/lucid hides /Applications/Emacs.app/Contents/Resources/lisp/obsolete/lucid/Applications/Emacs.app/Contents/Resources/lisp/emacs-lisp/levents hides /Applications/Emacs.app/Contents/Resources/lisp/obsolete/levents
Features:(ispell newcomment help-mode view shadow mail-extr message ecompleterfc822 mml mml-sec password-cache mm-decode mm-bodies mm-encode mailcapmail-parse rfc2231 rfc2047 rfc2045 qp ietf-drums mailabbrev nnheadergnus-util netrc time-date mm-util mail-prsvr gmm-utils wid-editmailheader canlock sha1 hex-util hashcash mail-utils emacsbug sendmailregexp-opt server tooltip ediff-hook vc-hooks lisp-float-type mwheelns-win easymenu tool-bar dnd fontset image fringe lisp-mode registerpage menu-bar rfn-eshadow timer select scroll-bar mldrag mouse jit-lockfont-lock syntax facemenu font-core frame cham georgian utf-8-langmisc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrewgreek romanian slovak czech european ethiopic indian cyrillic chinesecase-table epa-hook jka-cmpr-hook help simple abbrev loaddefs buttonminibuffer faces cus-face text-properties overlay md5 base64 format envcode-pages mule custom widget hashtable-print-readable backquotemake-network-process ns multi-tty emacs) 		 	   		  
_________________________________________________________________
Use Hotmail to send and receive mail from your different email accounts
http://clk.atdmt.com/UKM/go/186394592/direct/01/
[Message part 2 (text/html, inline)]
[emacs-foreground-server.patch (application/octet-stream, attachment)]

Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#4944; Package emacs. (Wed, 18 Nov 2009 18:35:04 GMT) Full text and rfc822 format available.

Message #8 received at 4944 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Dan Nicolaescu <dann <at> ics.uci.edu>
To: Kenny Stuart <kstuart <at> hotmail.co.uk>
Cc: 4944 <at> debbugs.gnu.org
Subject: Re: bug#4944: 23.1.50; starting a server without forking a daemon
Date: Wed, 18 Nov 2009 10:25:28 -0800 (PST)
Kenny Stuart <kstuart <at> hotmail.co.uk> writes:

  > Please write in English if possible, because the Emacs maintainers
  > usually do not have translators to read other languages for them.
  > 
  > Your bug report will be posted to the emacs-pretest-bug <at> gnu.org mailing list.
  > 
  > Please describe exactly what actions triggered the bug
  > and the precise symptoms of the bug.  If you can, give
  > a recipe starting from `emacs -Q':
  > 
  > This is a feature request to add the facility to start an emacs server
  > using a command-line option that runs as a foreground process instead
  > of forking a daemon and exiting.
  > 
  > Motivation:
  > 
  > Forking a daemon then exiting the main process is incompatible with
  > systems that manage processes as services, such as launchd on OS X,
  > therefore it is not possible to create an effective launchd service
  > using emacs in daemon mode.
  > 
  > Possible Solution:
  > 
  > For review I have included a patch that adds a --server command line
  > option that does what the --daemon option does, except it runs the
  > server in the foreground process rather than forking a daemon and
  > exiting.

How is this different from:

emacs -f server-start 

?

Also note that you do not have to start the daemon explicitly, if you use

emacsclient -a "" 

it will start an emacs daemon if one is not already running.




Severity set to 'wishlist' from 'normal' Request was from Glenn Morris <rgm <at> gnu.org> to control <at> emacsbugs.donarmstrong.com. (Thu, 19 Nov 2009 07:30:06 GMT) Full text and rfc822 format available.

Added tag(s) moreinfo. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> emacsbugs.donarmstrong.com. (Thu, 19 Nov 2009 07:30:06 GMT) Full text and rfc822 format available.

Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#4944; Package emacs. (Thu, 19 Nov 2009 16:30:06 GMT) Full text and rfc822 format available.

Acknowledgement sent to Dan Nicolaescu <dann <at> ics.uci.edu>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Thu, 19 Nov 2009 16:30:07 GMT) Full text and rfc822 format available.

Message #17 received at 4944 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Dan Nicolaescu <dann <at> ics.uci.edu>
To: Kenny Stuart <kstuart <at> hotmail.co.uk>
Cc: 4944 <at> debbugs.gnu.org
Subject: Re: bug#4944: 23.1.50; starting a server without forking a daemon
Date: Thu, 19 Nov 2009 08:22:46 -0800 (PST)
Kenny Stuart <kstuart <at> hotmail.co.uk> writes:

  > On 18 Nov 2009, at 18:25, Dan Nicolaescu wrote:
  > 
  > 
  >     Kenny Stuart <kstuart <at> hotmail.co.uk> writes:
  > 
  > 
  >         Please write in English if possible, because the Emacs maintainers
  > 
  >         usually do not have translators to read other languages for them.
  > 
  > 
  > 
  >         Your bug report will be posted to the emacs-pretest-bug <at> gnu.org mailing
  >         list.
  > 
  > 
  > 
  >         Please describe exactly what actions triggered the bug
  > 
  >         and the precise symptoms of the bug.  If you can, give
  > 
  >         a recipe starting from `emacs -Q':
  > 
  > 
  > 
  >         This is a feature request to add the facility to start an emacs server
  > 
  >         using a command-line option that runs as a foreground process instead
  > 
  >         of forking a daemon and exiting.
  > 
  > 
  > 
  >         Motivation:
  > 
  > 
  > 
  >         Forking a daemon then exiting the main process is incompatible with
  > 
  >         systems that manage processes as services, such as launchd on OS X,
  > 
  >         therefore it is not possible to create an effective launchd service
  > 
  >         using emacs in daemon mode.
  > 
  > 
  > 
  >         Possible Solution:
  > 
  > 
  > 
  >         For review I have included a patch that adds a --server command line
  > 
  >         option that does what the --daemon option does, except it runs the
  > 
  >         server in the foreground process rather than forking a daemon and
  > 
  >         exiting.
  > 
  > 
  >     How is this different from:
  > 
  >     emacs -f server-start
  > 
  >     ?
  > 
  >     Also note that you do not have to start the daemon explicitly, if you use
  > 
  >     emacsclient -a ""
  > 
  >     it will start an emacs daemon if one is not already running.
  > 
  > 

Please keep 4944 <at> debbugs.gnu.org in Cc: so that these
messages can be archived and seen by more people.

  > Neither of these appear compatible with launchd (and probably smf under
  > Solaris).

Can you please explain what do you mean by that?

It would also help if you would explain what are you trying to do, how
are you trying to do it, and what exactly are the problems that you
faced when trying to do that.


  > emacs -f server-start will initialize the display system, which is undesirable
  > when
  > starting emacs as a service, equally closing the last emacs window will
  > terminate the
  > server.
  > 
  > emacsclient -ca "" produces the following output on my mac running OS X 10.6.2
  > 
  > emacsclient: can't find socket; have you started the server?
  > To start the server in Emacs, type "M-x server-start".
  > emacsclient: connect: Connection refused
  > emacs daemon: exec failed: 2
  > Error: server did not start correctly
  > Error: Could not start the Emacs daemon
  > 
  > So there may be an issue with the trunk builds in this regard, however even if
  > it did
  > work surely it is simply starting an instance of emacs in daemon mode, which
  > will
  > fork and exit and so would be no different than having manually started the
  > daemon
  > beforehand.




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#4944; Package emacs. (Thu, 19 Nov 2009 21:45:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to Kenny Stuart <kstuart <at> hotmail.co.uk>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Thu, 19 Nov 2009 21:45:04 GMT) Full text and rfc822 format available.

Message #22 received at 4944 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Kenny Stuart <kstuart <at> hotmail.co.uk>
To: Dan Nicolaescu <dann <at> ics.uci.edu>
Cc: 4944 <at> debbugs.gnu.org
Subject: Re: bug#4944: 23.1.50; starting a server without forking a daemon
Date: Thu, 19 Nov 2009 21:39:35 +0000
On 19 Nov 2009, at 16:22, Dan Nicolaescu wrote:

> Kenny Stuart <kstuart <at> hotmail.co.uk> writes:
> 
>> On 18 Nov 2009, at 18:25, Dan Nicolaescu wrote:
>> 
>> 
>>    Kenny Stuart <kstuart <at> hotmail.co.uk> writes:
>> 
>> 
>>        Please write in English if possible, because the Emacs maintainers
>> 
>>        usually do not have translators to read other languages for them.
>> 
>> 
>> 
>>        Your bug report will be posted to the emacs-pretest-bug <at> gnu.org mailing
>>        list.
>> 
>> 
>> 
>>        Please describe exactly what actions triggered the bug
>> 
>>        and the precise symptoms of the bug.  If you can, give
>> 
>>        a recipe starting from `emacs -Q':
>> 
>> 
>> 
>>        This is a feature request to add the facility to start an emacs server
>> 
>>        using a command-line option that runs as a foreground process instead
>> 
>>        of forking a daemon and exiting.
>> 
>> 
>> 
>>        Motivation:
>> 
>> 
>> 
>>        Forking a daemon then exiting the main process is incompatible with
>> 
>>        systems that manage processes as services, such as launchd on OS X,
>> 
>>        therefore it is not possible to create an effective launchd service
>> 
>>        using emacs in daemon mode.
>> 
>> 
>> 
>>        Possible Solution:
>> 
>> 
>> 
>>        For review I have included a patch that adds a --server command line
>> 
>>        option that does what the --daemon option does, except it runs the
>> 
>>        server in the foreground process rather than forking a daemon and
>> 
>>        exiting.
>> 
>> 
>>    How is this different from:
>> 
>>    emacs -f server-start
>> 
>>    ?
>> 
>>    Also note that you do not have to start the daemon explicitly, if you use
>> 
>>    emacsclient -a ""
>> 
>>    it will start an emacs daemon if one is not already running.
>> 
>> 
> 
> Please keep 4944 <at> debbugs.gnu.org in Cc: so that these
> messages can be archived and seen by more people.
> 
>> Neither of these appear compatible with launchd (and probably smf under
>> Solaris).
> 
> Can you please explain what do you mean by that?
> 
> It would also help if you would explain what are you trying to do, how
> are you trying to do it, and what exactly are the problems that you
> faced when trying to do that.
> 
> 
>> emacs -f server-start will initialize the display system, which is undesirable
>> when
>> starting emacs as a service, equally closing the last emacs window will
>> terminate the
>> server.
>> 
>> emacsclient -ca "" produces the following output on my mac running OS X 10.6.2
>> 
>> emacsclient: can't find socket; have you started the server?
>> To start the server in Emacs, type "M-x server-start".
>> emacsclient: connect: Connection refused
>> emacs daemon: exec failed: 2
>> Error: server did not start correctly
>> Error: Could not start the Emacs daemon
>> 
>> So there may be an issue with the trunk builds in this regard, however even if
>> it did
>> work surely it is simply starting an instance of emacs in daemon mode, which
>> will
>> fork and exit and so would be no different than having manually started the
>> daemon
>> beforehand.

I'm trying to do the equivalent of using init or Upstart on Linux to
have the system start an emacs server, on OS X launchd provides that
facility, however emacs --daemon is not compatible with launchd.

** From the launchd man page:

In Darwin, the canonical way to launch a daemon is through launchd
as opposed to more traditional mechanisms or mechanisms provided
in earlier versions of Mac OS X. These alternate methods should be
considered deprecated and not suitable for new projects.

In the launchd lexicon, a "daemon" is, by definition, a system-wide
service of which there is one instance for all clients. An "agent"
is a service that runs on a per-user basis. Daemons should not attempt
to display UI or interact directly with a user's login session. Any
and all work that involves interacting with a user should be done
through agents.

** From the launchd.plist man page:

Daemons or agents managed by launchd are expected to behave certain
ways.

A daemon or agent launched by launchd MUST NOT do the following in the
process directly launched by launchd:

  •   Call daemon(3).
  •   Do the moral equivalent of daemon(3) by calling fork(2) and have
      the parent process exit(3) or _exit(2).

A daemon or agent launched by launchd SHOULD NOT do the following as a
part of their startup initialization:

  •   Setup the user ID or group ID.
  •   Setup the working directory.
  •   chroot(2)
  •   setsid(2)
  •   Close "stray" file descriptors.
  •   Change stdio(3) to /dev/null.
  •   Setup resource limits with setrusage(2).
  •   Setup priority with setpriority(2).
  •   Ignore the SIGTERM signal.

**

I'm using a LaunchAgent to start an emacs server by placing a launchd
plist file in ~/Library/LaunchAgents, the agent is configured to start
an emacs server and respawn it should it fail, since emacs --daemon is
not launchd compatible a respawn loop starts until launchd gives up.




Removed tag(s) moreinfo. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> emacsbugs.donarmstrong.com. (Tue, 24 Nov 2009 23:30:03 GMT) Full text and rfc822 format available.

Information forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#4944; Package emacs. (Wed, 18 May 2011 16:12:03 GMT) Full text and rfc822 format available.

Message #27 received at 4944 <at> debbugs.gnu.org (full text, mbox):

From: Kamil Cholewiński <harry666t <at> gmail.com>
To: 4944 <at> debbugs.gnu.org
Subject: Re: bug#4944: 23.1.50; starting a server without forking a daemon
Date: Wed, 18 May 2011 16:58:39 +0300
Hi all,

This bug is very relevant to my interests. I'm trying to run Emacs in
daemon mode under supervision of daemontools[1], and the current
behaviour (forking into the background) makes this a PITA. daemontools
includes a small utility called "fghack" which tries to keep a forked
process in the foreground, however terminating the service still
doesn't work properly. The proper solution recommended[2] by the
designers of daemontools in the FAQ is to "fix" the misbehaving
program.

By the way, this bug seems to be a duplicate of #2677 [3].

[1] http://cr.yp.to/daemontools.html
[2] http://cr.yp.to/daemontools/faq/create.html#fghack
[3] http://debbugs.gnu.org/cgi/bugreport.cgi?bug=2677

Thanks,
Kamil




Merged 2677 4944. Request was from Chong Yidong <cyd <at> stupidchicken.com> to control <at> debbugs.gnu.org. (Sun, 29 May 2011 19:29:02 GMT) Full text and rfc822 format available.

Added tag(s) patch. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Wed, 05 Oct 2011 06:46:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 2677 <at> debbugs.gnu.org and Jameson Rollins <jrollins <at> finestructure.net> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 29 Feb 2016 03:49:02 GMT) Full text and rfc822 format available.

Did not alter fixed versions and reopened. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 29 Feb 2016 17:11:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 16 Dec 2016 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 133 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.