all: cache errno in local variable before using it

This commit is contained in:
Thomas Haller
2019-01-31 13:29:21 +01:00
parent b7bb744973
commit 047998f80a
34 changed files with 217 additions and 147 deletions

View File

@@ -1426,19 +1426,20 @@ pager_fallback (void)
{
char buf[64];
int rb;
int errsv;
do {
rb = read (STDIN_FILENO, buf, sizeof (buf));
if (rb == -1) {
if (errno == EINTR) {
errsv = errno;
if (errsv == EINTR)
continue;
} else {
g_printerr (_("Error reading nmcli output: %s\n"), strerror (errno));
_exit(EXIT_FAILURE);
}
g_printerr (_("Error reading nmcli output: %s\n"), strerror (errsv));
_exit(EXIT_FAILURE);
}
if (write (STDOUT_FILENO, buf, rb) == -1) {
g_printerr (_("Error writing nmcli output: %s\n"), strerror (errno));
errsv = errno;
g_printerr (_("Error writing nmcli output: %s\n"), strerror (errsv));
_exit(EXIT_FAILURE);
}
} while (rb > 0);
@@ -1453,6 +1454,7 @@ nmc_terminal_spawn_pager (const NmcConfig *nmc_config)
pid_t pager_pid;
pid_t parent_pid;
int fd[2];
int errsv;
if ( nmc_config->in_editor
|| nmc_config->print_output == NMC_PRINT_TERSE
@@ -1462,7 +1464,8 @@ nmc_terminal_spawn_pager (const NmcConfig *nmc_config)
return 0;
if (pipe (fd) == -1) {
g_printerr (_("Failed to create pager pipe: %s\n"), strerror (errno));
errsv = errno;
g_printerr (_("Failed to create pager pipe: %s\n"), strerror (errsv));
return 0;
}
@@ -1470,7 +1473,8 @@ nmc_terminal_spawn_pager (const NmcConfig *nmc_config)
pager_pid = fork ();
if (pager_pid == -1) {
g_printerr (_("Failed to fork pager: %s\n"), strerror (errno));
errsv = errno;
g_printerr (_("Failed to fork pager: %s\n"), strerror (errsv));
nm_close (fd[0]);
nm_close (fd[1]);
return 0;
@@ -1515,10 +1519,14 @@ nmc_terminal_spawn_pager (const NmcConfig *nmc_config)
}
/* Return in the parent */
if (dup2 (fd[1], STDOUT_FILENO) < 0)
g_printerr (_("Failed to duplicate pager pipe: %s\n"), strerror (errno));
if (dup2 (fd[1], STDERR_FILENO) < 0)
g_printerr (_("Failed to duplicate pager pipe: %s\n"), strerror (errno));
if (dup2 (fd[1], STDOUT_FILENO) < 0) {
errsv = errno;
g_printerr (_("Failed to duplicate pager pipe: %s\n"), strerror (errsv));
}
if (dup2 (fd[1], STDERR_FILENO) < 0) {
errsv = errno;
g_printerr (_("Failed to duplicate pager pipe: %s\n"), strerror (errsv));
}
nm_close (fd[0]);
nm_close (fd[1]);

View File

@@ -82,7 +82,6 @@ nm_vpn_plugin_utils_read_vpn_details (int fd,
ssize_t nr;
GHashTable *hash = NULL;
errno = 0;
nr = read (fd, &c, 1);
if (nr == -1) {
if (errno == EAGAIN) {

View File

@@ -807,7 +807,6 @@ nm_vpn_service_plugin_read_vpn_details (int fd,
while (1) {
ssize_t nr;
errno = 0;
nr = read (fd, &c, 1);
if (nr < 0) {
if (errno == EAGAIN) {

View File

@@ -36,10 +36,11 @@ _nm_printf (3, 4)
static int
_get_contents_error (GError **error, int errsv, const char *format, ...)
{
if (errsv < 0)
errsv = -errsv;
else if (!errsv)
errsv = errno;
if (errsv < 0) {
errsv = errsv == G_MININT
? G_MAXINT
: -errsv;
}
if (error) {
char *msg;
@@ -57,6 +58,12 @@ _get_contents_error (GError **error, int errsv, const char *format, ...)
}
return -errsv;
}
#define _get_contents_error_errno(error, ...) \
({ \
int _errsv = (errno); \
\
_get_contents_error (error, _errsv, __VA_ARGS__); \
})
static char *
_mem_realloc (char *old, gboolean do_bzero_mem, gsize cur_len, gsize new_len)
@@ -127,13 +134,14 @@ nm_utils_fd_get_contents (int fd,
struct stat stat_buf;
gs_free char *str = NULL;
const bool do_bzero_mem = NM_FLAGS_HAS (flags, NM_UTILS_FILE_GET_CONTENTS_FLAG_SECRET);
int errsv;
g_return_val_if_fail (fd >= 0, -EINVAL);
g_return_val_if_fail (contents, -EINVAL);
g_return_val_if_fail (!error || !*error, -EINVAL);
if (fstat (fd, &stat_buf) < 0)
return _get_contents_error (error, 0, "failure during fstat");
return _get_contents_error_errno (error, "failure during fstat");
if (!max_length) {
/* default to a very large size, but not extreme */
@@ -156,7 +164,7 @@ nm_utils_fd_get_contents (int fd,
if (n_read < 0) {
if (do_bzero_mem)
nm_explicit_bzero (str, n_stat);
return _get_contents_error (error, n_read, "error reading %zu bytes from file descriptor", n_stat);
return _get_contents_error (error, -n_read, "error reading %zu bytes from file descriptor", n_stat);
}
str[n_read] = '\0';
@@ -176,19 +184,19 @@ nm_utils_fd_get_contents (int fd,
else {
fd2 = fcntl (fd, F_DUPFD_CLOEXEC, 0);
if (fd2 < 0)
return _get_contents_error (error, 0, "error during dup");
return _get_contents_error_errno (error, "error during dup");
}
if (!(f = fdopen (fd2, "r"))) {
errsv = errno;
nm_close (fd2);
return _get_contents_error (error, 0, "failure during fdopen");
return _get_contents_error (error, errsv, "failure during fdopen");
}
n_have = 0;
n_alloc = 0;
while (!feof (f)) {
int errsv;
gsize n_read;
n_read = fread (buf, 1, sizeof (buf), f);
@@ -395,20 +403,21 @@ nm_utils_file_set_contents (const char *filename,
* guarantee the data is written to the disk before the metadata.)
*/
if ( lstat (filename, &statbuf) == 0
&& statbuf.st_size > 0
&& fsync (fd) != 0) {
errsv = errno;
&& statbuf.st_size > 0) {
if (fsync (fd) != 0) {
errsv = errno;
nm_close (fd);
unlink (tmp_name);
nm_close (fd);
unlink (tmp_name);
g_set_error (error,
G_FILE_ERROR,
g_file_error_from_errno (errsv),
"failed to fsync %s: %s",
tmp_name,
g_strerror (errsv));
return FALSE;
g_set_error (error,
G_FILE_ERROR,
g_file_error_from_errno (errsv),
"failed to fsync %s: %s",
tmp_name,
g_strerror (errsv));
return FALSE;
}
}
nm_close (fd);

View File

@@ -1769,10 +1769,12 @@ nm_utils_fd_read_loop (int fd, void *buf, size_t nbytes, bool do_poll)
k = read (fd, p, nbytes);
if (k < 0) {
if (errno == EINTR)
int errsv = errno;
if (errsv == EINTR)
continue;
if (errno == EAGAIN && do_poll) {
if (errsv == EAGAIN && do_poll) {
/* We knowingly ignore any return value here,
* and expect that any error/EOF is reported
@@ -1782,7 +1784,7 @@ nm_utils_fd_read_loop (int fd, void *buf, size_t nbytes, bool do_poll)
continue;
}
return n > 0 ? n : -errno;
return n > 0 ? n : -errsv;
}
if (k == 0)

View File

@@ -369,8 +369,8 @@ br2684_create_iface (NMDeviceAdsl *self,
priv->nas_update_id = g_timeout_add (100, nas_update_cb, self);
return NM_ACT_STAGE_RETURN_POSTPONE;
}
if (errno != EEXIST) {
errsv = errno;
errsv = errno;
if (errsv != EEXIST) {
_LOGW (LOGD_ADSL, "failed to create br2684 interface (%d)", errsv);
break;
}

View File

@@ -56,6 +56,7 @@ dun_connect (NMBluez5DunContext *context)
char tty[100];
const int ttylen = sizeof (tty) - 1;
GError *error = NULL;
int errsv;
struct rfcomm_dev_req req = {
.flags = (1 << RFCOMM_REUSE_DLC) | (1 << RFCOMM_RELEASE_ONHUP),
@@ -65,7 +66,7 @@ dun_connect (NMBluez5DunContext *context)
context->rfcomm_fd = socket (AF_BLUETOOTH, SOCK_STREAM | SOCK_CLOEXEC, BTPROTO_RFCOMM);
if (context->rfcomm_fd < 0) {
int errsv = errno;
errsv = errno;
error = g_error_new (NM_BT_ERROR, NM_BT_ERROR_DUN_CONNECT_FAILED,
"Failed to create RFCOMM socket: (%d) %s",
errsv, strerror (errsv));
@@ -77,7 +78,7 @@ dun_connect (NMBluez5DunContext *context)
sa.rc_channel = 0;
memcpy (&sa.rc_bdaddr, &context->src, ETH_ALEN);
if (bind (context->rfcomm_fd, (struct sockaddr *) &sa, sizeof(sa))) {
int errsv = errno;
errsv = errno;
error = g_error_new (NM_BT_ERROR, NM_BT_ERROR_DUN_CONNECT_FAILED,
"Failed to bind socket: (%d) %s",
errsv, strerror (errsv));
@@ -87,7 +88,7 @@ dun_connect (NMBluez5DunContext *context)
sa.rc_channel = context->rfcomm_channel;
memcpy (&sa.rc_bdaddr, &context->dst, ETH_ALEN);
if (connect (context->rfcomm_fd, (struct sockaddr *) &sa, sizeof (sa)) ) {
int errsv = errno;
errsv = errno;
error = g_error_new (NM_BT_ERROR, NM_BT_ERROR_DUN_CONNECT_FAILED,
"Failed to connect to remote device: (%d) %s",
errsv, strerror (errsv));
@@ -102,7 +103,7 @@ dun_connect (NMBluez5DunContext *context)
memcpy (&req.dst, &context->dst, ETH_ALEN);
devid = ioctl (context->rfcomm_fd, RFCOMMCREATEDEV, &req);
if (devid < 0) {
int errsv = errno;
errsv = errno;
error = g_error_new (NM_BT_ERROR, NM_BT_ERROR_DUN_CONNECT_FAILED,
"Failed to create rfcomm device: (%d) %s",
errsv, strerror (errsv));
@@ -249,7 +250,8 @@ sdp_connect_watch (GIOChannel *channel, GIOCondition condition, gpointer user_da
sdp_list_t *search, *attrs;
uuid_t svclass;
uint16_t attr;
int fd, err, fd_err = 0;
int fd, fd_err = 0;
int err;
socklen_t len = sizeof (fd_err);
GError *error = NULL;
@@ -257,13 +259,13 @@ sdp_connect_watch (GIOChannel *channel, GIOCondition condition, gpointer user_da
fd = g_io_channel_unix_get_fd (channel);
if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &fd_err, &len) < 0) {
nm_log_dbg (LOGD_BT, "(%s -> %s): getsockopt error=%d",
context->src_str, context->dst_str, errno);
err = errno;
nm_log_dbg (LOGD_BT, "(%s -> %s): getsockopt error=%d",
context->src_str, context->dst_str, err);
} else {
err = fd_err;
nm_log_dbg (LOGD_BT, "(%s -> %s): SO_ERROR error=%d",
context->src_str, context->dst_str, fd_err);
err = fd_err;
}
if (err != 0) {

View File

@@ -136,6 +136,7 @@ agent_dbus_method_cb (GDBusConnection *connection,
int ifindex;
NMDevice *device;
gs_free char *name_owner = NULL;
int errsv;
/* Be paranoid and check the sender address */
name_owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (priv->object_manager));
@@ -171,8 +172,9 @@ agent_dbus_method_cb (GDBusConnection *connection,
ifindex = if_nametoindex (ifname);
if (!ifindex) {
errsv = errno;
_LOGD ("agent-request: if_nametoindex failed for Name %s for Device at %s: %i",
ifname, device_path, errno);
ifname, device_path, errsv);
goto return_error;
}
@@ -338,6 +340,7 @@ set_device_dbus_object (NMIwdManager *self, GDBusProxy *proxy,
const char *ifname;
int ifindex;
NMDevice *device;
int errsv;
ifname = get_property_string_or_null (proxy, "Name");
if (!ifname) {
@@ -349,8 +352,9 @@ set_device_dbus_object (NMIwdManager *self, GDBusProxy *proxy,
ifindex = if_nametoindex (ifname);
if (!ifindex) {
errsv = errno;
_LOGE ("if_nametoindex failed for Name %s for Device at %s: %i",
ifname, g_dbus_proxy_get_object_path (proxy), errno);
ifname, g_dbus_proxy_get_object_path (proxy), errsv);
return;
}

View File

@@ -591,16 +591,18 @@ stop (NMDhcpClient *client, gboolean release)
{
NMDhcpDhclient *self = NM_DHCP_DHCLIENT (client);
NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (self);
int errsv;
NM_DHCP_CLIENT_CLASS (nm_dhcp_dhclient_parent_class)->stop (client, release);
if (priv->conf_file)
if (remove (priv->conf_file) == -1)
_LOGD ("could not remove dhcp config file \"%s\": %d (%s)", priv->conf_file, errno, g_strerror (errno));
if (remove (priv->conf_file) == -1) {
errsv = errno;
_LOGD ("could not remove dhcp config file \"%s\": %d (%s)", priv->conf_file, errsv, g_strerror (errsv));
}
if (priv->pid_file) {
if (remove (priv->pid_file) == -1) {
int errsv = errno;
errsv = errno;
_LOGD ("could not remove dhcp pid file \"%s\": %s (%d)", priv->pid_file, g_strerror (errsv), errsv);
}
nm_clear_g_free (&priv->pid_file);

View File

@@ -203,12 +203,15 @@ stop (NMDhcpClient *client, gboolean release)
{
NMDhcpDhcpcanon *self = NM_DHCP_DHCPCANON (client);
NMDhcpDhcpcanonPrivate *priv = NM_DHCP_DHCPCANON_GET_PRIVATE (self);
int errsv;
NM_DHCP_CLIENT_CLASS (nm_dhcp_dhcpcanon_parent_class)->stop (client, release);
if (priv->pid_file) {
if (remove (priv->pid_file) == -1)
_LOGD ("could not remove dhcp pid file \"%s\": %d (%s)", priv->pid_file, errno, g_strerror (errno));
if (remove (priv->pid_file) == -1) {
errsv = errno;
_LOGD ("could not remove dhcp pid file \"%s\": %d (%s)", priv->pid_file, errsv, g_strerror (errsv));
}
g_free (priv->pid_file);
priv->pid_file = NULL;
}

View File

@@ -197,12 +197,15 @@ stop (NMDhcpClient *client, gboolean release)
{
NMDhcpDhcpcd *self = NM_DHCP_DHCPCD (client);
NMDhcpDhcpcdPrivate *priv = NM_DHCP_DHCPCD_GET_PRIVATE (self);
int errsv;
NM_DHCP_CLIENT_CLASS (nm_dhcp_dhcpcd_parent_class)->stop (client, release);
if (priv->pid_file) {
if (remove (priv->pid_file) == -1)
_LOGD ("could not remove dhcp pid file \"%s\": %d (%s)", priv->pid_file, errno, g_strerror (errno));
if (remove (priv->pid_file) == -1) {
errsv = errno;
_LOGD ("could not remove dhcp pid file \"%s\": %d (%s)", priv->pid_file, errsv, g_strerror (errsv));
}
}
/* FIXME: implement release... */

View File

@@ -544,7 +544,7 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
errno = 0;
int_mtu = strtol (str, NULL, 10);
if ((errno == EINVAL) || (errno == ERANGE))
if (NM_IN_SET (errno, EINVAL, ERANGE))
goto error;
if (int_mtu > 576)

View File

@@ -535,6 +535,7 @@ dispatch_netconfig (NMDnsManager *self,
{
GPid pid;
int fd;
int errsv;
int status;
gssize l;
nm_auto_free_gstring GString *str = NULL;
@@ -565,8 +566,7 @@ again:
/* Wait until the process exits */
if (!nm_utils_kill_child_sync (pid, 0, LOGD_DNS, "netconfig", &status, 1000, 0)) {
int errsv = errno;
errsv = errno;
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED,
"Error waiting for netconfig to exit: %s",
strerror (errsv));
@@ -708,7 +708,8 @@ dispatch_resolvconf (NMDnsManager *self,
gs_free char *cmd = NULL;
FILE *f;
gboolean success = FALSE;
int errnosv, err;
int errsv;
int err;
char *argv[] = { RESOLVCONF_PATH, "-d", "NetworkManager", NULL };
int status;
@@ -742,12 +743,13 @@ dispatch_resolvconf (NMDnsManager *self,
cmd = g_strconcat (RESOLVCONF_PATH, " -a ", "NetworkManager", NULL);
if ((f = popen (cmd, "w")) == NULL) {
errsv = errno;
g_set_error (error,
NM_MANAGER_ERROR,
NM_MANAGER_ERROR_FAILED,
"Could not write to %s: %s",
RESOLVCONF_PATH,
g_strerror (errno));
g_strerror (errsv));
return SR_ERROR;
}
@@ -758,10 +760,10 @@ dispatch_resolvconf (NMDnsManager *self,
error);
err = pclose (f);
if (err < 0) {
errnosv = errno;
errsv = errno;
g_clear_error (error);
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errnosv),
"Failed to close pipe to resolvconf: %d", errnosv);
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
"Failed to close pipe to resolvconf: %d", errsv);
return SR_ERROR;
} else if (err > 0) {
_LOGW ("resolvconf failed with status %d", err);
@@ -924,7 +926,7 @@ update_resolv_conf (NMDnsManager *self,
NM_MANAGER_ERROR_FAILED,
"Could not replace %s: %s",
MY_RESOLV_CONF,
g_strerror (errno));
g_strerror (errsv));
_LOGT ("update-resolv-conf: failed to rename temporary file %s to %s (%s)",
MY_RESOLV_CONF_TMP, MY_RESOLV_CONF, g_strerror (errsv));
return SR_ERROR;

View File

@@ -92,6 +92,7 @@ main (int argc, char *argv[])
};
GOptionContext *option_context;
GError *error = NULL;
int errsv;
option_context = g_option_context_new ("-- [ip=...] [rd.route=...] [bridge=...] [bond=...] [team=...] [vlan=...] "
"[bootdev=...] [nameserver=...] [rd.peerdns=...] [rd.bootif=...] [BOOTIF=...] ... ");
@@ -121,7 +122,8 @@ main (int argc, char *argv[])
g_clear_pointer (&connections_dir, g_free);
if (connections_dir && g_mkdir_with_parents (connections_dir, 0755) != 0) {
_LOGW (LOGD_CORE, "%s: %s", connections_dir, strerror (errno));
errsv = errno;
_LOGW (LOGD_CORE, "%s: %s", connections_dir, strerror (errsv));
return 1;
}

View File

@@ -92,21 +92,26 @@ nm_main_utils_write_pidfile (const char *pidfile)
{
char pid[16];
int fd;
int errsv;
gboolean success = FALSE;
if ((fd = open (pidfile, O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC, 00644)) < 0) {
fprintf (stderr, _("Opening %s failed: %s\n"), pidfile, strerror (errno));
errsv = errno;
fprintf (stderr, _("Opening %s failed: %s\n"), pidfile, strerror (errsv));
return FALSE;
}
g_snprintf (pid, sizeof (pid), "%d", getpid ());
if (write (fd, pid, strlen (pid)) < 0)
fprintf (stderr, _("Writing to %s failed: %s\n"), pidfile, strerror (errno));
else
if (write (fd, pid, strlen (pid)) < 0) {
errsv = errno;
fprintf (stderr, _("Writing to %s failed: %s\n"), pidfile, strerror (errsv));
} else
success = TRUE;
if (nm_close (fd))
fprintf (stderr, _("Closing %s failed: %s\n"), pidfile, strerror (errno));
if (nm_close (fd)) {
errsv = errno;
fprintf (stderr, _("Closing %s failed: %s\n"), pidfile, strerror (errsv));
}
return success;
}

View File

@@ -230,6 +230,7 @@ main (int argc, char *argv[])
guint sd_id = 0;
GError *error_invalid_logging_config = NULL;
const char *const *warnings;
int errsv;
/* Known to cause a possible deadlock upon GDBus initialization:
* https://bugzilla.gnome.org/show_bug.cgi?id=674885 */
@@ -331,12 +332,10 @@ main (int argc, char *argv[])
if (global_opt.become_daemon && !nm_config_get_is_debug (config)) {
if (daemon (0, 0) < 0) {
int saved_errno;
saved_errno = errno;
errsv = errno;
fprintf (stderr, _("Could not daemonize: %s [error %u]\n"),
g_strerror (saved_errno),
saved_errno);
g_strerror (errsv),
errsv);
exit (1);
}
wrote_pidfile = nm_main_utils_write_pidfile (global_opt.pidfile);

View File

@@ -335,15 +335,17 @@ init_auditd (NMAuditManager *self)
{
NMAuditManagerPrivate *priv = NM_AUDIT_MANAGER_GET_PRIVATE (self);
NMConfigData *data = nm_config_get_data (priv->config);
int errsv;
if (nm_config_data_get_value_boolean (data, NM_CONFIG_KEYFILE_GROUP_LOGGING,
NM_CONFIG_KEYFILE_KEY_LOGGING_AUDIT,
NM_CONFIG_DEFAULT_LOGGING_AUDIT_BOOL)) {
if (priv->auditd_fd < 0) {
priv->auditd_fd = audit_open ();
if (priv->auditd_fd < 0)
_LOGE (LOGD_CORE, "failed to open auditd socket: %s", strerror (errno));
else
if (priv->auditd_fd < 0) {
errsv = errno;
_LOGE (LOGD_CORE, "failed to open auditd socket: %s", strerror (errsv));
} else
_LOGD (LOGD_CORE, "socket created");
}
} else {

View File

@@ -216,7 +216,6 @@ nm_config_data_get_value_int64 (const NMConfigData *self, const char *group, con
str = nm_config_keyfile_get_value (NM_CONFIG_DATA_GET_PRIVATE (self)->keyfile, group, key, NM_CONFIG_GET_VALUE_NONE);
val = _nm_utils_ascii_str_to_int64 (str, base, min, max, fallback);
if (str) {
/* preserve errno from the parsing. */
errsv = errno;
g_free (str);
errno = errsv;

View File

@@ -387,6 +387,7 @@ main (int argc, char *argv[])
gs_unref_bytes GBytes *client_id = NULL;
gs_free NMUtilsIPv6IfaceId *iid = NULL;
guint sd_id;
int errsv;
c_list_init (&gl.dad_failed_lst_head);
@@ -423,7 +424,8 @@ main (int argc, char *argv[])
gl.ifindex = nmp_utils_if_nametoindex (global_opt.ifname);
if (gl.ifindex <= 0) {
fprintf (stderr, _("Failed to find interface index for %s (%s)\n"), global_opt.ifname, strerror (errno));
errsv = errno;
fprintf (stderr, _("Failed to find interface index for %s (%s)\n"), global_opt.ifname, strerror (errsv));
return 1;
}
pidfile = g_strdup_printf (NMIH_PID_FILE_FMT, gl.ifindex);
@@ -448,12 +450,10 @@ main (int argc, char *argv[])
if (global_opt.become_daemon && !global_opt.debug) {
if (daemon (0, 0) < 0) {
int saved_errno;
saved_errno = errno;
errsv = errno;
fprintf (stderr, _("Could not daemonize: %s [error %u]\n"),
g_strerror (saved_errno),
saved_errno);
g_strerror (errsv),
errsv);
return 1;
}
if (nm_main_utils_write_pidfile (pidfile))

View File

@@ -680,7 +680,7 @@ _nm_log_impl (const char *file,
va_list args;
char *msg;
GTimeVal tv;
int errno_saved;
int errsv;
const NMLogDomain *cur_log_state;
NMLogDomain cur_log_state_copy[_LOGL_N_REAL];
Global g_copy;
@@ -710,7 +710,7 @@ _nm_log_impl (const char *file,
(void) cur_log_state;
errno_saved = errno;
errsv = errno;
/* Make sure that %m maps to the specified error */
if (error != 0) {
@@ -833,7 +833,7 @@ _nm_log_impl (const char *file,
g_free (msg);
errno = errno_saved;
errno = errsv;
}
/*****************************************************************************/

View File

@@ -7184,10 +7184,10 @@ rfkill_change (NMManager *self, const char *desc, RfKillType rtype, gboolean ena
int fd;
struct rfkill_event event;
ssize_t len;
int errsv;
g_return_if_fail (rtype == RFKILL_TYPE_WLAN || rtype == RFKILL_TYPE_WWAN);
errno = 0;
fd = open ("/dev/rfkill", O_RDWR | O_CLOEXEC);
if (fd < 0) {
if (errno == EACCES)
@@ -7218,8 +7218,9 @@ rfkill_change (NMManager *self, const char *desc, RfKillType rtype, gboolean ena
len = write (fd, &event, sizeof (event));
if (len < 0) {
errsv = errno;
_LOGW (LOGD_RFKILL, "rfkill: (%s): failed to change Wi-Fi killswitch state: (%d) %s",
desc, errno, g_strerror (errno));
desc, errsv, g_strerror (errsv));
} else if (len == sizeof (event)) {
_LOGI (LOGD_RFKILL, "rfkill: %s hardware radio set %s",
desc, enabled ? "enabled" : "disabled");

View File

@@ -506,13 +506,13 @@ settings_set_hostname_cb (const char *hostname,
NMPolicy *self = NM_POLICY (user_data);
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
int ret = 0;
int errsv;
if (!result) {
_LOGT (LOGD_DNS, "set-hostname: hostname set via dbus failed, fallback to \"sethostname\"");
ret = sethostname (hostname, strlen (hostname));
if (ret != 0) {
int errsv = errno;
errsv = errno;
_LOGW (LOGD_DNS, "set-hostname: couldn't set the system hostname to '%s': (%d) %s",
hostname, errsv, strerror (errsv));
if (errsv == EPERM)
@@ -533,6 +533,7 @@ _get_hostname (NMPolicy *self)
{
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self);
char *hostname = NULL;
int errsv;
/* If there is an in-progress hostname change, return
* the last hostname set as would be set soon...
@@ -551,8 +552,7 @@ _get_hostname (NMPolicy *self)
/* ...or retrieve it by yourself */
hostname = g_malloc (HOST_NAME_BUFSIZE);
if (gethostname (hostname, HOST_NAME_BUFSIZE -1) != 0) {
int errsv = errno;
errsv = errno;
_LOGT (LOGD_DNS, "get-hostname: couldn't get the system hostname: (%d) %s",
errsv, g_strerror (errsv));
g_free (hostname);

View File

@@ -204,13 +204,15 @@ static gboolean
ck_update_cache (NMSessionMonitor *monitor)
{
struct stat statbuf;
int errsv;
if (!monitor->ck.cache)
return FALSE;
/* Check the database file */
if (stat (CKDB_PATH, &statbuf) != 0) {
_LOGE ("failed to check ConsoleKit timestamp: %s", strerror (errno));
errsv = errno;
_LOGE ("failed to check ConsoleKit timestamp: %s", strerror (errsv));
return FALSE;
}
if (statbuf.st_mtime == monitor->ck.timestamp)

View File

@@ -5022,7 +5022,7 @@ _nl_send_nlmsghdr (NMPlatform *platform,
{
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
guint32 seq;
int nle;
int errsv;
nm_assert (nlhdr);
@@ -5051,13 +5051,13 @@ _nl_send_nlmsghdr (NMPlatform *platform,
try_count = 0;
again:
nle = sendmsg (nl_socket_get_fd (priv->nlh), &msg, 0);
if (nle < 0) {
nle = errno;
if (nle == EINTR && try_count++ < 100)
errsv = sendmsg (nl_socket_get_fd (priv->nlh), &msg, 0);
if (errsv < 0) {
errsv = errno;
if (errsv == EINTR && try_count++ < 100)
goto again;
_LOGD ("netlink: nl-send-nlmsghdr: failed sending message: %s (%d)", g_strerror (nle), nle);
return -nle;
_LOGD ("netlink: nl-send-nlmsghdr: failed sending message: %s (%d)", g_strerror (errsv), errsv);
return -nm_errno_from_native (errsv);
}
}
@@ -6096,6 +6096,7 @@ link_set_sriov_params (NMPlatform *platform,
gint64 current_num;
char ifname[IFNAMSIZ];
char buf[64];
int errsv;
if (!nm_platform_netns_push (platform, &netns))
return FALSE;
@@ -6143,7 +6144,8 @@ link_set_sriov_params (NMPlatform *platform,
ifname,
"device/sriov_numvfs"),
"0")) {
_LOGW ("link: couldn't reset SR-IOV num_vfs: %s", strerror (errno));
errsv = errno;
_LOGW ("link: couldn't reset SR-IOV num_vfs: %s", strerror (errsv));
return FALSE;
}
}
@@ -6158,7 +6160,8 @@ link_set_sriov_params (NMPlatform *platform,
ifname,
"device/sriov_drivers_autoprobe"),
nm_sprintf_buf (buf, "%d", (int) autoprobe))) {
_LOGW ("link: couldn't set SR-IOV drivers-autoprobe to %d: %s", (int) autoprobe, strerror (errno));
errsv = errno;
_LOGW ("link: couldn't set SR-IOV drivers-autoprobe to %d: %s", (int) autoprobe, strerror (errsv));
return FALSE;
}
@@ -6167,7 +6170,8 @@ link_set_sriov_params (NMPlatform *platform,
ifname,
"device/sriov_numvfs"),
nm_sprintf_buf (buf, "%u", num_vfs))) {
_LOGW ("link: couldn't set SR-IOV num_vfs to %d: %s", num_vfs, strerror (errno));
errsv = errno;
_LOGW ("link: couldn't set SR-IOV num_vfs to %d: %s", num_vfs, strerror (errsv));
return FALSE;
}

View File

@@ -1333,6 +1333,7 @@ nl_recv (struct nl_sock *sk,
struct ucred tmpcreds;
gboolean tmpcreds_has = FALSE;
int retval;
int errsv;
nm_assert (nla);
nm_assert (buf && !*buf);
@@ -1361,10 +1362,10 @@ retry:
}
if (n < 0) {
if (errno == EINTR)
errsv = errno;
if (errsv == EINTR)
goto retry;
retval = -nm_errno_from_native (errno);
retval = -nm_errno_from_native (errsv);
goto abort;
}

View File

@@ -1043,6 +1043,7 @@ nmp_utils_mii_supports_carrier_detect (int ifindex)
int r;
struct ifreq ifr;
struct mii_ioctl_data *mii;
int errsv;
g_return_val_if_fail (ifindex > 0, FALSE);
@@ -1057,7 +1058,8 @@ nmp_utils_mii_supports_carrier_detect (int ifindex)
memcpy (ifr.ifr_name, shandle.ifname, IFNAMSIZ);
if (ioctl (shandle.fd, SIOCGMIIPHY, &ifr) < 0) {
nm_log_trace (LOGD_PLATFORM, "mii[%d,%s]: carrier-detect no: SIOCGMIIPHY failed: %s", ifindex, shandle.ifname, strerror (errno));
errsv = errno;
nm_log_trace (LOGD_PLATFORM, "mii[%d,%s]: carrier-detect no: SIOCGMIIPHY failed: %s", ifindex, shandle.ifname, strerror (errsv));
return FALSE;
}
@@ -1066,7 +1068,8 @@ nmp_utils_mii_supports_carrier_detect (int ifindex)
mii->reg_num = MII_BMSR;
if (ioctl (shandle.fd, SIOCGMIIREG, &ifr) != 0) {
nm_log_trace (LOGD_PLATFORM, "mii[%d,%s]: carrier-detect no: SIOCGMIIREG failed: %s", ifindex, shandle.ifname, strerror (errno));
errsv = errno;
nm_log_trace (LOGD_PLATFORM, "mii[%d,%s]: carrier-detect no: SIOCGMIIREG failed: %s", ifindex, shandle.ifname, strerror (errsv));
return FALSE;
}

View File

@@ -127,15 +127,17 @@ wifi_wext_get_mode_ifname (NMWifiUtils *data, const char *ifname)
{
NMWifiUtilsWext *wext = (NMWifiUtilsWext *) data;
struct iwreq wrq;
int errsv;
memset (&wrq, 0, sizeof (struct iwreq));
nm_utils_ifname_cpy (wrq.ifr_name, ifname);
if (ioctl (wext->fd, SIOCGIWMODE, &wrq) < 0) {
if (errno != ENODEV) {
errsv = errno;
if (errsv != ENODEV) {
_LOGW (LOGD_PLATFORM | LOGD_WIFI,
"(%s): error %d getting card mode",
ifname, errno);
ifname, errsv);
}
return NM_802_11_MODE_UNKNOWN;
}
@@ -504,10 +506,10 @@ wifi_wext_set_mesh_ssid (NMWifiUtils *data, const guint8 *ssid, gsize len)
if (ioctl (wext->fd, SIOCSIWESSID, &wrq) == 0)
return TRUE;
if (errno != ENODEV) {
errsv = errno;
if (errsv != ENODEV) {
gs_free char *ssid_str = NULL;
errsv = errno;
_LOGE (LOGD_PLATFORM | LOGD_WIFI | LOGD_OLPC,
"(%s): error setting SSID to %s: %s",
ifname,
@@ -543,6 +545,7 @@ wext_get_range_ifname (NMWifiUtilsWext *wext,
int i = 26;
gboolean success = FALSE;
struct iwreq wrq;
int errsv;
memset (&wrq, 0, sizeof (struct iwreq));
nm_utils_ifname_cpy (wrq.ifr_name, ifname);
@@ -559,11 +562,14 @@ wext_get_range_ifname (NMWifiUtilsWext *wext,
*response_len = wrq.u.data.length;
success = TRUE;
break;
} else if (errno != EAGAIN) {
_LOGE (LOGD_PLATFORM | LOGD_WIFI,
"(%s): couldn't get driver range information (%d).",
ifname, errno);
break;
} else {
errsv = errno;
if (errsv != EAGAIN) {
_LOGE (LOGD_PLATFORM | LOGD_WIFI,
"(%s): couldn't get driver range information (%d).",
ifname, errsv);
break;
}
}
g_usleep (G_USEC_PER_SEC / 4);

View File

@@ -180,6 +180,7 @@ monitor_cb (gpointer user_data)
NMPPPManager *self = NM_PPP_MANAGER (user_data);
NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self);
const char *ifname;
int errsv;
ifname = nm_platform_link_get_name (NM_PLATFORM_GET, priv->ifindex);
@@ -191,8 +192,9 @@ monitor_cb (gpointer user_data)
nm_utils_ifname_cpy (req.ifr_name, ifname);
if (ioctl (priv->monitor_fd, SIOCGPPPSTATS, &req) < 0) {
if (errno != ENODEV)
_LOGW ("could not read ppp stats: %s", strerror (errno));
errsv = errno;
if (errsv != ENODEV)
_LOGW ("could not read ppp stats: %s", strerror (errsv));
} else {
g_signal_emit (self, signals[STATS], 0,
(guint) stats.p.ppp_ibytes,
@@ -207,19 +209,23 @@ static void
monitor_stats (NMPPPManager *self)
{
NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self);
int errsv;
/* already monitoring */
if (priv->monitor_fd >= 0)
return;
priv->monitor_fd = socket (AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (priv->monitor_fd >= 0) {
g_warn_if_fail (priv->monitor_id == 0);
if (priv->monitor_id)
g_source_remove (priv->monitor_id);
priv->monitor_id = g_timeout_add_seconds (5, monitor_cb, self);
} else
_LOGW ("could not monitor PPP stats: %s", strerror (errno));
if (priv->monitor_fd < 0) {
errsv = errno;
_LOGW ("could not monitor PPP stats: %s", strerror (errsv));
return;
}
g_warn_if_fail (priv->monitor_id == 0);
if (priv->monitor_id)
g_source_remove (priv->monitor_id);
priv->monitor_id = g_timeout_add_seconds (5, monitor_cb, self);
}
/*****************************************************************************/

View File

@@ -141,11 +141,11 @@ init_inotify (NMInotifyHelper *self)
{
NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE (self);
GIOChannel *channel;
int errsv;
priv->ifd = inotify_init1 (IN_CLOEXEC);
if (priv->ifd == -1) {
int errsv = errno;
errsv = errno;
nm_log_warn (LOGD_SETTINGS, "couldn't initialize inotify: %s (%d)", strerror (errsv), errsv);
return FALSE;
}

View File

@@ -3949,9 +3949,8 @@ make_wireless_setting (shvarFile *ifcfg,
value = svGetValueStr_cp (ifcfg, "CHANNEL");
if (value) {
errno = 0;
chan = _nm_utils_ascii_str_to_int64 (value, 10, 1, 196, 0);
if (errno || (chan == 0)) {
if (chan == 0) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid wireless channel '%s'", value);
g_free (value);

View File

@@ -1315,21 +1315,20 @@ svWriteFile (shvarFile *s, int mode, GError **error)
FILE *f;
int tmpfd;
CList *current;
int errsv;
if (s->modified) {
if (s->fd == -1)
s->fd = open (s->fileName, O_WRONLY | O_CREAT | O_CLOEXEC, mode);
if (s->fd == -1) {
int errsv = errno;
errsv = errno;
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errsv),
"Could not open file '%s' for writing: %s",
s->fileName, strerror (errsv));
return FALSE;
}
if (ftruncate (s->fd, 0) < 0) {
int errsv = errno;
errsv = errno;
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errsv),
"Could not overwrite file '%s': %s",
s->fileName, strerror (errsv));
@@ -1338,8 +1337,7 @@ svWriteFile (shvarFile *s, int mode, GError **error)
tmpfd = fcntl (s->fd, F_DUPFD_CLOEXEC, 0);
if (tmpfd == -1) {
int errsv = errno;
errsv = errno;
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errsv),
"Internal error writing file '%s': %s",
s->fileName, strerror (errsv));

View File

@@ -10019,10 +10019,14 @@ NMTST_DEFINE ();
int main (int argc, char **argv)
{
int errsv;
nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT");
if (g_mkdir_with_parents (TEST_SCRATCH_DIR_TMP, 0755) != 0)
g_error ("failure to create test directory \"%s\": %s", TEST_SCRATCH_DIR_TMP, g_strerror (errno));
if (g_mkdir_with_parents (TEST_SCRATCH_DIR_TMP, 0755) != 0) {
errsv = errno;
g_error ("failure to create test directory \"%s\": %s", TEST_SCRATCH_DIR_TMP, g_strerror (errsv));
}
g_test_add_func (TPATH "svUnescape", test_svUnescape);

View File

@@ -2614,11 +2614,16 @@ NMTST_DEFINE ();
int main (int argc, char **argv)
{
int errsv;
_nm_utils_set_testing (NM_UTILS_TEST_NO_KEYFILE_OWNER_CHECK);
nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT");
if (g_mkdir_with_parents (TEST_SCRATCH_DIR, 0755) != 0)
g_error ("failure to create test directory \"%s\": %s", TEST_SCRATCH_DIR, g_strerror (errno));
if (g_mkdir_with_parents (TEST_SCRATCH_DIR, 0755) != 0) {
errsv = errno;
g_error ("failure to create test directory \"%s\": %s", TEST_SCRATCH_DIR, g_strerror (errsv));
}
/* The tests */
g_test_add_func ("/keyfile/test_read_valid_wired_connection", test_read_valid_wired_connection);

View File

@@ -40,7 +40,8 @@ test_nm_utils_monotonic_timestamp_as_boottime (void)
clockid_t clockid;
guint i;
if (clock_gettime (CLOCK_BOOTTIME, &tp) != 0 && errno == EINVAL)
if ( clock_gettime (CLOCK_BOOTTIME, &tp) != 0
&& errno == EINVAL)
clockid = CLOCK_MONOTONIC;
else
clockid = CLOCK_BOOTTIME;