bug-gnu-emacs
[Top][All Lists]
Advanced

[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: Lucas Werkmeister
Subject: bug#46022: 27.1; kill-emacs should call sd_notify only in daemon mode
Date: Fri, 22 Jan 2021 10:47:49 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1

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 via email to

[Prev in Thread] Current Thread [Next in Thread]