commit:     88623eaf009738afd30693093a3b1d9abf00a858
Author:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
AuthorDate: Sun Mar  9 19:44:38 2025 +0000
Commit:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
CommitDate: Sun Mar  9 19:44:38 2025 +0000
URL:        https://gitweb.gentoo.org/proj/emacs-tools.git/commit/?id=88623eaf

Add wrapper script for Emacs daemon

* emacs-wrapper.sh: New file, moved here from emacs-daemon.
* 10emacs-common-gentoo.el: Ditto. Simplified.
* Makefile (DISTFILES): Add them.
* emacs.initd (EMACS_START, EMACS_SIGNAL_TIMEOUT): New variables.
* README.daemon: Document them.

Signed-off-by: Ulrich Müller <ulm <AT> gentoo.org>

 10emacs-common-gentoo.el | 3 +++
 ChangeLog                | 8 ++++++++
 Makefile                 | 3 ++-
 README.daemon            | 9 +++++++++
 emacs-wrapper.sh         | 3 +++
 emacs.initd              | 7 ++++++-
 6 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/10emacs-common-gentoo.el b/10emacs-common-gentoo.el
new file mode 100644
index 0000000..b23135e
--- /dev/null
+++ b/10emacs-common-gentoo.el
@@ -0,0 +1,3 @@
+(if (daemonp)
+    ;; Restart the server if signal SIGUSR1 is received
+    (define-key special-event-map [sigusr1] #'server-start))

diff --git a/ChangeLog b/ChangeLog
index 9bd5053..dabba3c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2025-03-09  Ulrich Müller  <[email protected]>
+
+       * emacs-wrapper.sh: New file, moved here from emacs-daemon.
+       * 10emacs-common-gentoo.el: Ditto. Simplified.
+       * Makefile (DISTFILES): Add them.
+       * emacs.initd (EMACS_START, EMACS_SIGNAL_TIMEOUT): New variables.
+       * README.daemon: Document them.
+
 2025-03-07  Ulrich Müller  <[email protected]>
 
        * README.gentoo.in: New file, from DOC_CONTENTS of the ebuild.

diff --git a/Makefile b/Makefile
index 76a2498..bedfc9f 100644
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,8 @@ ICONFILES = sink.png \
        emacs25_128.png emacs25.svg
 GSCHEMAFILES = org.gnu.emacs.defaults.gschema.xml
 DISTFILES = README.gentoo.in README.daemon \
-       site-start.el site-gentoo.el subdirs.el.in emacs.initd \
+       site-start.el site-gentoo.el subdirs.el.in 10emacs-common-gentoo.el \
+       emacs.initd emacs-wrapper.sh \
        $(DESKTOPFILES) $(addprefix icons/,COPYRIGHT.icons $(ICONFILES)) \
        $(GSCHEMAFILES)
 

diff --git a/README.daemon b/README.daemon
index 12201dc..a7a9e49 100644
--- a/README.daemon
+++ b/README.daemon
@@ -39,6 +39,15 @@ directory. The following variables can the configured:
    Options to pass to Emacs (in addition to ``--fg-daemon`` which is
    always passed); empty by default.
 
+``EMACS_START``
+   Wrapper script for starting Emacs. This executes a login shell,
+   in order to read the user's profile (bug #246460);
+   ``/usr/libexec/emacs/emacs-wrapper.sh`` by default.
+
+``EMACS_SIGNAL_TIMEOUT``
+   Retry specification for stopping the daemon; ``TERM/30/KILL/5``
+   by default. See start-stop-daemon(8) for documentation.
+
 Launching the Emacs daemon at system startup
 --------------------------------------------
 

diff --git a/emacs-wrapper.sh b/emacs-wrapper.sh
new file mode 100644
index 0000000..22c8cd9
--- /dev/null
+++ b/emacs-wrapper.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+# Start Emacs with a login shell wrapper to read the user's profile
+exec -l "${SHELL}" -c "exec \"${EMACS}\" $*"

diff --git a/emacs.initd b/emacs.initd
index 38ac455..2a7c145 100644
--- a/emacs.initd
+++ b/emacs.initd
@@ -3,13 +3,16 @@
 # Distributed under the terms of the GNU General Public License v2 or later
 
 : "${EMACS:=/usr/bin/emacs}"
+: "${EMACS_START:=/usr/libexec/emacs/emacs-wrapper.sh}"
+: "${EMACS_SIGNAL_TIMEOUT:=TERM/30/KILL/5}"
 
 description="Start an Emacs server running in the background"
 
 supervisor=supervise-daemon
-command="${EMACS}"
+command="${EMACS_START}"
 command_args="${EMACS_OPTS}"
 command_args_foreground="--fg-daemon"
+retry="${EMACS_SIGNAL_TIMEOUT}"
 
 depend() {
     after dbus
@@ -26,4 +29,6 @@ start_pre() {
         eerror "${EMACS} does not support running as a daemon"
         return 1
     fi
+
+    export EMACS
 }

Reply via email to