Commit eab2ee89 authored by Dan Nicolaescu's avatar Dan Nicolaescu

* emacs.c (standard_args): Add --daemon.

(main): Disconnect from the terminal when --daemon is passed.
(is_daemon): New variable.
(Fdaemonp): New function.
(syms_of_emacs): Defsubr it.

* startup.el (command-line): Start the server when in daemon mode.

* cmdargs.texi (Initial Options): Document --daemon.
parent d06f8010
2008-09-21 Dan Nicolaescu <dann@ics.uci.edu>
* cmdargs.texi (Initial Options): Document --daemon.
2008-09-20 Glenn Morris <rgm@gnu.org> 2008-09-20 Glenn Morris <rgm@gnu.org>
* files.texi (Numbered Backups): Mention that some modes set * files.texi (Numbered Backups): Mention that some modes set
......
...@@ -277,6 +277,15 @@ option and @samp{-Q} are the only options that block it. ...@@ -277,6 +277,15 @@ option and @samp{-Q} are the only options that block it.
Start emacs with minimum customizations. This is like using @samp{-q} Start emacs with minimum customizations. This is like using @samp{-q}
and @samp{--no-site-file}, but also disables the startup screen. and @samp{--no-site-file}, but also disables the startup screen.
@item -daemon
@opindex -daemon
@itemx --daemon
@opindex --daemon
Start emacs in background as a daemon (i.e. it will disconnect from the
terminal), do not open any frames and start the server. Clients can
connect and create graphical or terminal frames using
@code{emacsclient}.
@item --no-splash @item --no-splash
@opindex --no-splash @opindex --no-splash
@vindex inhibit-splash-screen @vindex inhibit-splash-screen
......
...@@ -130,6 +130,11 @@ Now, the default behavior is to open a new Emacs frame by default. ...@@ -130,6 +130,11 @@ Now, the default behavior is to open a new Emacs frame by default.
Use the -c option to get the old behavior of opening files in the Use the -c option to get the old behavior of opening files in the
currently selected Emacs frame. currently selected Emacs frame.
*** Emacs can now start in background, as a daemon when using the
--daemon command line argument. It disconnects from the terminal and
starts the server. Clients can connect and create graphical or
terminal frames using emacsclient.
*** The new command close-display-connection closes a connection to a *** The new command close-display-connection closes a connection to a
remote display. remote display.
......
2008-09-21 Dan Nicolaescu <dann@ics.uci.edu> 2008-09-21 Dan Nicolaescu <dann@ics.uci.edu>
* startup.el (command-line): Start the server when in daemon mode.
* frame.el (frame-initialize): Remove spurious setting of * frame.el (frame-initialize): Remove spurious setting of
special-display-function with the default value. special-display-function with the default value.
......
...@@ -881,9 +881,15 @@ opening the first frame (e.g. open a connection to an X server).") ...@@ -881,9 +881,15 @@ opening the first frame (e.g. open a connection to an X server).")
(run-hooks 'before-init-hook) (run-hooks 'before-init-hook)
;; Under X Window, this creates the X frame and deletes the terminal frame. (if (daemonp)
(when (fboundp 'frame-initialize) ;; Just start the server here, no need to run
(frame-initialize)) ;; `frame-initialize', it deals with creating a frame and
;; setting the parameters for the initial frame, we don't need
;; any oxof those.
(server-start)
;; Under X Window, this creates the X frame and deletes the terminal frame.
(when (fboundp 'frame-initialize)
(frame-initialize)))
;; Turn off blinking cursor if so specified in X resources. This is here ;; Turn off blinking cursor if so specified in X resources. This is here
;; only because all other settings of no-blinking-cursor are here. ;; only because all other settings of no-blinking-cursor are here.
......
2008-09-21 Dan Nicolaescu <dann@ics.uci.edu>
* emacs.c (standard_args): Add --daemon.
(main): Disconnect from the terminal when --daemon is passed.
(is_daemon): New variable.
(Fdaemonp): New function.
(syms_of_emacs): Defsubr it.
2008-09-20 Chong Yidong <cyd@stupidchicken.com> 2008-09-20 Chong Yidong <cyd@stupidchicken.com>
* xdisp.c (get_next_display_element): Handle string display * xdisp.c (get_next_display_element): Handle string display
......
...@@ -232,6 +232,9 @@ int noninteractive; ...@@ -232,6 +232,9 @@ int noninteractive;
int noninteractive1; int noninteractive1;
/* Nonzero means Emacs was started as a daemon. */
int is_daemon = 0;
/* Save argv and argc. */ /* Save argv and argc. */
char **initial_argv; char **initial_argv;
int initial_argc; int initial_argc;
...@@ -1068,6 +1071,34 @@ main (int argc, char **argv) ...@@ -1068,6 +1071,34 @@ main (int argc, char **argv)
exit (0); exit (0);
} }
#ifndef DOS_NT
if (argmatch (argv, argc, "-daemon", "--daemon", 5, NULL, &skip_args))
{
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);
#endif /* DOS_NT */
if (! noninteractive) if (! noninteractive)
{ {
#ifdef BSD_PGRPS #ifdef BSD_PGRPS
...@@ -1719,6 +1750,7 @@ struct standard_args standard_args[] = ...@@ -1719,6 +1750,7 @@ struct standard_args standard_args[] =
{ "-nw", "--no-windows", 110, 0 }, { "-nw", "--no-windows", 110, 0 },
{ "-batch", "--batch", 100, 0 }, { "-batch", "--batch", 100, 0 },
{ "-script", "--script", 100, 1 }, { "-script", "--script", 100, 1 },
{ "-daemon", "--daemon", 99, 0 },
{ "-help", "--help", 90, 0 }, { "-help", "--help", 90, 0 },
{ "-no-unibyte", "--no-unibyte", 83, 0 }, { "-no-unibyte", "--no-unibyte", 83, 0 },
{ "-multibyte", "--multibyte", 82, 0 }, { "-multibyte", "--multibyte", 82, 0 },
...@@ -2350,6 +2382,13 @@ decode_env_path (evarname, defalt) ...@@ -2350,6 +2382,13 @@ decode_env_path (evarname, defalt)
return Fnreverse (lpath); return Fnreverse (lpath);
} }
DEFUN ("daemonp", Fdaemonp, Sdaemonp, 0, 0, 0,
doc: /* Make the current emacs process a daemon.*/)
(void)
{
return is_daemon ? Qt : Qnil;
}
void void
syms_of_emacs () syms_of_emacs ()
{ {
...@@ -2368,6 +2407,7 @@ syms_of_emacs () ...@@ -2368,6 +2407,7 @@ syms_of_emacs ()
defsubr (&Sinvocation_name); defsubr (&Sinvocation_name);
defsubr (&Sinvocation_directory); defsubr (&Sinvocation_directory);
defsubr (&Sdaemonp);
DEFVAR_LISP ("command-line-args", &Vcommand_line_args, DEFVAR_LISP ("command-line-args", &Vcommand_line_args,
doc: /* Args passed by shell to Emacs, as a list of strings. doc: /* Args passed by shell to Emacs, as a list of strings.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment