From: Mailer <vine24683579@gmail.com>
To: guile-devel <guile-devel@gnu.org>
Subject: Re: [PATCH] At-exit hook
Date: Thu, 7 Nov 2024 19:51:57 +0000 [thread overview]
Message-ID: <20241107195157.5a8cad633d4370bf4c48f21f@gmail.com> (raw)
In-Reply-To: <20241107171045.ZsAk2D00S42S6aw01sAkk9@laurent.telenet-ops.be>
On Thu, 7 Nov 2024 17:10:45 +0100
Maxime Devos <maximedevos@telenet.be> 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'. […]
>
> No, I did mean exactly what I wrote. Read the glibc documentation of ‘exit’ and you’ll see. (Likewise for the POSIX page for ‘exit’ – POSIX does not seem to restrict things to _outside_ signal handlers.)
>
> Also, when two authorative sources (POSIX and glibc in this case) have contrary claims, then simply repeating one of those claim does not help at all, you would need to explain the cause of the discrepancy instead.
>
> That ‘exit’ flushes buffers does not imply that ‘exit’ is async-unsafe, alternatives include buffer flushing being safe, ‘exit’ having its own implementation of flushing that is AC-safe, or ‘you may call ‘exit’ but only if no files (as in FILE*) are open’.
>
> Best regards,
> Maxime Devos
You have lost me. "AC-safe" means async-cancel-safe. It is irrelevant:
1. Only three POSIX functions are async cancelation safe, namely
pthread_cancel, pthread_setcancelstate, and pthread_setcanceltype. See
the POSIX standard of 2017 (the only one I have to hand), General
Information, paragraph 2.9.5, Async-Cancel Safety: "No other functions
in this volume of POSIX.1-2017 are required to be async-cancel-safe."
The GNU documentation says the same.
2. No one ever uses asynchronous cancelation anyway, partly because of
that. Deferred thread cancelation at safe cancelation points is the
only cancelation used in practice.
3. AC-Safety has no bearing on the current discussion in any case.
On Async-Signal Safety, whatever you may say, 'exit' is not on the
POSIX list of async-signal-safe functions. See the POSIX standard of
2017, General Information, paragraph 2.4.3, Signal Actions: "Any
function not in the above table may be unsafe with respect to
signals." Do 'man 7 signal-safety', also at
https://man7.org/linux/man-pages/man7/signal-safety.7.html, to see your
implementation's list, which includes '_exit' but not 'exit' (on my
distribution), thus conforming with POSIX.
AS-Safety is probably also irrelevant because as I understand it guile
implements its own deferred signal delivery with asyncs, which may or
not permit guile's exit to be invoked in an async handler (I have never
examined it to find out). POSIX and glibc documentation is not
authoritative on that.
Chris
next prev parent reply other threads:[~2024-11-07 19:51 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
2024-11-07 16:10 ` Maxime Devos
2024-11-07 19:51 ` Mailer [this message]
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=20241107195157.5a8cad633d4370bf4c48f21f@gmail.com \
--to=vine24683579@gmail.com \
--cc=guile-devel@gnu.org \
/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).