From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tim Ruffing Newsgroups: gmane.emacs.bugs Subject: bug#46022: 27.1; kill-emacs should call sd_notify only in daemon mode Date: Thu, 21 Jan 2021 17:26:31 +0100 Message-ID: <1795381c3a29a50341502c2c020dccfcddf4be05.camel@timruffing.de> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20947"; mail-complaints-to="usenet@ciao.gmane.io" To: 46022@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jan 21 17:28:20 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l2col-0005Hz-TG for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 21 Jan 2021 17:28:20 +0100 Original-Received: from localhost ([::1]:53582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l2cok-0001N6-Lu for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 21 Jan 2021 11:28:18 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l2cnW-0001L5-8V for bug-gnu-emacs@gnu.org; Thu, 21 Jan 2021 11:27:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47623) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l2cnV-0000Id-Uf for bug-gnu-emacs@gnu.org; Thu, 21 Jan 2021 11:27:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l2cnV-0007ct-Oc for bug-gnu-emacs@gnu.org; Thu, 21 Jan 2021 11:27:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Tim Ruffing Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 21 Jan 2021 16:27:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 46022 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.161124640929293 (code B ref -1); Thu, 21 Jan 2021 16:27:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 21 Jan 2021 16:26:49 +0000 Original-Received: from localhost ([127.0.0.1]:59169 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l2cnI-0007cO-O7 for submit@debbugs.gnu.org; Thu, 21 Jan 2021 11:26:49 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:47052) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l2cnG-0007cG-IP for submit@debbugs.gnu.org; Thu, 21 Jan 2021 11:26:46 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42338) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l2cnG-00013Y-B4 for bug-gnu-emacs@gnu.org; Thu, 21 Jan 2021 11:26:46 -0500 Original-Received: from mout-p-202.mailbox.org ([80.241.56.172]:60282) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1l2cnD-00006v-NG for bug-gnu-emacs@gnu.org; Thu, 21 Jan 2021 11:26:45 -0500 Original-Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4DM77c1MbGzQlTG for ; Thu, 21 Jan 2021 17:26:36 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=timruffing.de; s=MBO0001; t=1611246394; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Af72Nsj9uHwDI3zhnC1y+CVhMZ+sHCs379nI+hFlYsw=; b=oTjQnPm6dfP6h+qRArztWCQIqFQ8EXc+HGxBfscPXrtlccDOfbsqdSV+NaqI5S0pfwRJGe Vw/eeDXvgoP51ac/sYS7X1Y37xTa1kgG0gA+fQApZpFFj+RkOSJMCWd3nenl+XhEa/GzuC YeOkUjZaqk2aDw/LHVqDlKXPikXp5N5XlU2hLgwEVqqmBPIOAieW7LmU0NSsNfPOb3pfuo 7GywwHrh0XUjHHsab7GMn8vtuSpiAuh6ocRjCDMYXnwU18UK9f1W/D3NlwmjdBjwCpzqv2 NlDqLSABTjn9POS/iJMAGOmoJB9hPPw/8cFfXzF09SRxo0I75oF4we0ZyYzzdw== Original-Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter06.heinlein-hosting.de (spamfilter06.heinlein-hosting.de [80.241.56.125]) (amavisd-new, port 10030) with ESMTP id SflDHjjyhTmu for ; Thu, 21 Jan 2021 17:26:32 +0100 (CET) X-Rspamd-Score: -4.83 / 15.00 / 15.00 X-Rspamd-Queue-Id: 3144A185B X-Rspamd-UID: 8d3d99 Received-SPF: pass client-ip=80.241.56.172; envelope-from=public@timruffing.de; helo=mout-p-202.mailbox.org X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:198323 Archived-At: 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