On Mon, Mar 23, 2026 at 7:04 PM alain williams <[email protected]> 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 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 ?
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

