From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id A7FE01582EF for ; Wed, 05 Mar 2025 13:36:23 +0000 (UTC) Received: from lists.gentoo.org (bobolink.gentoo.org [140.211.166.189]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: relay-lists.gentoo.org@gentoo.org) by smtp.gentoo.org (Postfix) with ESMTPSA id 8B38D342FE2 for ; Wed, 05 Mar 2025 13:36:23 +0000 (UTC) Received: from bobolink.gentoo.org (localhost [127.0.0.1]) by bobolink.gentoo.org (Postfix) with ESMTP id 7FF831102D0; Wed, 05 Mar 2025 13:36:22 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bobolink.gentoo.org (Postfix) with ESMTPS id 747951102D0 for ; Wed, 05 Mar 2025 13:36:22 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id F0D97342F94 for ; Wed, 05 Mar 2025 13:36:21 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 891A72872 for ; Wed, 05 Mar 2025 13:36:20 +0000 (UTC) From: "Ulrich Müller" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Ulrich Müller" Message-ID: <1741181710.4679ffa22311bbbff28e2a8caeb694a5b09c7c3c.ulm@gentoo> Subject: [gentoo-commits] proj/emacs-tools:emacs-daemon commit in: / X-VCS-Repository: proj/emacs-tools X-VCS-Files: 10emacs-daemon-gentoo.el ChangeLog emacs-wrapper.sh emacs.conf emacs.rc X-VCS-Directories: / X-VCS-Committer: ulm X-VCS-Committer-Name: Ulrich Müller X-VCS-Revision: 4679ffa22311bbbff28e2a8caeb694a5b09c7c3c X-VCS-Branch: emacs-daemon Date: Wed, 05 Mar 2025 13:36:20 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 958f8eaf-70aa-462d-b1a2-3f9b57fd1f6b X-Archives-Hash: 22615f56ce27452082d94c3f3cb0c4b9 commit: 4679ffa22311bbbff28e2a8caeb694a5b09c7c3c Author: Ulrich Müller gentoo org> AuthorDate: Wed Mar 5 13:05:35 2025 +0000 Commit: Ulrich Müller gentoo org> CommitDate: Wed Mar 5 13:35:10 2025 +0000 URL: https://gitweb.gentoo.org/proj/emacs-tools.git/commit/?id=4679ffa2 Use --fg-daemon instead of --daemon, let OpenRC handle the rest * emacs.rc (EMACS_OPTS): Use --fg-daemon instead of --daemon. (EMACSCLIENT): Remove. (start, stop): Don't export 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 gentoo.org> 10emacs-daemon-gentoo.el | 16 ++++------------ ChangeLog | 12 ++++++++++++ emacs-wrapper.sh | 26 +------------------------- emacs.conf | 18 +++++------------- emacs.rc | 14 ++++++++------ 5 files changed, 30 insertions(+), 56 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..8d3df52 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2025-03-05 Ulrich Müller + * emacs.rc (EMACS_OPTS): Use --fg-daemon instead of --daemon. + (EMACSCLIENT): Remove. + (start, stop): Don't export 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}\" $*" "${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..b962fd9 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.. -# 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,10 @@ # daemon. #246462 #EMACS_STOP="" -# Timeout (in seconds) to wait for the daemon to detach +# Timeout (in seconds) to wait for termination of the daemon #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..449e45b 100644 --- a/emacs.rc +++ b/emacs.rc @@ -3,8 +3,7 @@ # 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} @@ -50,10 +49,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 +65,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 EMACS_TIMEOUT ebegin "Calling Emacs stop script for ${USER}" "${EMACS_STOP}" eend $? || return