From: Mikael Djurfeldt <mikael@djurfeldt.com>
To: Mailer <vine24683579@gmail.com>
Cc: guile-devel <guile-devel@gnu.org>,
Mikael Djurfeldt <mikael@djurfeldt.com>
Subject: Re: [PATCH] At-exit hook
Date: Thu, 7 Nov 2024 14:28:46 +0100 [thread overview]
Message-ID: <CAA2Xvw+1V-dYKyBLSr_kEaD+KNzyddULTfL7mjRWUFKw_w3WQA@mail.gmail.com> (raw)
In-Reply-To: <20241107122700.b37d3e8d2c1c09203147117e@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2267 bytes --]
OK, so people have brought up two issues:
1. It is for various reasons not recommended to call atexit() from a
dynamically linked library (which Guile already does before my suggested
change, n.b.).
2. It is not async signal safe.
A suggested remedy would then be:
Instead of calling the at-exit-hook from really_cleanup_for_exit, we could
call it (still within an scm_with_guile) from the end of scm_boot_guile(),
just before exit(), with the disadvantage that it wouldn't be called if
main_func() calls exit on its own. It's kind of a pity that we didn't early
on introduce some kind of scm_finalize_guile() which the user would have to
call when done with the library...
And, well, perhaps we should block asyncs, but I don't know about signals
with this new setup.
Best regards,
Mikael
On Thu, Nov 7, 2024 at 1:26 PM Mailer <vine24683579@gmail.com> wrote:
> On Thu, 7 Nov 2024 12:09:25 +0000
> Mailer <vine24683579@gmail.com> wrote:
> > On Thu, 7 Nov 2024 12:23:08 +0100
> > Maxime Devos <maximedevos@telenet.be> wrote:
> > > ‘atexit’ functions are run at ‘exit’. ‘exit’ can be run from signal
> > > handlers (*). Since the hook runs Scheme code, it could do a lot of
> > > AC-unsafe things, resulting in problems.
> > >
> > > (*) glibc documentation says ‘exit’ is AC-unsafe, but this is
> > > unsupported by POSIX AFAICT. OTOH the same applies to even ‘malloc’,
> > > so likely I’m looking in the wrong places.
> >
> > I think you meant async-signal-safe (AS-safe). 'exit' is not a-s-s and
> > cannot be called in a signal handler (for example it can flush buffers)
> > whereas '_exit' is a-s-s. Furthermore a registered handler cannot
> > itself safely call 'exit'.
> >
> > I believe the main reason that use of 'atexit' or 'on_exit' is
> > discouraged is that it does not handle abnormal process termination.
> > (Registered handlers also don't run on termination by '_exit', but that
> > is usually what you want.)
>
> I believe also that use of 'atexit' is discouraged in dynamically linked
> libraries because of the uncertain timing of the unloading of the
> library, but I think in fact glibc is OK with this, so I guess it may
> depend on your libc.
>
> Chris
>
>
[-- Attachment #2: Type: text/html, Size: 3042 bytes --]
next prev parent reply other threads:[~2024-11-07 13:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-06 19:52 [PATCH] At-exit hook Mikael Djurfeldt
2024-11-07 11:23 ` Maxime Devos
2024-11-07 12:08 ` Nala Ginrut
2024-11-07 12:09 ` Mailer
2024-11-07 12:27 ` Mailer
2024-11-07 13:28 ` Mikael Djurfeldt [this message]
2024-11-07 16:10 ` Maxime Devos
2024-11-07 19:51 ` Mailer
2024-11-07 22:18 ` Maxime Devos
2024-11-08 9:09 ` Mikael Djurfeldt
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/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAA2Xvw+1V-dYKyBLSr_kEaD+KNzyddULTfL7mjRWUFKw_w3WQA@mail.gmail.com \
--to=mikael@djurfeldt.com \
--cc=guile-devel@gnu.org \
--cc=vine24683579@gmail.com \
/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.
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).