Hook for `_exit'

Florian Weimer fweimer@redhat.com
Fri Aug 5 08:22:11 GMT 2022


* Po Lu via Libc-alpha:

> I'd like to ask for a hook run before _exit kills the current thread.
> The reason for requesting such a hook is that badly behaved libraries
> such as GTK call _exit when the display connection is lost, without
> leaving programs a chance to perform cleanup, such as saving files that
> the user was working on.
>
> AFAIR, the GTK developers have already mentioned that they are unwilling
> to add such a hook on their end (especially to GTK 3, which is no longer
> receiving new features), and the chance of updated GTK versions getting
> to users is exceedingly slim.
>
> A real life example of this problem would be:
>
>   https://lists.gnu.org/archive/html/bug-gnu-emacs/2022-08/msg00433.html
>
> Where a user experienced a display disconnect, and as a result lost all
> of his work with no clear indication of what happened.

I think even if we add the hook in glibc, GTK will find a way to
terminate the process immediately by other means.  We already have exit,
yet GTK deliberately chose not to use it.  So it doesn't look like
something that can be solved with an in-process hook.

If you need to use a library with such an approach to error handling,
but you want to recover from errors, you need to use fork and confine
its use to a subprocess, and employ some IPC mechanism to maintain
relevant state in a more persistent process (or keep a redo log in the
file system).

Thanks,
Florian



More information about the Libc-alpha mailing list