unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#4944: 23.1.50; starting a server without forking a daemon
@ 2009-11-17 14:25 Kenny Stuart
  2009-11-18 18:25 ` Dan Nicolaescu
  2011-05-18 13:58 ` Kamil Cholewiński
  0 siblings, 2 replies; 5+ messages in thread
From: Kenny Stuart @ 2009-11-17 14:25 UTC (permalink / raw)
  To: emacs-pretest-bug


[-- Attachment #1.1: Type: text/plain, Size: 7274 bytes --]


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@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/

[-- Attachment #1.2: Type: text/html, Size: 10614 bytes --]

[-- Attachment #2: emacs-foreground-server.patch --]
[-- Type: application/octet-stream, Size: 2771 bytes --]

diff --git a/src/emacs.c b/src/emacs.c
index d96b3a1..956cbee 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -279,6 +279,7 @@ Initialization options:\n\
 --no-window-system, -nw     do not communicate with X, ignoring $DISPLAY\n\
 --quick, -Q                 equivalent to -q --no-site-file --no-splash\n\
 --script FILE               run FILE as an Emacs Lisp script\n\
+--server                    start a server in the foreground\n\
 --terminal, -t DEVICE       use DEVICE for terminal I/O\n\
 --user, -u USER             load ~USER/.emacs instead of your own\n\
 \n%s"
@@ -1081,7 +1082,20 @@ main (int argc, char **argv)
       exit (0);
     }
 
-  if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)
+  /* server mode and daemon mode are mutualy exclusive, if both are
+   * specified on the command line, server mode will take precedence */
+  if (argmatch (argv, argc, "-server", "--server", 5, NULL, &skip_args)
+      || argmatch (argv, argc, "server", "--server", 5, &dname_arg, &skip_args))
+    {
+      if (dname_arg)
+        daemon_name = xstrdup(dname_arg);
+
+      /* request to run as foreground server */
+      daemon_pipe[1] = -1;
+
+      /* FIXME: need to shut the foreground server down gracefully on SIGINT */
+    }
+  else if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args)
       || argmatch (argv, argc, "-daemon", "--daemon", 5, &dname_arg, &skip_args))
     {
 #ifndef DOS_NT
@@ -1855,6 +1869,7 @@ const struct standard_args standard_args[] =
   { "-batch", "--batch", 100, 0 },
   { "-script", "--script", 100, 1 },
   { "-daemon", "--daemon", 99, 0 },
+  { "-server", "--server", 99, 0 },
   { "-help", "--help", 90, 0 },
   { "-no-unibyte", "--no-unibyte", 83, 0 },
   { "-multibyte", "--multibyte", 82, 0 },
@@ -2512,7 +2527,7 @@ from the parent process and its tty file descriptors.  */)
   if (!IS_DAEMON)
     error ("This function can only be called if emacs is run as a daemon");
 
-  if (daemon_pipe[1] < 0)
+  if (daemon_pipe[1] < -1)
     error ("The daemon has already been initialized");
 
   if (NILP (Vafter_init_time))
@@ -2532,10 +2547,16 @@ from the parent process and its tty file descriptors.  */)
      Instead, we should probably close the pipe in start-process and
      call-process to make sure the pipe is never inherited by
      subprocesses.  */
-  write (daemon_pipe[1], "\n", 1);
-  close (daemon_pipe[1]);
-  /* Set it to an invalid value so we know we've already run this function.  */
-  daemon_pipe[1] = -1;
+  if (daemon_pipe[1] > 0)
+    {
+      write (daemon_pipe[1], "\n", 1);
+      close (daemon_pipe[1]);
+    }
+
+  /* indicate that this function has completed, calling it again will
+   * result in an error */
+  daemon_pipe[1] = -2;
+
   return Qt;
 }
 

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

end of thread, other threads:[~2011-05-18 13:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-17 14:25 bug#4944: 23.1.50; starting a server without forking a daemon Kenny Stuart
2009-11-18 18:25 ` Dan Nicolaescu
     [not found]   ` <BLU0-SMTP851950D69B194ABCA7830FECA20@phx.gbl>
2009-11-19 16:22     ` Dan Nicolaescu
2009-11-19 21:39       ` Kenny Stuart
2011-05-18 13:58 ` Kamil Cholewiński

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

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

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