unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#45181: 27.1; exit status and emacs.service
@ 2020-12-11 16:28 Tim Ruffing
  2020-12-11 20:33 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 4+ messages in thread
From: Tim Ruffing @ 2020-12-11 16:28 UTC (permalink / raw)
  To: 45181

The current emacs.service file contains the line  
'ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)"'

I think there are two minor issues with that line.

First, it's redundant. If this  line is removed, systemd will default
to sending SIGTERM and emacs will call kill-emacs on SIGTERM.

Second, I don't think this is really doing what is intended. Sure,
emacsclient is invoking kill-emacs but the systemd will later tell me
that emacs was not cleanly stopped. Here's sample output of "systemctl
--user status emacs" after "systemctl --user stop emacs". Note the
"failed (Result: exit-code)".

● emacs.service - Emacs text editor
     Loaded: loaded (/home/tim/.config/systemd/user/emacs.service;
enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2020-12-11 15:10:53
CET; 19min ago
       Docs: info:emacs
             man:emacs(1)
             https://gnu.org/software/emacs/
    Process: 3523 ExecStart=/usr/bin/emacs --fg-daemon (code=exited,
status=15)
    Process: 4121 ExecStop=/usr/bin/emacsclient --eval (kill-emacs)
(code=exited, status=0/SUCCESS)
   Main PID: 3523 (code=exited, status=15)

The problem here is the exit code 15, which emacs will return *only* if
it has received SIGTERM. I believe what's happening here is that
emacsclient will call kill-emacs but not wait until the emacs server
has properly shut down. However, it's supposed to wait for the shutdown
as an "ExecStop" command according to "man systemd.service". So since
the process is still alive when emacsclient comes back, systemd will
still issue SIGTERM, making emacs return 15 (maybe after calling kill-
emacs again?!).

I verified that if I spawn the server manually and invoke
"/usr/bin/emacsclient --eval "(kill-emacs)"" manually, then the server
will exit with status 0.

I think the proper thing to do is 
 - remove the ExecStop line (it's at least redundant and confusing)
 - add SuccessExitStatus=15 (to tell systemd that 15 is fine)

Best,
Tim

In GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.22,
cairo version 1.17.3)
 of 2020-08-28 built on juergen
Windowing system distributor 'The X.Org Foundation', version
11.0.12099001
System Description: Arch Linux

Configured using:
 'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
 --localstatedir=/var --with-x-toolkit=gtk3 --with-xft --with-wide-int
 --with-modules --with-cairo --with-harfbuzz 'CFLAGS=-march=x86-64
 -mtune=generic -O2 -pipe -fno-plt' CPPFLAGS=-D_FORTIFY_SOURCE=2
 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now'

Configured features:
XPM JPEG TIFF GIF PNG RSVG CAIRO SOUND GPM DBUS GSETTINGS GLIB NOTIFY
INOTIFY ACL GNUTLS LIBXML2 FREETYPE HARFBUZZ M17N_FLT LIBOTF ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS LIBSYSTEMD JSON
PDUMPER LCMS2 GMP

Important settings:
  value of $LC_COLLATE: de_DE.UTF-8
  value of $LC_CTYPE: de_DE.UTF-8
  value of $LC_MESSAGES: en_US.UTF-8
  value of $LC_MONETARY: de_DE.UTF-8
  value of $LC_NUMERIC: de_DE.UTF-8
  value of $LC_TIME: de_DE.UTF-8
  value of $LANG: en_US.utf8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message rmc puny dired dired-loaddefs
format-spec rfc822 mml easymenu mml-sec password-cache epa derived epg
epg-config gnus-util rmail rmail-loaddefs text-property-search time-
date
subr-x seq byte-opt gv bytecomp byte-compile cconv mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-
loaddefs
cl-lib sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-
utils
tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type
mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd fontset
image
regexp-opt fringe tabulated-list replace newcomment text-mode elisp-
mode
lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch
timer select scroll-bar mouse jit-lock font-lock syntax facemenu
font-core term/tty-colors frame minibuffer cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote threads dbusbind
inotify lcms2 dynamic-setting system-font-setting font-render-setting
cairo move-toolbar gtk x-toolkit x multi-tty make-network-process
emacs)

Memory information:
((conses 16 45785 10306)
 (symbols 48 6004 1)
 (strings 32 15644 1809)
 (string-bytes 1 511947)
 (vectors 16 10258)
 (vector-slots 8 133231 10154)
 (floats 8 19 43)
 (intervals 56 206 0)
 (buffers 1000 11))







^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#45181: 27.1; exit status and emacs.service
  2020-12-11 16:28 bug#45181: 27.1; exit status and emacs.service Tim Ruffing
