Commit 36b99556 authored by Glenn Morris's avatar Glenn Morris

Add --new-daemon, which runs in the foreground and does not fork

This is intended for modern init systems such as systemd,
which manage many of the traditional aspects of daemon behavior
themselves.  (Bug#2677)
* src/emacs.c (daemon_type): New integer.
(usage, standard_args): Add --old-daemon and --new-daemon.
(main): Handle --old-daemon and --new-daemon arguments.
Restrict all the forking and complicated daemon stuff to old-daemon.
(Fdaemon_initialized): Handle new-style daemon.
* src/lisp.h (IS_DAEMON, DAEMON_RUNNING) [!WINDOWNT]:
Replace daemon_pipe with daemon_type.
* doc/emacs/cmdargs.texi (Initial Options):
* doc/emacs/glossary.texi (Glossary):
* doc/emacs/misc.texi (Emacs Server):
* doc/lispref/display.texi (Window Systems):
* doc/lispref/os.texi (Startup Summary): Related doc updates.
* etc/NEWS: Mention this.
* etc/emacs.service: Use Type=simple and --new-daemon.
parent 35007ad9
......@@ -334,17 +334,18 @@ setting @code{inhibit-x-resources} to @code{t} (@pxref{Resources}).
@item -daemon
@opindex -daemon
@itemx --daemon
@itemx --daemon[=@var{name}]
@opindex --daemon
@itemx --old-daemon[=@var{name}]
@itemx --new-daemon[=@var{name}]
Start Emacs as a daemon---after Emacs starts up, it starts the Emacs
server and disconnects from the terminal without opening any frames.
server without opening any frames.
(Optionally, you can specify an explicit @var{name} for the server.)
You can then use the @command{emacsclient} command to connect to Emacs
for editing. @xref{Emacs Server}, for information about using Emacs
as a daemon.
@item -daemon=@var{SERVER-NAME}
Start emacs in background as a daemon, and use @var{SERVER-NAME} as
the server name.
as a daemon. An ``old-style'' daemon disconnects from the terminal
and runs in the background (@samp{--daemon} is an alias for
@samp{--old-daemon}).
@item --no-desktop
@opindex --no-desktop
......
......@@ -338,8 +338,8 @@ or by rebinding key sequences (@pxref{Keymaps}).
@item Daemon
A daemon is a standard term for a system-level process that runs in the
background. Daemons are often started when the system first starts up.
When Emacs runs in daemon-mode, it runs in the background and does not
open a display. You can then connect to it with the
When Emacs runs in daemon-mode, it does not
open a display. You connect to it with the
@command{emacsclient} program. @xref{Emacs Server}.
@item Default Argument
......
......@@ -1583,11 +1583,10 @@ dies with the Emacs process.
@cindex daemon, Emacs
@item
Run Emacs as a @dfn{daemon}, using the @samp{--daemon} command-line
option. @xref{Initial Options}. When Emacs is started this way, it
calls @code{server-start} after initialization, and returns control to
the calling terminal instead of opening an initial frame; it then
waits in the background, listening for edit requests.
Run Emacs as a @dfn{daemon}, using one of the @samp{--daemon} command-line
options. @xref{Initial Options}. When Emacs is started this way, it
calls @code{server-start} after initialization and does not open an
initial frame. It then waits for edit requests from clients.
@cindex systemd unit file
@item
......
......@@ -7166,7 +7166,7 @@ Emacs is displaying the frame on a character-based terminal.
@defvar initial-window-system
This variable holds the value of @code{window-system} used for the
first frame created by Emacs during startup. (When Emacs is invoked
with the @option{--daemon} option, it does not create any initial
as a daemon, it does not create any initial
frames, so @code{initial-window-system} is @code{nil}, except on
MS-Windows, where it is still @code{w32}. @xref{Initial Options,
daemon,, emacs, The GNU Emacs Manual}.)
......
......@@ -112,8 +112,8 @@ compiled into the Emacs executable when it was built.
It runs the normal hook @code{before-init-hook}.
@item
If appropriate, it creates a graphical frame. This is not done if the
options @samp{--batch} or @samp{--daemon} were specified.
If appropriate, it creates a graphical frame. This is not done in
batch (noninteractive) or daemon mode.
@item
It initializes the initial frame's faces, and sets up the menu bar
......@@ -256,10 +256,10 @@ options were specified.
@c last few bits of command-line-1 are not done in batch mode.
@item
If the option @code{--daemon} was specified, it calls
@code{server-start}, and on Posix systems also detaches from the
controlling terminal. @xref{Emacs Server,,, emacs, The GNU Emacs
Manual}.
If a daemon was requested, it calls @code{server-start}.
(On Posix systems, if a background daemon was requested, it then
detaches from the controlling terminal.) @xref{Emacs
Server,,, emacs, The GNU Emacs Manual}.
@item
If started by the X session manager, it calls
......@@ -337,7 +337,10 @@ Do not display a splash screen.
Run without an interactive terminal. @xref{Batch Mode}.
@item --daemon
Do not initialize any display; just start a server in the background.
@itemx --old-daemon
@itemx --new-daemon
Do not initialize any display; just start a server.
(An ``old-style'' daemon automatically runs in the background.)
@item --no-init-file
@itemx -q
......
......@@ -64,6 +64,12 @@ affected by this, as SGI stopped supporting IRIX in December 2013.
* Startup Changes in Emacs 26.1
** New option '--new-daemon'. This is the same as '--daemon', except
it runs in the foreground and does not fork. This is intended for
modern init systems such as systemd, which manage many of the traditional
aspects of daemon behavior themselves. '--old-daemon' is now an alias
for '--daemon'.
* Changes in Emacs 26.1
......
......@@ -7,8 +7,8 @@ Description=Emacs text editor
Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/
[Service]
Type=forking
ExecStart=emacs --daemon
Type=simple
ExecStart=emacs --new-daemon
ExecStop=emacsclient --eval "(kill-emacs)"
Environment=SSH_AUTH_SOCK=%t/keyring/ssh
Restart=on-failure
......
This diff is collapsed.
......@@ -4139,12 +4139,11 @@ extern bool no_site_lisp;
/* True means put details like time stamps into builds. */
extern bool build_details;
/* Pipe used to send exit notification to the daemon parent at
startup. On Windows, we use a kernel event instead. */
#ifndef WINDOWSNT
extern int daemon_pipe[2];
#define IS_DAEMON (daemon_pipe[1] != 0)
#define DAEMON_RUNNING (daemon_pipe[1] >= 0)
/* 0 not a daemon, 1 new-style (foreground), 2 old-style (background). */
extern int daemon_type;
#define IS_DAEMON (daemon_type != 0)
#define DAEMON_RUNNING (daemon_type >= 0)
#else /* WINDOWSNT */
extern void *w32_daemon_event;
#define IS_DAEMON (w32_daemon_event != NULL)
......
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