commit: 15268344aedf48ed8d73f57f7e39882f7d61b4a3 Author: Ulrich Müller <ulm <AT> gentoo <DOT> org> AuthorDate: Wed Jul 2 16:10:36 2025 +0000 Commit: Ulrich Müller <ulm <AT> gentoo <DOT> org> CommitDate: Wed Jul 2 16:10:36 2025 +0000 URL: https://gitweb.gentoo.org/proj/emacs-tools.git/commit/?id=15268344
Use default functions * emacs.rc (start, stop): Removed; use start-stop-daemon's default functions instead. (command, command_args, command_background, command_user) (directory, pidfile, retry): Define variables expected by them. (pidfile): Use the standard location. Now that the pid file is owned by root, we no longer need a user-writable subdirectory. Signed-off-by: Ulrich Müller <ulm <AT> gentoo.org> ChangeLog | 9 +++++++++ emacs.conf | 4 ---- emacs.rc | 47 +++++++++++++---------------------------------- 3 files changed, 22 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index d4c4455..eddac9d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2025-07-02 Ulrich Müller <[email protected]> + + * emacs.rc (start, stop): Removed; use start-stop-daemon's default + functions instead. + (command, command_args, command_background, command_user) + (directory, pidfile, retry): Define variables expected by them. + (pidfile): Use the standard location. Now that the pid file is + owned by root, we no longer need a user-writable subdirectory. + 2025-06-28 Ulrich Müller <[email protected]> * emacs.rc (start_pre): POSIX shell does not support "local". diff --git a/emacs.conf b/emacs.conf index 54a4880..56d8c5b 100644 --- a/emacs.conf +++ b/emacs.conf @@ -12,10 +12,6 @@ # in order to read the user's profile. #246460 #EMACS_START="/usr/libexec/emacs/emacs-wrapper.sh" -# Optionally, you may execute a custom script before stopping the -# daemon. #246462 -#EMACS_STOP="" - # Timeout (in seconds) to wait for termination of the daemon #EMACS_TIMEOUT="30" diff --git a/emacs.rc b/emacs.rc index 16c8524..2c8af7d 100644 --- a/emacs.rc +++ b/emacs.rc @@ -7,26 +7,31 @@ : "${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 description="Start an Emacs server running in the background" +command=${EMACS_START} +command_args=${EMACS_OPTS} +command_background=true +command_user=${RC_SVCNAME##*.} +directory="~${command_user}" +pidfile=/var/run/${RC_SVCNAME}.pid +retry=TERM/${EMACS_TIMEOUT}/KILL/5 + depend() { need localmount after bootmisc dbus } start_pre() { - if [ "${USER}" = "${RC_SVCNAME}" ]; then + if [ "${command_user}" = "${RC_SVCNAME}" ]; then eerror "You have to create an init script for each user:" eerror "ln -s emacs /etc/init.d/emacs.<user>" return 1 fi - if ! id -u "${USER}" >/dev/null; then - eerror "${USER}: No such user" + if ! id -u "${command_user}" >/dev/null; then + eerror "${command_user}: No such user" return 1 fi @@ -40,37 +45,11 @@ start_pre() { return 1 fi - checkpath -d --owner 0 --mode 0755 "${PIDFILE_DIR%/*}" - checkpath -d --owner 0 --mode 0755 "${PIDFILE_DIR}" -} - -start() { - SHELL=${EMACS_SHELL:-$(awk -F: "\$1 == \"${USER}\" { print \$7 }" \ - /etc/passwd)} + SHELL=${EMACS_SHELL:-$(awk -F: \ + "\$1 == \"${command_user}\" { print \$7 }" /etc/passwd)} 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 --background --make-pidfile \ - --user "${USER}" --pidfile "${PIDFILE}" --chdir "~${USER}" \ - --exec "${EMACS_START}" -- ${EMACS_OPTS} - eend $? -} - -stop() { - # Optionally, call a custom script before stopping. - if [ "${EMACS_STOP}" ] && [ -x "${EMACS_STOP}" ]; then - export USER PIDFILE EMACS EMACS_TIMEOUT - ebegin "Calling Emacs stop script for ${USER}" - "${EMACS_STOP}" - eend $? || return - fi - - ebegin "Stopping Emacs daemon for user ${USER}" - start-stop-daemon --stop --retry "TERM/${EMACS_TIMEOUT}/KILL/5" \ - --user "${USER}" --pidfile "${PIDFILE}" --exec "${EMACS}" - eend $? }
