• Re: Missing SIGTERM on reboot

    From didier gaumet@3:633/10 to All on Saturday, March 21, 2026 10:50:01
    Hello,

    excerpt from /etc/systemd/logind.conf:

    [...]
    # Entries in this file show the compile time defaults. Local configuration
    # should be created by either modifying this file (or a copy of it placed in # /etc/ if the original file is shipped in /usr/), or by creating "drop-ins" in
    # the /etc/systemd/logind.conf.d/ directory. The latter is generally
    # recommended. Defaults can be restored by simply deleting the main
    # configuration file and all drop-ins located in /etc/.
    #
    # Use 'systemd-analyze cat-config systemd/logind.conf' to display the full config.
    #
    # See logind.conf(5) for details.

    [Login]
    #NAutoVTs=6
    #ReserveVT=6
    #KillUserProcesses=no
    #KillOnlyUsers=
    #KillExcludeUsers=root
    [...]

    which suggest that by default (one may modify it by creating a custom
    file in /etc/systemd/logind.conf.d/) systemd-logind.service dos not kill
    user processes (root user included) and lets the killing of system
    processes to systemd-halt.service

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From CGS@3:633/10 to All on Sunday, March 22, 2026 16:10:02
    On 2026-03-20, Daniel Sterling <sterling.daniel@gmail.com> wrote:
    Found this as well which has more information about how systemd might
    shut down your user slice

    https://serverfault.com/questions/1137788/how-to-debug-systemd-shutdown-failing-to-gracefully-shutdown
    which lnks to https://www.freedesktop.org/software/systemd/man/latest/systemd.kill.html#KillMode=

    if you've verified your process gets a KILL signal and no TERM before
    hand, and the various unit / sessions settings are configured to send
    TERM before KILL, I guess that would be a systemd bug. but I guess,
    more likely than a bug, would be that the (potentially complicated) interaction between how systemd manages processes and how it can be configured is not configured to send a TERM first.

    since there doesn't seem to be a way to turn on debugging so systemd
    tells you what it's doing, you may have to either code up a patch to
    add more logging to systemd, or manually check the (again, potentially complicated) settings to see how those settings are telling systemd to
    kill your user session / slice. that of course also requires
    understanding what a session or slice even is, which I don't claim to
    know.

    not trying to be unhelpful here -- I was looking into this cuz I
    wanted to learn more about systemd, and the answer seems to be "it's potentially quite complicated"

    The text editor is the OP's version (whatever that means) of microemacs (whatever that is); it seems conceivable that the bug could be in the editor, rather than in systemd.
    On Fri, Mar 20, 2026 at 9:07?AM Daniel Sterling
    <sterling.daniel@gmail.com> wrote:

    from https://github.com/systemd/systemd/blob/main/src/shutdown/shutdown.c

    it looks like systemd does indeed try to term then kill all processes

    log_info("Sending SIGTERM to remaining processes...");
    broadcast_signal(SIGTERM, true, true, arg_timeout);

    log_info("Sending SIGKILL to remaining processes...");
    broadcast_signal(SIGKILL, true, false, arg_timeout);

    do you see those entries in your logs?

    On Fri, Mar 20, 2026 at 8:33?AM alain williams <addw@phcomp.co.uk> wrote:

    I find that when I do a reboot or poweroff (from command line) running
    processes are not being sent SIGTERM. The one that really annoys me is a text
    editor not receiving it and thus me losing work.

    The systemd documentation says that it should be sent; good old init used to do
    this.

    Is the documentation wrong or do I need to tweak some config somewhere ? >> >
    I am running Debian 13 with the mate desktop. MATE Terminal provides the >> > terminal emulation. The editor is my own version of microemacs (which does >> > handle SIGTERM correctly).

    The GUI (mate, etc) is actually irrelevant - the same thing happens to the >> > editor being run on a console.

    TIA

    --
    Alain Williams
    Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
    +44 (0) 787 668 0256 https://www.phcomp.co.uk/
    Parliament Hill Computers. Registration Information: https://www.phcomp.co.uk/Contact.html
    #include <std_disclaimer.h>




    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From alain williams@3:633/10 to All on Sunday, March 22, 2026 16:40:01
    On Sun, Mar 22, 2026 at 03:05:48PM -0000, CGS wrote:

    The text editor is the OP's version (whatever that means) of microemacs (whatever that is); it seems conceivable that the bug could be in the editor, rather than in systemd.

    No - I said that it handles SIGTERM correctly - I tested it before making this report.

    --
    Alain Williams
    Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
    +44 (0) 787 668 0256 https://www.phcomp.co.uk/
    Parliament Hill Computers. Registration Information: https://www.phcomp.co.uk/Contact.html
    #include <std_disclaimer.h>

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From CGS@3:633/10 to All on Sunday, March 22, 2026 16:50:01
    On 2026-03-22, alain williams <addw@phcomp.co.uk> wrote:
    On Sun, Mar 22, 2026 at 03:05:48PM -0000, CGS wrote:

    The text editor is the OP's version (whatever that means) of microemacs
    (whatever that is); it seems conceivable that the bug could be in the editor,
    rather than in systemd.

    No - I said that it handles SIGTERM correctly - I tested it before making this report.

    Why would you reboot or poweroff without saving your work first?

    Makes no sense to me.

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From alain williams@3:633/10 to All on Sunday, March 22, 2026 17:10:01
    On Sun, Mar 22, 2026 at 03:44:15PM -0000, CGS wrote:
    On 2026-03-22, alain williams <addw@phcomp.co.uk> wrote:
    On Sun, Mar 22, 2026 at 03:05:48PM -0000, CGS wrote:

    The text editor is the OP's version (whatever that means) of microemacs
    (whatever that is); it seems conceivable that the bug could be in the editor,
    rather than in systemd.

    No - I said that it handles SIGTERM correctly - I tested it before making this report.

    Why would you reboot or poweroff without saving your work first?

    Makes no sense to me.

    I have a hardware problem (graphics card occasionally crashes, I shall get a new one next week). This is what made me aware of the problem. I can ssh into the machine and poweroff (reboot is not enough, power cycle needed) - which is what I did. I now send instances of the editor SIGTERM before typing poweroff - thus it saves modified buffers.

    --
    Alain Williams
    Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
    +44 (0) 787 668 0256 https://www.phcomp.co.uk/
    Parliament Hill Computers. Registration Information: https://www.phcomp.co.uk/Contact.html
    #include <std_disclaimer.h>

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From tomas@3:633/10 to All on Sunday, March 22, 2026 17:30:01
    On Sun, Mar 22, 2026 at 03:44:15PM -0000, CGS wrote:
    On 2026-03-22, alain williams <addw@phcomp.co.uk> wrote:
    On Sun, Mar 22, 2026 at 03:05:48PM -0000, CGS wrote:

    The text editor is the OP's version (whatever that means) of microemacs
    (whatever that is); it seems conceivable that the bug could be in the editor,
    rather than in systemd.

    No - I said that it handles SIGTERM correctly - I tested it before making this report.

    Why would you reboot or poweroff without saving your work first?
    Why not? If the software does its thing, it all should go well.
    Cheers
    --
    t


    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From CGS@3:633/10 to All on Sunday, March 22, 2026 17:50:01
    On 2026-03-22, alain williams <addw@phcomp.co.uk> wrote:
    On Sun, Mar 22, 2026 at 03:44:15PM -0000, CGS wrote:
    On 2026-03-22, alain williams <addw@phcomp.co.uk> wrote:
    On Sun, Mar 22, 2026 at 03:05:48PM -0000, CGS wrote:

    The text editor is the OP's version (whatever that means) of microemacs >> >> (whatever that is); it seems conceivable that the bug could be in the editor,
    rather than in systemd.

    No - I said that it handles SIGTERM correctly - I tested it before making this report.

    Why would you reboot or poweroff without saving your work first?

    Makes no sense to me.

    I have a hardware problem (graphics card occasionally crashes, I shall get a new one next week). This is what made me aware of the problem. I can ssh into the machine and poweroff (reboot is not enough, power cycle needed) - which is
    what I did. I now send instances of the editor SIGTERM before typing poweroff -
    thus it saves modified buffers.

    Right. I think the crashed system isn't performing a canonical poweroff.

    Try powering off the machine when the system isn't crashed; this will demonstrate whether there's a bug or not.

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From alain williams@3:633/10 to All on Sunday, March 22, 2026 18:00:01
    On Sun, Mar 22, 2026 at 04:41:24PM -0000, CGS wrote:

    I have a hardware problem (graphics card occasionally crashes, I shall get a
    new one next week). This is what made me aware of the problem. I can ssh into
    the machine and poweroff (reboot is not enough, power cycle needed) - which is
    what I did. I now send instances of the editor SIGTERM before typing poweroff -
    thus it saves modified buffers.

    Right. I think the crashed system isn't performing a canonical poweroff.

    Reboot does not do a power cycle.

    The graphics card crashes (system log has messages complaining about it), sometimes crashes the system but generally not - thus I can ssh in.

    Try powering off the machine when the system isn't crashed; this will demonstrate whether there's a bug or not.

    Tried that and I get the same problem (in a VM, but will work the same). Why did
    you think that I did not try that ?

    --
    Alain Williams
    Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
    +44 (0) 787 668 0256 https://www.phcomp.co.uk/
    Parliament Hill Computers. Registration Information: https://www.phcomp.co.uk/Contact.html
    #include <std_disclaimer.h>

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From CGS@3:633/10 to All on Sunday, March 22, 2026 18:00:02
    On 2026-03-22, <tomas@tuxteam.de> <tomas@tuxteam.de> wrote:

    Why would you reboot or poweroff without saving your work first?

    Why not? If the software does its thing, it all should go well.


    I use vim and there's a .swp file in the event of an irregular system
    shutdown, e.g. a power outage or, as described by the OP, a system
    that has crashed due to a buggy graphics card/driver.

    I would not depend on systemd or anything else to send the canonical
    SIGTERM to processes, neither in the former nor in the latter case.

    At any rate, I don't depend on much but typing :w as I go.

    YMMV.

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From CGS@3:633/10 to All on Sunday, March 22, 2026 18:10:02
    On 2026-03-22, alain williams <addw@phcomp.co.uk> wrote:
    On Sun, Mar 22, 2026 at 04:41:24PM -0000, CGS wrote:

    I have a hardware problem (graphics card occasionally crashes, I shall get a
    new one next week). This is what made me aware of the problem. I can ssh into
    the machine and poweroff (reboot is not enough, power cycle needed) - which is
    what I did. I now send instances of the editor SIGTERM before typing poweroff -
    thus it saves modified buffers.

    Right. I think the crashed system isn't performing a canonical poweroff.

    Reboot does not do a power cycle.

    The graphics card crashes (system log has messages complaining about it), sometimes crashes the system but generally not - thus I can ssh in.

    Try powering off the machine when the system isn't crashed; this will
    demonstrate whether there's a bug or not.

    Tried that and I get the same problem (in a VM, but will work the same). Why did
    you think that I did not try that ?

    So with Debian Trixie in a VM poweroff doesn't send a SIGTERM to
    processes. Have you filed a bug report? This seems like a big one. How
    about not in a VM? Have you tried that, too?

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Stefan Monnier@3:633/10 to All on Monday, March 23, 2026 14:50:01
    I find that when I do a reboot or poweroff (from command line) running processes are not being sent SIGTERM. The one that really annoys me is a text editor not receiving it and thus me losing work.

    The systemd documentation says that it should be sent; good old init
    used to do this.

    Is the documentation wrong or do I need to tweak some config somewhere ?

    I am running Debian 13 with the mate desktop. MATE Terminal provides the terminal emulation. The editor is my own version of microemacs (which does handle SIGTERM correctly).

    The GUI (mate, etc) is actually irrelevant - the same thing happens to the editor being run on a console.

    I have no idea what's really going on, but I think there are two
    possible explanations:

    - Your editor process is sent *another* signal (e.g. because of the
    disappearance of some other endpoint of one of its file descriptors)
    that makes it die without saving-work, before systemd gets a chance to
    send it a SIGTERM. [ If that's the case, the problem is in your editor
    which should handle that other signal better. ]

    - Maybe same as above but systemd wouldn't send a SIGTERM anyway.

    - Your process is not sent any signal. I think that would qualify as
    a bug in systemd.

    - The filesystem is read-only when your process gets SIGTERM so it can't
    save your work?


    === Stefan

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From CGS@3:633/10 to All on Monday, March 23, 2026 15:20:01
    On 2026-03-23, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
    I find that when I do a reboot or poweroff (from command line) running
    processes are not being sent SIGTERM. The one that really annoys me is a text
    editor not receiving it and thus me losing work.

    The systemd documentation says that it should be sent; good old init
    used to do this.

    Is the documentation wrong or do I need to tweak some config somewhere ?

    I am running Debian 13 with the mate desktop. MATE Terminal provides the
    terminal emulation. The editor is my own version of microemacs (which does >> handle SIGTERM correctly).

    The GUI (mate, etc) is actually irrelevant - the same thing happens to the >> editor being run on a console.

    I have no idea what's really going on, but I think there are two
    possible explanations:

    - Your editor process is sent *another* signal (e.g. because of the
    disappearance of some other endpoint of one of its file descriptors)
    that makes it die without saving-work, before systemd gets a chance to
    send it a SIGTERM. [ If that's the case, the problem is in your editor
    which should handle that other signal better. ]

    - Maybe same as above but systemd wouldn't send a SIGTERM anyway.

    - Your process is not sent any signal. I think that would qualify as
    a bug in systemd.

    - The filesystem is read-only when your process gets SIGTERM so it can't
    save your work?

    It's a VM, apparently, BTW.


    === Stefan



    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From debian-user@3:633/10 to All on Monday, March 23, 2026 19:40:01
    Stefan Monnier <monnier@iro.umontreal.ca> wrote:
    I find that when I do a reboot or poweroff (from command line)
    running processes are not being sent SIGTERM. The one that really
    annoys me is a text editor not receiving it and thus me losing work.

    The systemd documentation says that it should be sent; good old init
    used to do this.

    Is the documentation wrong or do I need to tweak some config
    somewhere ?

    I am running Debian 13 with the mate desktop. MATE Terminal
    provides the terminal emulation. The editor is my own version of
    microemacs (which does handle SIGTERM correctly).

    The GUI (mate, etc) is actually irrelevant - the same thing happens
    to the editor being run on a console.

    I have no idea what's really going on, but I think there are two
    possible explanations:

    - Your editor process is sent *another* signal (e.g. because of the
    disappearance of some other endpoint of one of its file descriptors)
    that makes it die without saving-work, before systemd gets a chance
    to send it a SIGTERM. [ If that's the case, the problem is in your
    editor which should handle that other signal better. ]

    - Maybe same as above but systemd wouldn't send a SIGTERM anyway.

    - Your process is not sent any signal. I think that would qualify as
    a bug in systemd.

    - The filesystem is read-only when your process gets SIGTERM so it
    can't save your work?

    I think that would be a bug in systemd as well, if it makes a
    filesystem RO before processes using the filesystem have terminated?

    Really, I wouldn't expect systemd to disappear any filesystems before
    it had terminated all processes that could be using them.

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From alain williams@3:633/10 to All on Tuesday, March 24, 2026 00:10:01
    On Mon, Mar 23, 2026 at 09:48:35AM -0400, Stefan Monnier wrote:

    I have no idea what's really going on, but I think there are two
    possible explanations:

    I have found the cause of the problem. When my editor receives a signal (any catchable signal) it produces some messages (signal xx received; command
    trace; ...) and then saves modified buffers (to recovery file) and then says goodbye. The what-is-happening messages are first in case saving buffers causes another signal.

    I removed generation of all of these messages and the recovery file is generated. So it seems that when the system is shutting down any terminal output causes the program to be immediately terminated or possibly just suspended and then later terminated.

    The solution, for me, is simple: do not generate nice 'error: this is happening' messages when a SIGTERM is received, but do so with other signals. The most common is SIGHUP when a network error kills a ssh session (this works as expected).

    This is, IMHO, unexpected behaviour. In a shutdown situation the messages should be accepted and: output or ignored/thrown-away depending on what is possible. I suspect that many programs will say something, a quick search shows an example of this:

    https://www.ibm.com/support/pages/how-applications-can-detect-when-job-ending-controlled-manner

    So: problem with systemd ? What do you think ?

    --
    Alain Williams
    Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
    +44 (0) 787 668 0256 https://www.phcomp.co.uk/
    Parliament Hill Computers. Registration Information: https://www.phcomp.co.uk/Contact.html
    #include <std_disclaimer.h>

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Andy Smith@3:633/10 to All on Tuesday, March 24, 2026 00:40:02
    Hi,

    On Mon, Mar 23, 2026 at 11:04:08PM +0000, alain williams wrote:
    I removed generation of all of these messages and the recovery file is generated. So it seems that when the system is shutting down any terminal output causes the program to be immediately terminated or possibly just suspended and then later terminated.

    [?]

    So: problem with systemd ? What do you think ?

    I don't fully understand the situation, but if it is that:

    1. All your processes receive a SIGTERM
    2. Your editor writes a message about that to your terminal
    3. Your terminal already exited because it got a SIGTERM
    3. So your editor never manages to write its message and then doesn't
    follow through with writing open buffers to recovery file

    ?then I would say that the bug is in the editor because writes to file descriptors aren't guaranteed to succeed or even to not block forever,
    so should it really be blocking an emergency action on the success of
    that?

    If we were to argue that the bug is in systemd, what would be the
    systemd fix to that situation?

    But perhaps I have misunderstood.

    Thanks,
    Andy

    --
    https://bitfolk.com/ -- No-nonsense VPS hosting

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From alain williams@3:633/10 to All on Tuesday, March 24, 2026 01:00:01
    On Mon, Mar 23, 2026 at 11:35:09PM +0000, Andy Smith wrote:

    I don't fully understand the situation, but if it is that:

    1. All your processes receive a SIGTERM
    2. Your editor writes a message about that to your terminal
    3. Your terminal already exited because it got a SIGTERM
    3. So your editor never manages to write its message and then doesn't
    follow through with writing open buffers to recovery file

    ?then I would say that the bug is in the editor because writes to file descriptors aren't guaranteed to succeed or even to not block forever,
    so should it really be blocking an emergency action on the success of
    that?

    Yes: it tries to write to the TTY, it does not test if this succeeds, but it fails in a way that stops it from proceeding: either by blocking (forever) or by killing it.

    If we were to argue that the bug is in systemd, what would be the
    systemd fix to that situation?

    Prolly a change in order of shutting things down so that ttys continue to work until user processes have terminated. This is analogous to keeping file systems writable until user processes have terminated. (This fails on console ttys as well as gnome terminals.)

    I have now fixed the editor to not send anything to the terminal if SIGTERM is received.

    But perhaps I have misunderstood.

    No, you got it right.

    As seen with my link to IBM - I am not the only one that this would have tripped up.

    --
    Alain Williams
    Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
    +44 (0) 787 668 0256 https://www.phcomp.co.uk/
    Parliament Hill Computers. Registration Information: https://www.phcomp.co.uk/Contact.html
    #include <std_disclaimer.h>

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Greg Wooledge@3:633/10 to All on Tuesday, March 24, 2026 01:00:01
    On Mon, Mar 23, 2026 at 23:35:09 +0000, Andy Smith wrote:
    I don't fully understand the situation, but if it is that:

    1. All your processes receive a SIGTERM
    2. Your editor writes a message about that to your terminal
    3. Your terminal already exited because it got a SIGTERM
    3. So your editor never manages to write its message and then doesn't
    follow through with writing open buffers to recovery file

    ?then I would say that the bug is in the editor because writes to file descriptors aren't guaranteed to succeed or even to not block forever,
    so should it really be blocking an emergency action on the success of
    that?

    If we were to argue that the bug is in systemd, what would be the
    systemd fix to that situation?

    If I recall correctly, it was reported that the issue also occurs if
    the editor is running on a Linux virtual console (/dev/tty2 or whatever).
    In that case, unless I'm *very* confused, I don't believe there is any
    process associated with the terminal, or at least no process that can
    be terminated by a signal.

    In that specific scenario, I wonder whether the virtual consoles are
    being de-allocated prematurely. If they are, then that *could* be
    something within systemd that could be re-ordered. If not, then what's
    causing the error messages to fail/block?

    At that point, I would want to see an strace of the editor being
    signalled, and see exactly what happens. This could be incredibly
    tricky to arrange, though. The trace log would need to continue being
    written while the system is being torn down. I don't know whether
    that's possible.

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From alain williams@3:633/10 to All on Tuesday, March 24, 2026 01:20:02
    On Mon, Mar 23, 2026 at 07:59:22PM -0400, Greg Wooledge wrote:

    If I recall correctly, it was reported that the issue also occurs if
    the editor is running on a Linux virtual console (/dev/tty2 or whatever).
    In that case, unless I'm *very* confused, I don't believe there is any process associated with the terminal, or at least no process that can
    be terminated by a signal.

    That is what I find. It is not just a Debian thing - it also happens under Rocky Linux (aka Red Hat).

    --
    Alain Williams
    Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
    +44 (0) 787 668 0256 https://www.phcomp.co.uk/
    Parliament Hill Computers. Registration Information: https://www.phcomp.co.uk/Contact.html
    #include <std_disclaimer.h>

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Max Nikulin@3:633/10 to All on Tuesday, March 24, 2026 03:50:01
    On 24/03/2026 6:59 am, Greg Wooledge wrote:
    At that point, I would want to see an strace of the editor being
    signalled, and see exactly what happens. This could be incredibly
    tricky to arrange, though. The trace log would need to continue being written while the system is being torn down. I don't know whether
    that's possible.

    strace may be an independent systemd unit with its own KillMode and
    intervals between signals. systemd-run should allow to launch an ad hoc
    unit.

    Perhaps write access to tty is revoked from the user at certain moment
    of shout down process.

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Stefan Monnier@3:633/10 to All on Tuesday, March 24, 2026 04:40:01
    I removed generation of all of these messages and the recovery file is generated. So it seems that when the system is shutting down any terminal output causes the program to be immediately terminated or possibly just suspended and then later terminated.

    Or maybe the writing of the error message causes reception of
    another signal? Or it just blocks?

    Where is this writing taking place? From the signal handler itself?


    === Stefan

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Jeffrey Walton@3:633/10 to All on Tuesday, March 24, 2026 05:10:01
    On Mon, Mar 23, 2026 at 7:04?PM alain williams <addw@phcomp.co.uk>
    wrote:

    On Mon, Mar 23, 2026 at 09:48:35AM -0400, Stefan Monnier wrote:

    I have no idea what's really going on, but I think there are two
    possible explanations:

    I have found the cause of the problem. When my editor receives a signal (
    any
    catchable signal) it produces some messages (signal xx received; command trace; ...) and then saves modified buffers (to recovery file) and then s
    ays
    goodbye. The what-is-happening messages are first in case saving buffers
    causes
    another signal.

    I removed generation of all of these messages and the recovery file is generated. So it seems that when the system is shutting down any terminal output causes the program to be immediately terminated or possibly just suspended and then later terminated.

    The solution, for me, is simple: do not generate nice 'error: this is happening' messages when a SIGTERM is received, but do so with other sign
    als.
    The most common is SIGHUP when a network error kills a ssh session (this
    works
    as expected).

    This is, IMHO, unexpected behaviour. In a shutdown situation the messages should be accepted and: output or ignored/thrown-away depending on what i
    s
    possible. I suspect that many programs will say something, a quick search
    shows
    an example of this:

    https://www.ibm.com/support/pages/how-applications-can-detect-when-job-en
    ding-controlled-manner

    So: problem with systemd ? What do you think ?

    You have to be careful of what you do in a signal handler. If the
    editor is trying to log messages to a log file like, "Received SIGTERM
    on 03/23/2026 22:00:00", then things could get very tricky. That's
    because any system call made must be AS-Safe a/k/a Asynchronous Signal
    Safe. If the call is not AS-Safe, then that is Undefined Behavior
    (UB) and you should expect nasal demons.

    You can see the libc functions that are AS-Safe under
    "Async-signal-safe functions" in the signal(7) man page, <https://linux.die.net/man/7/signal>. Here's a spoiler alert:
    printf() and friends are _NOT_ AS-Safe. Strange things happen when
    you try to format a message to be logged in a signal handler. Under
    Glibc, that is usually a hang because printf() may need to allocate a
    buffer, but the memory/allocator lock cannot be acquired because a
    signal handler preempts other threads (holding the lock). The process
    appears to hang, and you have to send a couple of ^C to kill it.

    Jeff

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From alain williams@3:633/10 to All on Tuesday, March 24, 2026 09:20:01
    On Tue, Mar 24, 2026 at 12:01:23AM -0400, Jeffrey Walton wrote:

    You have to be careful of what you do in a signal handler. If the
    editor is trying to log messages to a log file like, "Received SIGTERM
    on 03/23/2026 22:00:00", then things could get very tricky. That's
    because any system call made must be AS-Safe a/k/a Asynchronous Signal
    Safe. If the call is not AS-Safe, then that is Undefined Behavior
    (UB) and you should expect nasal demons.

    I am well aware of that. The signal handler code is careful to not use stdio - so thus open()/close()/write(); things like localtime() not used.

    It does use strsignal() & strerror() which I am a bit dubious about.

    It does use sprintf() (%ld) which I think should be safe.

    --
    Alain Williams
    Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
    +44 (0) 787 668 0256 https://www.phcomp.co.uk/
    Parliament Hill Computers. Registration Information: https://www.phcomp.co.uk/Contact.html
    #include <std_disclaimer.h>

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From alain williams@3:633/10 to All on Tuesday, March 24, 2026 09:20:01
    On Mon, Mar 23, 2026 at 11:38:17PM -0400, Stefan Monnier wrote:
    I removed generation of all of these messages and the recovery file is generated. So it seems that when the system is shutting down any terminal output causes the program to be immediately terminated or possibly just suspended and then later terminated.

    Or maybe the writing of the error message causes reception of
    another signal? Or it just blocks?

    I will investigate later today.

    Where is this writing taking place? From the signal handler itself?


    === Stefan


    --
    Alain Williams
    Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
    +44 (0) 787 668 0256 https://www.phcomp.co.uk/
    Parliament Hill Computers. Registration Information: https://www.phcomp.co.uk/Contact.html
    #include <std_disclaimer.h>

    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From tomas@3:633/10 to All on Tuesday, March 24, 2026 11:00:01
    On Tue, Mar 24, 2026 at 08:18:58AM +0000, alain williams wrote:
    On Mon, Mar 23, 2026 at 11:38:17PM -0400, Stefan Monnier wrote:
    I removed generation of all of these messages and the recovery file is generated. So it seems that when the system is shutting down any terminal output causes the program to be immediately terminated or possibly just suspended and then later terminated.

    Or maybe the writing of the error message causes reception of
    another signal? Or it just blocks?

    I will investigate later today.
    SIGHUP or SIGPIPE might be candidates, when disappearing I/O is involved. Cheers
    --
    t


    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Jeffrey Walton@3:633/10 to All on Tuesday, March 24, 2026 12:20:01
    On Tue, Mar 24, 2026 at 4:18?AM alain williams <addw@phcomp.co.uk> wrote:
    On Tue, Mar 24, 2026 at 12:01:23AM -0400, Jeffrey Walton wrote:

    You have to be careful of what you do in a signal handler. If the
    editor is trying to log messages to a log file like, "Received SIGTERM
    on 03/23/2026 22:00:00", then things could get very tricky. That's
    because any system call made must be AS-Safe a/k/a Asynchronous Signal Safe. If the call is not AS-Safe, then that is Undefined Behavior
    (UB) and you should expect nasal demons.

    I am well aware of that. The signal handler code is careful to not use
    stdio -
    so thus open()/close()/write(); things like localtime() not used.

    It does use strsignal() & strerror() which I am a bit dubious about.

    strsignal() and strerror() are _NOT_ AS-Safe. They are not listed under "Async-signal-safe functions" in signal(7) man page. Remove calls to them.
    It does use sprintf() (%ld) which I think should be safe.

    sprintf() is _NOT_ AS-Safe. It is not listed under "Async-signal-safe functions" in signal(7) man page. Remove calls to it.
    Jeff


    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Jeffrey Walton@3:633/10 to All on Tuesday, March 24, 2026 12:30:02
    On Tue, Mar 24, 2026 at 4:18?AM alain williams <addw@phcomp.co.uk> wrote:
    On Tue, Mar 24, 2026 at 12:01:23AM -0400, Jeffrey Walton wrote:

    You have to be careful of what you do in a signal handler. If the
    editor is trying to log messages to a log file like, "Received SIGTERM
    on 03/23/2026 22:00:00", then things could get very tricky. That's
    because any system call made must be AS-Safe a/k/a Asynchronous Signal Safe. If the call is not AS-Safe, then that is Undefined Behavior
    (UB) and you should expect nasal demons.

    I am well aware of that. The signal handler code is careful to not use
    stdio -
    so thus open()/close()/write(); things like localtime() not used.

    My bad for a second post...
    write() _IS_ AS-Signal safe. That is what you should be using.
    But _NO_ memory allocations, like could happen with printf(), sprintf() and friends. Below is some code I wrote to log a signal in a signal handler.
    It uses write(). I had to switch from printf() to write() because printf()
    was causing hangs on occasion, like during shutdown.

    It does use strsignal() & strerror() which I am a bit dubious about.

    It does use sprintf() (%ld) which I think should be safe.

    And for completeness, the other email said do not use strsignal(),
    strerror() and sprintf() in a signal handler because they are _NOT_
    AS-Signal safe.
    ----- Code -----
    /* No printf in the signal handler. Use write(2) directly */
    static void signal_callback(int sig)
    {
    int save_errno = errno;
    /* Add a \n for ^C in terminal */
    if (sig == SIGINT)
    write(STDOUT_FILENO, "\n", 1);
    if (log_level_guard(LOG_DEBUG))
    write(STDOUT_FILENO, "signal_callback\n", 16);
    g_sigval = sig;
    if (log_level_guard(LOG_INFO))
    {
    const char* sigName = signal_to_string(sig);
    size_t len=0;
    for (; sigName[len] != '\0'; ++len) {}
    write(STDOUT_FILENO, "Info: received signal ", 22);
    write(STDOUT_FILENO, sigName, len);
    write(STDOUT_FILENO, "\n", 1);
    }
    g_continue = 0;
    errno = save_errno;
    }
    const char* signal_to_string(int sig)
    {
    switch (sig)
    {
    case SIGABRT:
    return "SIGABRT";
    case SIGHUP:
    return "SIGHUP";
    case SIGINT:
    return "SIGINT";
    case SIGKILL:
    return "SIGKILL";
    case SIGCONT:
    return "SIGCONT";
    case SIGPWR:
    return "SIGPWR";
    case SIGQUIT:
    return "SIGQUIT";
    case SIGSTOP:
    return "SIGSTOP";
    case SIGTERM:
    return "SIGTERM";
    case SIGUSR1:
    return "SIGUSR1";
    case SIGUSR2:
    return "SIGUSR2";
    default:
    ;;
    }
    return "UNKNOWN";
    }
    ----- End Code -----
    Jeff


    --- PyGate Linux v1.5.13
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)