diff --git a/clients/cli/utils.c b/clients/cli/utils.c index f23e079c9635ad031e8be459fda47ae8935dbeab..b3190b085c92d70aea6328df179dc69fb357dbb0 100644 --- a/clients/cli/utils.c +++ b/clients/cli/utils.c @@ -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]); diff --git a/libnm-glib/nm-vpn-plugin-utils.c b/libnm-glib/nm-vpn-plugin-utils.c index e2bc42896c6a52c63d13bd51294c7e5ad721315d..30949d19731c593b13831b2108c63a8165aa16b6 100644 --- a/libnm-glib/nm-vpn-plugin-utils.c +++ b/libnm-glib/nm-vpn-plugin-utils.c @@ -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) { diff --git a/libnm/nm-vpn-service-plugin.c b/libnm/nm-vpn-service-plugin.c index 57b36e69b538e1191b40d2576cef7e2461524a05..5e3c0641f3de6d94d6cb95b52f4df078f70e7919 100644 --- a/libnm/nm-vpn-service-plugin.c +++ b/libnm/nm-vpn-service-plugin.c @@ -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) { diff --git a/shared/nm-utils/nm-io-utils.c b/shared/nm-utils/nm-io-utils.c index 06f756c4126888d82f3f3c2ee296d768ca69fd31..ac16ff97f261bb2ea8d86019cadbcb1e7ce7062a 100644 --- a/shared/nm-utils/nm-io-utils.c +++ b/shared/nm-utils/nm-io-utils.c @@ -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); diff --git a/shared/nm-utils/nm-shared-utils.c b/shared/nm-utils/nm-shared-utils.c index db97111193d80b3ab575339d18760e4d9942070b..860d4c18a6bcda66660784f81cf775a542131a9e 100644 --- a/shared/nm-utils/nm-shared-utils.c +++ b/shared/nm-utils/nm-shared-utils.c @@ -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) diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c index e0501a74b3634358ca5e71438646455de0a693e3..89de6e76ca7c475227f7538d84335d89fbf6be05 100644 --- a/src/devices/adsl/nm-device-adsl.c +++ b/src/devices/adsl/nm-device-adsl.c @@ -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; } diff --git a/src/devices/bluetooth/nm-bluez5-dun.c b/src/devices/bluetooth/nm-bluez5-dun.c index b85a410e8dc8df43cda53c7f8a72db095c588403..ae5efcedfcd18e7430ce5aef12da671155297617 100644 --- a/src/devices/bluetooth/nm-bluez5-dun.c +++ b/src/devices/bluetooth/nm-bluez5-dun.c @@ -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) { diff --git a/src/devices/wifi/nm-iwd-manager.c b/src/devices/wifi/nm-iwd-manager.c index c6e2d644e773dbe218f373a4652a6a66d481d2c8..d668f0d88992e67d20c3e057a2a327aa796501e1 100644 --- a/src/devices/wifi/nm-iwd-manager.c +++ b/src/devices/wifi/nm-iwd-manager.c @@ -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; } diff --git a/src/dhcp/nm-dhcp-dhclient.c b/src/dhcp/nm-dhcp-dhclient.c index 6673f9ae9a36b1246dff9a69824e9398bdb2c7ae..3a3f1feae59ed4f84a6e0ecf2f42fc7eeb43de9d 100644 --- a/src/dhcp/nm-dhcp-dhclient.c +++ b/src/dhcp/nm-dhcp-dhclient.c @@ -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); diff --git a/src/dhcp/nm-dhcp-dhcpcanon.c b/src/dhcp/nm-dhcp-dhcpcanon.c index e1495cc6cc3e4d6f71a6be2859ed8f1f831a017c..e6bd14e0555924c7586f76c85497ac0006d0988a 100644 --- a/src/dhcp/nm-dhcp-dhcpcanon.c +++ b/src/dhcp/nm-dhcp-dhcpcanon.c @@ -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; } diff --git a/src/dhcp/nm-dhcp-dhcpcd.c b/src/dhcp/nm-dhcp-dhcpcd.c index b3d87ee00aed96b9b2a299ead6ffc121a78ad90c..59ffe441320c8eec395ca05f56257c286ad8f96d 100644 --- a/src/dhcp/nm-dhcp-dhcpcd.c +++ b/src/dhcp/nm-dhcp-dhcpcd.c @@ -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... */ diff --git a/src/dhcp/nm-dhcp-utils.c b/src/dhcp/nm-dhcp-utils.c index efd8422b3619f1bd383016cc331ca7d6b4130768..3d347427cadd04095b335be999c022612804e798 100644 --- a/src/dhcp/nm-dhcp-utils.c +++ b/src/dhcp/nm-dhcp-utils.c @@ -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) diff --git a/src/dns/nm-dns-manager.c b/src/dns/nm-dns-manager.c index a6a10f59e418ff2a0325e649634d75499f6fa425..93426efda6065108dd5e2175d595468c00b4794f 100644 --- a/src/dns/nm-dns-manager.c +++ b/src/dns/nm-dns-manager.c @@ -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; diff --git a/src/initrd/nm-initrd-generator.c b/src/initrd/nm-initrd-generator.c index 70f23e17746c4f6f14594df5139d4dcda3be1505..9946be7df8023e4f9c15a861b02502ddc8faf8d4 100644 --- a/src/initrd/nm-initrd-generator.c +++ b/src/initrd/nm-initrd-generator.c @@ -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; } diff --git a/src/main-utils.c b/src/main-utils.c index 753f2c7de4afe31c36e60478ccb3fc3484c98b45..5799f095591998b5fe9b26d1c051f2a4ff5cc555 100644 --- a/src/main-utils.c +++ b/src/main-utils.c @@ -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; } diff --git a/src/main.c b/src/main.c index b52b9347c419c98193341e573d6257d855828a5d..b9cbdc44ab113da85d961e03029036fa5a426903 100644 --- a/src/main.c +++ b/src/main.c @@ -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); diff --git a/src/nm-audit-manager.c b/src/nm-audit-manager.c index 64b8b525133caafeb8e9dd2264fad20dcc4baf2c..05fc88cc2579a5e3231a775963ea9af215d83e7f 100644 --- a/src/nm-audit-manager.c +++ b/src/nm-audit-manager.c @@ -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 { diff --git a/src/nm-config-data.c b/src/nm-config-data.c index 3e75e1aa71e7a3c1efca1662276567e155efaeeb..608b7e589091cd803415458775ccbd6742f896f9 100644 --- a/src/nm-config-data.c +++ b/src/nm-config-data.c @@ -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; diff --git a/src/nm-iface-helper.c b/src/nm-iface-helper.c index 2dd606a82271bbf1e4c3f9d912d8285479201edd..a038e79e5baf180ddf801151ca4ec7068bf3d58a 100644 --- a/src/nm-iface-helper.c +++ b/src/nm-iface-helper.c @@ -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)) diff --git a/src/nm-logging.c b/src/nm-logging.c index d870732641dbb15e0cdb1e16b222af25a755fad8..fed57966a4f66cd8af5e42c1d31bb404aaf3ec8a 100644 --- a/src/nm-logging.c +++ b/src/nm-logging.c @@ -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; } /*****************************************************************************/ diff --git a/src/nm-manager.c b/src/nm-manager.c index 5f490c83a7c2b05d57e00c9997162d71a80f58fd..138cfb35fccb11225ec4435652d305d7caade3c1 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -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"); diff --git a/src/nm-policy.c b/src/nm-policy.c index 9372965f039dd797498b4ff14083aae875603153..9cdddde0082294ca47916bffd0bcf5fc71780689 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -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); diff --git a/src/nm-session-monitor.c b/src/nm-session-monitor.c index aadfa6b91d4a16960f1ffb7604d5ad6be73146fa..31810b8dc764ed0ca337d43d1d068073e85fa690 100644 --- a/src/nm-session-monitor.c +++ b/src/nm-session-monitor.c @@ -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) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 748d2c572d4b0870d80f5706bbf1f68e92165f27..5343e2a5a218982c7f2937577d008a97160fb1e3 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -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; } diff --git a/src/platform/nm-netlink.c b/src/platform/nm-netlink.c index 6abc1c3a346b6b6d05b440a749c7c01e9ef922e0..80d8b9eeb09a6da0095d0654121721bb7dda1ed2 100644 --- a/src/platform/nm-netlink.c +++ b/src/platform/nm-netlink.c @@ -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; } diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c index 75eba0ba08d3e1680aa4c9601e9937bcbda31883..b7305faa41bec47fecf1b6718b34eafd5b8f4d85 100644 --- a/src/platform/nm-platform-utils.c +++ b/src/platform/nm-platform-utils.c @@ -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; } diff --git a/src/platform/wifi/nm-wifi-utils-wext.c b/src/platform/wifi/nm-wifi-utils-wext.c index 9b8be8de6acb409880f966905b5e64f78a97fd2a..80680f56be129b548f8d5eabd815873dcf408424 100644 --- a/src/platform/wifi/nm-wifi-utils-wext.c +++ b/src/platform/wifi/nm-wifi-utils-wext.c @@ -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); diff --git a/src/ppp/nm-ppp-manager.c b/src/ppp/nm-ppp-manager.c index 2f6cb032948ee258eba5c2f9c53165dcbc3eed4c..86551fc035458610ae84e88c12a38e6356d95fd7 100644 --- a/src/ppp/nm-ppp-manager.c +++ b/src/ppp/nm-ppp-manager.c @@ -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); } /*****************************************************************************/ diff --git a/src/settings/plugins/ifcfg-rh/nm-inotify-helper.c b/src/settings/plugins/ifcfg-rh/nm-inotify-helper.c index bed127fa434ac1bb6ea53fcd410375200bc2ee61..5a16c01d5154b299967b75046a22f3be4268a410 100644 --- a/src/settings/plugins/ifcfg-rh/nm-inotify-helper.c +++ b/src/settings/plugins/ifcfg-rh/nm-inotify-helper.c @@ -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; } diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index d7fc5da1ba693d19c4d82ae4c3d44665d43e1902..2ae94e38e3130072319c29689e6494c7efcdcbb6 100644 --- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -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); diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index ac150b74f1bd4c7885d36c811c46d6c48576524c..6df75acc66b50be0be404d7ed378184383a08e4c 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -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)); diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 108e7f677e8f6321305edc5286aa4e0c68a00b11..6c30e129374658c35b687dfa8afa8729623eb2d9 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -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); diff --git a/src/settings/plugins/keyfile/tests/test-keyfile.c b/src/settings/plugins/keyfile/tests/test-keyfile.c index 15c7f5b3b102eb9df7c8e720a3abffe711ac11b8..3655563d24cd5a4d4b8b59cbcc04b6bf0f6e2890 100644 --- a/src/settings/plugins/keyfile/tests/test-keyfile.c +++ b/src/settings/plugins/keyfile/tests/test-keyfile.c @@ -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); diff --git a/src/tests/test-general-with-expect.c b/src/tests/test-general-with-expect.c index dd720ac712afd279aa1a68a420a6dfd5268198c6..8339fa5d435a69ce97fce84ade7428207e36eeb0 100644 --- a/src/tests/test-general-with-expect.c +++ b/src/tests/test-general-with-expect.c @@ -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;