[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#46022: 27.1; kill-emacs should call sd_notify only in daemon mode
From: |
Eli Zaretskii |
Subject: |
bug#46022: 27.1; kill-emacs should call sd_notify only in daemon mode |
Date: |
Fri, 22 Jan 2021 10:19:40 +0200 |
> Cc: 46022@debbugs.gnu.org
> From: Lucas Werkmeister <mail@lucaswerkmeister.de>
> Date: Thu, 21 Jan 2021 21:12:03 +0100
>
> Hm, I wasn’t aware systemd logged those warnings. Probably a good idea
> to guard the sd_notify(0, "STOPPING=1") with a guard on (a stashed copy
> of?) daemon_type, then, yes.
OK, thanks. Does the patch below seems reasonable and give good
results? If yes, I'd like it to go into the upcoming Emacs 27.2.
diff --git a/src/emacs.c b/src/emacs.c
index f2e858f..67220eb 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -187,7 +187,8 @@ #define MAIN_PROGRAM
/* Name for the server started by the daemon.*/
static char *daemon_name;
-/* 0 not a daemon, 1 new-style (foreground), 2 old-style (background). */
+/* 0 not a daemon, 1 new-style (foreground), 2 old-style (background).
+ A negative value means the daemon initialization was already done. */
int daemon_type;
#ifndef WINDOWSNT
@@ -2371,7 +2372,10 @@ DEFUN ("kill-emacs", Fkill_emacs, Skill_emacs, 0, 1, "P",
int exit_code;
#ifdef HAVE_LIBSYSTEMD
- sd_notify(0, "STOPPING=1");
+ /* Notify systemd we are shutting down, but only if we have notified
+ it about startup. */
+ if (daemon_type == -1)
+ sd_notify(0, "STOPPING=1");
#endif /* HAVE_LIBSYSTEMD */
/* Fsignal calls emacs_abort () if it sees that waiting_for_input is
@@ -2876,7 +2880,7 @@ DEFUN ("daemon-initialized", Fdaemon_initialized,
Sdaemon_initialized, 0, 0, 0,
}
/* Set it to an invalid value so we know we've already run this function. */
- daemon_type = -1;
+ daemon_type = -daemon_type;
#else /* WINDOWSNT */
/* Signal the waiting emacsclient process. */