unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lucas Werkmeister <mail@lucaswerkmeister.de>
To: Eli Zaretskii <eliz@gnu.org>
Cc: public@timruffing.de, 46022@debbugs.gnu.org
Subject: bug#46022: 27.1; kill-emacs should call sd_notify only in daemon mode
Date: Fri, 22 Jan 2021 10:47:49 +0100	[thread overview]
Message-ID: <6b98486b-a5ff-72fd-5c9b-fe90858790ee@lucaswerkmeister.de> (raw)
In-Reply-To: <83lfcl5qoz.fsf@gnu.org>

On 22.01.21 09:19, Eli Zaretskii wrote:
>> 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.  */
> 

That looks good to me. If daemon_type is 0, it will now stay at 0
instead of being marked as invalid, but that should be okay, since
daemon-initialized has no special code for daemon_type == 0.





  reply	other threads:[~2021-01-22  9:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-21 16:26 bug#46022: 27.1; kill-emacs should call sd_notify only in daemon mode Tim Ruffing
2021-01-21 19:29 ` Eli Zaretskii
2021-01-21 20:12   ` Lucas Werkmeister
2021-01-22  8:19     ` Eli Zaretskii
2021-01-22  9:47       ` Lucas Werkmeister [this message]
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=6b98486b-a5ff-72fd-5c9b-fe90858790ee@lucaswerkmeister.de \
    --to=mail@lucaswerkmeister.de \
    --cc=46022@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=public@timruffing.de \
    /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).