GNOME Bugzilla – Bug 741791
gmain: Save errno when handling unix signals
Last modified: 2015-03-20 17:33:05 UTC
This is a real problem. I tested this on glibc/Linux with the following program: void handler (int sig) { errno = 5432; } int main (void) { signal (SIGINT, handler); errno = 1234; raise (SIGINT); printf ("%d\n", errno); return 0; } and main() prints out the value of errno that was set from the handler.
Created attachment 293110 [details] [review] gmain: Save errno when handling unix signals Our signal handler calls write() on a pipe or an eventfd in order to deliver the notification. It's unlikely, but this could fail, setting errno. We even check the case that it fails with EINTR. If it does set errno, then it has potentially blown away the value or errno that the preempted code cared about (ie: if the signal arrived shortly after a system call but before errno was checked). Wrap the handler with code to save errno.
Review of attachment 293110 [details] [review]: I see no error.
Attachment 293110 [details] pushed as 7c70377 - gmain: Save errno when handling unix signals