unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Tim Ruffing <public@timruffing.de>
To: 46022@debbugs.gnu.org
Subject: bug#46022: 27.1; kill-emacs should call sd_notify only in daemon mode
Date: Thu, 21 Jan 2021 17:26:31 +0100	[thread overview]
Message-ID: <1795381c3a29a50341502c2c020dccfcddf4be05.camel@timruffing.de> (raw)

When run with --fg-daemon mode (as done by the provided systemd unit
file "emacs.service"), emacs will call sd_notify() on startup to notify
systemd about its status. On exit, emacs will call sd_notify()
unconditionally, i.e., even when not run in daemon mode.

This means that when the daemon is running, other emacs processes
derived from the main process (e.g., in batch mode started by the async
package) may send exit notifications when they're exiting, even though
the main daemon process is not exiting. systemd will (correctly) ignore
these notifications because they come from the wrong PID; this is the
lucky default value of "NotifyAccess=main" in the systemd unit, i.e.,
only the main PID may send notifications. However, systemd will also
emit a warning in this case. With my config, this results in a lot of
warning messages in the systemd user journal:
Jan 20 14:23:06 systemd[1309]: emacs.service: Got notification message from PID 271936, but reception only permitted for main PID 1365
Jan 20 14:24:06 systemd[1309]: emacs.service: Got notification message from PID 271956, but reception only permitted for main PID 1365
Jan 20 14:25:07 systemd[1309]: emacs.service: Got notification message from PID 271983, but reception only permitted for main PID 1365
Jan 20 14:26:06 systemd[1309]: emacs.service: Got notification message from PID 272071, but reception only permitted for main PID 1365
Jan 20 14:27:06 systemd[1309]: emacs.service: Got notification message from PID 272092, but reception only permitted for main PID 1365
Jan 20 14:28:06 systemd[1309]: emacs.service: Got notification message from PID 272127, but reception only permitted for main PID 1365
Jan 20 14:29:06 systemd[1309]: emacs.service: Got notification message from PID 272304, but reception only permitted for main PID 1365
Jan 20 14:30:06 systemd[1309]: emacs.service: Got notification message from PID 272442, but reception only permitted for main PID 1365 

I admit that this config may be exotic but the core of the issue is not
the number of messages, it's simply that there shouldn't be any
notification (nor warning).

So I think the right thing to do is to call sd_notify in kill-emacs
only when we run in foreground daemon mode, i.e., if daemon_type == 1.
This is done when calling sd_notify in daemon-initialized. I assume the
check was omitted in kill-emacs because daemon-initialized sets
daemon_type = -1, so this information is no longer accessible when
kill-emacs runs (and it was believed sd-notify is a no-op anyway in
those cases -- but that's only partly true due to warning message).
 
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.12010000
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







             reply	other threads:[~2021-01-21 16:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-21 16:26 Tim Ruffing [this message]
2021-01-21 19:29 ` bug#46022: 27.1; kill-emacs should call sd_notify only in daemon mode Eli Zaretskii
2021-01-21 20:12   ` Lucas Werkmeister
2021-01-22  8:19     ` Eli Zaretskii
2021-01-22  9:47       ` Lucas Werkmeister
2021-01-22 11:45         ` Eli Zaretskii
2021-01-22 12:07           ` Tim Ruffing
2021-01-22 12:31             ` Eli Zaretskii

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=1795381c3a29a50341502c2c020dccfcddf4be05.camel@timruffing.de \
    --to=public@timruffing.de \
    --cc=46022@debbugs.gnu.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.
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).