After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 741791 - gmain: Save errno when handling unix signals
gmain: Save errno when handling unix signals
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: mainloop
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2014-12-19 22:11 UTC by Allison Karlitskaya (desrt)
Modified: 2015-03-20 17:33 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gmain: Save errno when handling unix signals (1.18 KB, patch)
2014-12-19 22:11 UTC, Allison Karlitskaya (desrt)
committed Details | Review

Description Allison Karlitskaya (desrt) 2014-12-19 22:11:45 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.
Comment 1 Allison Karlitskaya (desrt) 2014-12-19 22:11:47 UTC
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.
Comment 2 Colin Walters 2014-12-19 23:10:26 UTC
Review of attachment 293110 [details] [review]:

I see no error.
Comment 3 Allison Karlitskaya (desrt) 2015-03-20 17:33:02 UTC
Attachment 293110 [details] pushed as 7c70377 - gmain: Save errno when handling unix signals