From: Markus Wichmann <nullplan@gmx.net>
To: musl@lists.openwall.com
Subject: [musl] Is errno signal-safe?
Date: Wed, 16 Feb 2022 20:40:20 +0100 [thread overview]
Message-ID: <20220216194020.GA16437@voyager> (raw)
Hi all,
today I had a flash of inspiration while staring at some code: errno is
a global variable, right? OK, it is thread-local, but still a global
variable in the context of one thread. And looking at a global variable
while it may (or may not) be modified in a signal handler is not safe to
do.
So now I have to wonder. There are a bunch of functions that set errno,
that are on the ostensibly async-signal-safe list, like for example
write(). And to my knowledge, changes to errno are not turned back by
sigreturn(). So, are changes to errno made in a signal handler
propagated to the main program? If so, how do I inspect errno correctly
in the main program? I could block signals, but for one thing, doing so
every time errno might be relevant is going to be overkill, and for two,
if the system call I want the errno from is also blocking and I want to
allow signals while the call is blocking, there is no way to do that
without race condition.
But then again, now that I thought of it, this is so obvious that surely
someone else must have stumbled across it before, right? A solution must
exist, right?
Ciao,
Markus
next reply other threads:[~2022-02-16 19:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-16 19:40 Markus Wichmann [this message]
2022-02-16 19:56 ` Carlos O'Donell
2022-02-16 21:01 ` Florian Weimer
2022-02-16 21:02 ` Carlos O'Donell
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220216194020.GA16437@voyager \
--to=nullplan@gmx.net \
--cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).