|
Message-ID: <20220216194020.GA16437@voyager> Date: Wed, 16 Feb 2022 20:40:20 +0100 From: Markus Wichmann <nullplan@....net> To: musl@...ts.openwall.com Subject: Is errno signal-safe? 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
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.