mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-02 07:23:41 +02:00
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
This commit is contained in:
@@ -497,11 +497,12 @@ g_unix_connection_receive_credentials (GUnixConnection *connection,
|
||||
&opt_val,
|
||||
NULL))
|
||||
{
|
||||
int errsv = errno;
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
g_io_error_from_errno (errno),
|
||||
g_io_error_from_errno (errsv),
|
||||
_("Error checking if SO_PASSCRED is enabled for socket: %s"),
|
||||
g_strerror (errno));
|
||||
g_strerror (errsv));
|
||||
goto out;
|
||||
}
|
||||
if (opt_val == 0)
|
||||
@@ -512,11 +513,12 @@ g_unix_connection_receive_credentials (GUnixConnection *connection,
|
||||
TRUE,
|
||||
NULL))
|
||||
{
|
||||
int errsv = errno;
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
g_io_error_from_errno (errno),
|
||||
g_io_error_from_errno (errsv),
|
||||
_("Error enabling SO_PASSCRED: %s"),
|
||||
g_strerror (errno));
|
||||
g_strerror (errsv));
|
||||
goto out;
|
||||
}
|
||||
turn_off_so_passcreds = TRUE;
|
||||
@@ -605,11 +607,12 @@ g_unix_connection_receive_credentials (GUnixConnection *connection,
|
||||
FALSE,
|
||||
NULL))
|
||||
{
|
||||
int errsv = errno;
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
g_io_error_from_errno (errno),
|
||||
g_io_error_from_errno (errsv),
|
||||
_("Error while disabling SO_PASSCRED: %s"),
|
||||
g_strerror (errno));
|
||||
g_strerror (errsv));
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user