public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Ulrich Müller" <ulm@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/emacs-tools:emacs-daemon commit in: /
Date: Wed, 05 Mar 2025 13:08:12 +0000 (UTC)	[thread overview]
Message-ID: <1741179935.f2551f65034bf63298f1a3787bf60bf92821487e.ulm@gentoo> (raw)

commit:     f2551f65034bf63298f1a3787bf60bf92821487e
Author:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
AuthorDate: Wed Mar  5 13:05:35 2025 +0000
Commit:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
CommitDate: Wed Mar  5 13:05:35 2025 +0000
URL:        https://gitweb.gentoo.org/proj/emacs-tools.git/commit/?id=f2551f65

Use --fg-daemon instead of --daemon, let OpenRC handle the rest

* emacs.rc (EMACS_OPTS): Use --fg-daemon instead of --daemon.
(EMACSCLIENT, EMACS_TIMEOUT): Remove.
(start, stop): Don't export EMACS_TIMEOUT, EMACS_DEBUG,
EMACSCLIENT and EMACSCLIENT_OPTS.
(start): Call start-stop-daemon with options --background and
--make-pidfile. Unset XDG_RUNTIME_DIR because it points to the
directory of the superuser and is not writable for us.
* emacs.conf: Update accordingly.
* emacs-wrapper.sh: Simplify; keep only the login shell wrapper.
* 10emacs-daemon-gentoo.el: Don't write the pid file, as this is
now handled by OpenRC's start-stop-daemon command.

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

 10emacs-daemon-gentoo.el | 16 ++++------------
 ChangeLog                | 12 ++++++++++++
 emacs-wrapper.sh         | 26 +-------------------------
 emacs.conf               | 19 ++++---------------
 emacs.rc                 | 15 ++++++++-------
 5 files changed, 29 insertions(+), 59 deletions(-)

diff --git a/10emacs-daemon-gentoo.el b/10emacs-daemon-gentoo.el
index 840166d..b878eb4 100644
--- a/10emacs-daemon-gentoo.el
+++ b/10emacs-daemon-gentoo.el
@@ -14,21 +14,13 @@
 		    (insert-file-contents-literally file nil 0 100)
 		    (and (looking-at "[0-9]+")
 			 (string-to-number (match-string 0))))))))