@ 2020-12-11 20:33 ` Lars Ingebrigtsen
  2020-12-14 15:08   ` Tim Ruffing
  0 siblings, 1 reply; 4+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-11 20:33 UTC (permalink / raw)
  To: Tim Ruffing; +Cc: 45181

Tim Ruffing <public@timruffing.de> writes:

> I think the proper thing to do is 
>  - remove the ExecStop line (it's at least redundant and confusing)
>  - add SuccessExitStatus=15 (to tell systemd that 15 is fine)

Thanks for the analysis of the situation.  This sounds like the right
solution -- could you submit a patch for the emacs.service file?  Even
if this sounds like an easy fix, I don't use systemd myself for Emacs,
so I can't verify that the end result is correct (if I were to do the
changes myself).

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#45181: 27.1; exit status and emacs.service
  2020-12-11 20:33 ` Lars Ingebrigtsen
@ 2020-12-14 15:08   ` Tim Ruffing
  2020-12-14 17:00     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 4+ messages in thread
From: Tim Ruffing @ 2020-12-14 15:08 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 45181

[-- Attachment #1: Type: text/plain, Size: 778 bytes --]

I attached a patch. Feel free to edit (including the commit message --
I tried to mimic the format, I hope it's fine). This patch works fine
for me locally.

Best,
Tim

On Fri, 2020-12-11 at 21:33 +0100, Lars Ingebrigtsen wrote:
> Tim Ruffing <public@timruffing.de> writes:
> 
> > I think the proper thing to do is 
> >  - remove the ExecStop line (it's at least redundant and confusing)
> >  - add SuccessExitStatus=15 (to tell systemd that 15 is fine)
> 
> Thanks for the analysis of the situation.  This sounds like the right
> solution -- could you submit a patch for the emacs.service file? 
> Even
> if this sounds like an easy fix, I don't use systemd myself for
> Emacs,
> so I can't verify that the end result is correct (if I were to do the
> changes myself).
> 


[-- Attachment #2: 0001-etc-emacs.service.patch --]
[-- Type: text/x-patch, Size: 1704 bytes --]

From d5c31deca10b2166616059d0345f77605ca5ed6e Mon Sep 17 00:00:00 2001
From: Tim Ruffing <crypto@timruffing.de>
Date: Mon, 14 Dec 2020 15:43:41 +0100
Subject: [PATCH] * etc/emacs.service:

Before this commit, emacs.service contained an ExecStop command which
invokes (kill-emacs) via emacsclient. This was redundant because
systemd will be default send SIGTERM, which Emacs will handle by
calling (kill-emacs). Moreover, the command violated the contract of
ExecStop because emacsclient does not wait until the emacs server has
properly stopped. This led to systemd issuing SIGTERM anyway after
emacsclient exits, making Emacs exit with non-zero status 15 due to the
SIGTERM, and letting systemd believe that stopping was done properly.

This commit removes the ExecStop command such that only SIGTERM will
be used to stop the service. This commit also adds 15 to the list
of acceptable exit codes because it is not supposed to indicate failure
in this case.
---
 etc/emacs.service | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/etc/emacs.service b/etc/emacs.service
index c99c6779f5..809c49cdbc 100644
--- a/etc/emacs.service
+++ b/etc/emacs.service
@@ -9,7 +9,11 @@ Documentation=info:emacs man:emacs(1) https://gnu.org/software/emacs/
 [Service]
 Type=notify
 ExecStart=emacs --fg-daemon
-ExecStop=emacsclient --eval "(kill-emacs)"
+
+# Emacs will exit with status 15 after having received SIGTERM, which
+# is the default "KillSignal" value systemd uses to stop services.
+SuccessExitStatus=15
+
 # The location of the SSH auth socket varies by distribution, and some
 # set it from PAM, so don't override by default.
 # Environment=SSH_AUTH_SOCK=%t/keyring/ssh
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#45181: 27.1; exit status and emacs.service
  2020-12-14 15:08   ` Tim Ruffing
@ 2020-12-14 17:00     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2020-12-14 17:00 UTC (permalink / raw)
  To: Tim Ruffing; +Cc: 45181

Tim Ruffing <public@timruffing.de> writes:

> I attached a patch. Feel free to edit (including the commit message --
> I tried to mimic the format, I hope it's fine). This patch works fine
> for me locally.

Thanks; I've now committed this to Emacs 28.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-12-14 17:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-11 16:28 bug#45181: 27.1; exit status and emacs.service Tim Ruffing
2020-12-11 20:33 ` Lars Ingebrigtsen
2020-12-14 15:08   ` Tim Ruffing
2020-12-14 17:00     ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).