summaryrefslogtreecommitdiff
path: root/gio/gunixfdmessage.c
diff options
context:
space:
mode:
authorPhilip Withnall <withnall@endlessm.com>2017-07-31 11:30:55 +0100
committerPhilip Withnall <withnall@endlessm.com>2017-08-03 10:21:13 +0100
commit5cddde1fb2b8466d8104595008eafabd0728de5d (patch)
treeea3f201272ca80118baee43c0a72babfc51244e6 /gio/gunixfdmessage.c
parent41a4a70b433fc5a1e7b0c536fdd3d32a9c214219 (diff)
downloadglib-5cddde1fb2b8466d8104595008eafabd0728de5d.tar.gz
Consistently save errno immediately after the operation setting it
Prevent the situation where errno is set by function A, then function B is called (which is typically _(), but could be anything else) and it overwrites errno, then errno is checked by the caller. errno is a horrific API, and we need to be careful to save its value as soon as a function call (which might set it) returns. i.e. Follow the pattern: int errsv, ret; ret = some_call_which_might_set_errno (); errsv = errno; if (ret < 0) puts (strerror (errsv)); This patch implements that pattern throughout GLib. There might be a few places in the test code which still use errno directly. They should be ported as necessary. It doesn’t modify all the call sites like this: if (some_call_which_might_set_errno () && errno == ESOMETHING) since the refactoring involved is probably more harmful than beneficial there. It does, however, refactor other call sites regardless of whether they were originally buggy. https://bugzilla.gnome.org/show_bug.cgi?id=785577
Diffstat (limited to 'gio/gunixfdmessage.c')
-rw-r--r--gio/gunixfdmessage.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/gio/gunixfdmessage.c b/gio/gunixfdmessage.c
index 581670328..b80283b0b 100644
--- a/gio/gunixfdmessage.c
+++ b/gio/gunixfdmessage.c
@@ -110,14 +110,19 @@ g_unix_fd_message_deserialize (int level,
*/
for (i = 0; i < n; i++)
{
+ int errsv;
+
do
- s = fcntl (fds[i], F_SETFD, FD_CLOEXEC);
- while (s < 0 && errno == EINTR);
+ {
+ s = fcntl (fds[i], F_SETFD, FD_CLOEXEC);
+ errsv = errno;
+ }
+ while (s < 0 && errsv == EINTR);
if (s < 0)
{
g_warning ("Error setting close-on-exec flag on incoming fd: %s",
- g_strerror (errno));
+ g_strerror (errsv));
return NULL;
}
}