-   (cond
-    ((and (integerp pid)
-	  (string-match
-	   "emacs" (or (cdr (assq 'comm (process-attributes pid))) ""))
-	  (/= pid (emacs-pid)))
+   (when (and (integerp pid)
+	      (string-match
+	       "emacs" (or (cdr (assq 'comm (process-attributes pid))) ""))
+	      (/= pid (emacs-pid)))
      ;; If another Emacs daemon is already running for this user,
      ;; then we would steal its server socket. So we better die.
      (message "Another Emacs daemon is already running at process id %d" pid)
      (kill-emacs))
-    ((file-writable-p file)
-     ;; Write process id to file
-     (with-temp-file file
-       (insert (number-to-string (emacs-pid)) "\n"))
-     ;; Remove file on exit
-     (add-hook 'kill-emacs-hook
-	       `(lambda () (ignore-errors (delete-file ,file))))))
    ;; Restart the server if signal SIGUSR1 is received.
    (define-key special-event-map [sigusr1] #'server-start)))

diff --git a/ChangeLog b/ChangeLog
index 4b18d6f..71c0d78 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2025-03-05  Ulrich Müller  <ulm@gentoo.org>
 
+	* emacs.rc (EMACS_OPTS): Use --fg-daemon instead of --daemon.
+	(EMACSCLIENT, EMACS_TIMEOUT): Remove.
+	(start, stop): Don't export EMACS_TIMEOUT, EMACS_DEBUG,
+	EMACSCLIENT and EMACSCLIENT_OPTS.
+	(start): Call start-stop-daemon with options --background and
+	--make-pidfile. Unset XDG_RUNTIME_DIR because it points to the
+	directory of the superuser and is not writable for us.
+	* emacs.conf: Update accordingly.
+	* emacs-wrapper.sh: Simplify; keep only the login shell wrapper.
+	* 10emacs-daemon-gentoo.el: Don't write the pid file, as this is
+	now handled by OpenRC's start-stop-daemon command.
+
 	* emacs.rc (checkconfig): Remove obsolete test for baselayout-1.
 	* emacs-stop.sh: Remove example script.
 	* 10emacs-daemon-gentoo.el: Sharp-quote function name.

diff --git a/emacs-wrapper.sh b/emacs-wrapper.sh
index f418970..22c8cd9 100644
--- a/emacs-wrapper.sh
+++ b/emacs-wrapper.sh
@@ -1,27 +1,3 @@
 #!/bin/bash
-# Copyright 2008-2016 Gentoo Authors
-# Distributed under the terms of the GNU General Public License v2 or later
-
-# Save output in a temporary file and display in case of error
-logfile=$(mktemp ${TMPDIR:-/tmp}/emacs.log.XXXXXX)
-trap "rm -f '${logfile}'" EXIT
-
 # Start Emacs with a login shell wrapper to read the user's profile
-exec -l "${SHELL}" -c "exec \"${EMACS}\" $*" </dev/null &>"${logfile}" &
-pid=$!
-
-# Wait for Emacs daemon to detach
-for (( t=${EMACS_TIMEOUT:-30}; t > 0; t-- )); do
-    sleep 1
-    if ! kill -0 ${pid} 2>/dev/null; then
-        wait ${pid}		# get exit status
-        status=$?
-        [[ ${status} -ne 0 || -n ${EMACS_DEBUG} ]] && cat "${logfile}"
-        exit ${status}
-    fi
-done
-
-cat "${logfile}"
-echo "${0##*/}: timeout waiting for ${EMACS} to detach" >&2
-kill ${pid} $(pgrep -P ${pid}) 2>/dev/null
-exit 1
+exec -l "${SHELL}" -c "exec \"${EMACS}\" $*"

diff --git a/emacs.conf b/emacs.conf
index 0733e20..46975e0 100644
--- a/emacs.conf
+++ b/emacs.conf
@@ -2,9 +2,11 @@
 # This can also be used as multiplexed configuration, i.e. openrc-run
 # looks for both /etc/conf.d/emacs and /etc/conf.d/emacs.<user>.
 
-# Absolute path to the emacs and emacsclient binaries
+# Absolute path to the emacs binary
 #EMACS="/usr/bin/emacs"
-#EMACSCLIENT="/usr/bin/emacsclient"
+
+# Options to pass to emacs. Don't remove "--fg-daemon".
+#EMACS_OPTS="--fg-daemon"
 
 # Emacs detaches and exits the parent process only after loading the
 # user's .emacs (initialisation). Anything may happen there, so we use
@@ -16,20 +18,7 @@
 # daemon. #246462
 #EMACS_STOP=""
 
-# Timeout (in seconds) to wait for the daemon to detach
-#EMACS_TIMEOUT="30"
-
-# Options to pass to emacs. Don't remove "--daemon".
-#EMACS_OPTS="--daemon"
-
-# Options to pass to emacsclient. This variable is only used if you
-# call emacsclient from a custom stop script, see EMACS_STOP above.
-#EMACSCLIENT_OPTS=""
-
 # The SHELL variable to be passed to EMACS_START. emacs-wrapper.sh uses
 # this as the user's login shell. If (explicitly set to) empty, then
 # the shell field from the passwd file is used.
 #EMACS_SHELL="/bin/bash"
-
-# Enable additional output for debugging.
-#EMACS_DEBUG=""

diff --git a/emacs.rc b/emacs.rc
index cedf3c4..042935b 100644
--- a/emacs.rc
+++ b/emacs.rc
@@ -3,11 +3,9 @@
 # Distributed under the terms of the GNU General Public License v2 or later
 
 : ${EMACS:=/usr/bin/emacs}
-: ${EMACSCLIENT:=/usr/bin/emacsclient}
-: ${EMACS_OPTS:=--daemon}
+: ${EMACS_OPTS:=--fg-daemon}
 : ${EMACS_SHELL=/bin/bash}
 : ${EMACS_START:=/usr/libexec/emacs/emacs-wrapper.sh}
-: ${EMACS_TIMEOUT:=30}
 USER=${RC_SVCNAME##*.}
 PIDFILE_DIR=/var/run/emacs/${USER}
 PIDFILE=${PIDFILE_DIR}/emacs.pid
@@ -50,10 +48,14 @@ start() {
 
     SHELL=${EMACS_SHELL:-$(awk -F: "\$1 == \"${USER}\" { print \$7 }" \
 	/etc/passwd)}
-    export SHELL EMACS EMACS_TIMEOUT EMACS_DEBUG
+    export SHELL EMACS
+
+    # XDG_RUNTIME_DIR points to /run/user/0 which is not writable for us
+    # Unset it, otherwise Emacs would try to create its server socket there
+    unset XDG_RUNTIME_DIR
 
     ebegin "Starting Emacs daemon for user ${USER}"
-    start-stop-daemon --start \
+    start-stop-daemon --start --background --make-pidfile \
 	--user "${USER}" --pidfile "${PIDFILE}" --chdir "${home}" \
 	--exec "${EMACS_START}" -- ${EMACS_OPTS}
     eend $?
@@ -62,8 +64,7 @@ start() {
 stop() {
     # Optionally, call a custom script before stopping.
     if [ "${EMACS_STOP}" ] && [ -x "${EMACS_STOP}" ]; then
-	export USER PIDFILE EMACS EMACS_TIMEOUT EMACS_DEBUG
-	export EMACSCLIENT EMACSCLIENT_OPTS
+	export USER PIDFILE EMACS
 	ebegin "Calling Emacs stop script for ${USER}"
 	"${EMACS_STOP}"
 	eend $? || return


             reply	other threads:[~2025-03-05 13:08 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-05 13:08 Ulrich Müller [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-03-09 20:48 [gentoo-commits] proj/emacs-tools:emacs-daemon commit in: / Ulrich Müller
2025-03-07 16:58 Ulrich Müller
2025-03-05 15:56 Ulrich Müller
2025-03-05 13:36 Ulrich Müller
2025-03-05 13:08 Ulrich Müller
2018-12-09 22:36 Ulrich Müller
2018-09-16 14:49 Ulrich Müller
2016-06-08  6:43 Ulrich Müller
2016-05-06 13:20 Ulrich Müller
2016-05-06 13:20 Ulrich Müller
2016-05-06 13:20 Ulrich Müller
2014-02-02 11:29 Ulrich Müller
2014-02-02 11:29 Ulrich Müller
2013-08-06 19:09 Ulrich Mueller
2013-08-06 19:09 Ulrich Mueller
2013-03-23 22:08 Ulrich Mueller
2013-03-23 22:08 Ulrich Mueller
2013-03-23 22:08 Ulrich Mueller
2013-03-23 22:08 Ulrich Mueller
2012-07-21  9:01 Ulrich Mueller
2012-07-21  9:01 Ulrich Mueller
2012-05-06 18:47 Ulrich Mueller
2012-05-06 18:14 Ulrich Mueller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1741179935.f2551f65034bf63298f1a3787bf60bf92821487e.ulm@gentoo \
    --to=ulm@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox