summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2017-10-18 11:36:30 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2017-10-19 15:49:58 +0200
commitd29115c138dcd88172eb2668cf0a40b5bc428716 (patch)
tree165b5b868ad4b59a453b0a35c37374d49f1749c5
parent1bc1809e11759d9c0ff505f078943e73ded9db9c (diff)
downloadNetworkManager-d29115c138dcd88172eb2668cf0a40b5bc428716.tar.gz
core: use nm_close()
Use nm_close() in the core to catch any improper use of close().
-rw-r--r--src/devices/adsl/nm-device-adsl.c8
-rw-r--r--src/devices/bluetooth/nm-bluez5-dun.c4
-rw-r--r--src/dns/nm-dns-manager.c4
-rw-r--r--src/platform/nm-linux-platform.c12
-rw-r--r--src/platform/nmp-netns.c16
-rw-r--r--src/platform/wifi/wifi-utils-wext.c5
-rw-r--r--src/ppp/nm-ppp-manager.c2
-rw-r--r--src/settings/nm-inotify-helper.c3
-rw-r--r--src/settings/plugins/ifcfg-rh/shvar.c3
9 files changed, 24 insertions, 33 deletions
diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c
index feeb243d02..e9bd41ae00 100644
--- a/src/devices/adsl/nm-device-adsl.c
+++ b/src/devices/adsl/nm-device-adsl.c
@@ -227,7 +227,7 @@ br2684_assign_vcc (NMDeviceAdsl *self, NMSettingAdsl *s_adsl)
return TRUE;
error:
- close (priv->brfd);
+ nm_close (priv->brfd);
priv->brfd = -1;
return FALSE;
}
@@ -519,10 +519,8 @@ adsl_cleanup (NMDeviceAdsl *self)
g_signal_handlers_disconnect_by_func (nm_device_get_platform (NM_DEVICE (self)), G_CALLBACK (link_changed_cb), self);
- if (priv->brfd >= 0) {
- close (priv->brfd);
- priv->brfd = -1;
- }
+ nm_close (priv->brfd);
+ priv->brfd = -1;
nm_clear_g_source (&priv->nas_update_id);
diff --git a/src/devices/bluetooth/nm-bluez5-dun.c b/src/devices/bluetooth/nm-bluez5-dun.c
index aba3a0dd97..ca09b276e7 100644
--- a/src/devices/bluetooth/nm-bluez5-dun.c
+++ b/src/devices/bluetooth/nm-bluez5-dun.c
@@ -386,11 +386,11 @@ nm_bluez5_dun_cleanup (NMBluez5DunContext *context)
ioctl (context->rfcomm_fd, RFCOMMRELEASEDEV, &req);
context->rfcomm_id = -1;
}
- close (context->rfcomm_fd);
+ nm_close (context->rfcomm_fd);
context->rfcomm_fd = -1;
}
- close (context->rfcomm_tty_fd);
+ nm_close (context->rfcomm_tty_fd);
context->rfcomm_tty_fd = -1;
}
diff --git a/src/dns/nm-dns-manager.c b/src/dns/nm-dns-manager.c
index 4bce0df4ea..d5392b7d41 100644
--- a/src/dns/nm-dns-manager.c
+++ b/src/dns/nm-dns-manager.c
@@ -497,7 +497,7 @@ dispatch_netconfig (NMDnsManager *self,
g_free (str);
}
- close (fd);
+ nm_close (fd);
/* Wait until the process exits */
if (!nm_utils_kill_child_sync (pid, 0, LOGD_DNS, "netconfig", &status, 1000, 0)) {
@@ -1633,7 +1633,7 @@ _check_resconf_immutable (NMDnsManagerResolvConfManager rc_manager)
if (fd != -1) {
if (ioctl (fd, FS_IOC_GETFLAGS, &flags) != -1)
immutable = NM_FLAGS_HAS (flags, FS_IMMUTABLE_FL);
- close (fd);
+ nm_close (fd);
}
return immutable ? NM_DNS_MANAGER_RESOLV_CONF_MAN_IMMUTABLE : rc_manager;
}
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index c40a2c532b..440d2760cb 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -3019,7 +3019,7 @@ sysctl_set (NMPlatform *platform, const char *pathid, int dirfd, const char *pat
}
if (nwrote < len - 1) {
- if (close (fd) != 0) {
+ if (nm_close (fd) != 0) {
if (errsv != 0)
errno = errsv;
} else if (errsv != 0)
@@ -3028,7 +3028,7 @@ sysctl_set (NMPlatform *platform, const char *pathid, int dirfd, const char *pat
errno = EIO;
return FALSE;
}
- if (close (fd) != 0) {
+ if (nm_close (fd) != 0) {
/* errno is already properly set. */
return FALSE;
}
@@ -5601,26 +5601,26 @@ tun_add (NMPlatform *platform, const char *name, gboolean tap,
ifr.ifr_flags |= NM_IFF_MULTI_QUEUE;
if (ioctl (fd, TUNSETIFF, &ifr)) {
- close (fd);
+ nm_close (fd);
return FALSE;
}
if (owner >= 0 && owner < G_MAXINT32) {
if (ioctl (fd, TUNSETOWNER, (uid_t) owner)) {
- close (fd);
+ nm_close (fd);
return FALSE;
}
}
if (group >= 0 && group < G_MAXINT32) {
if (ioctl (fd, TUNSETGROUP, (gid_t) group)) {
- close (fd);
+ nm_close (fd);
return FALSE;
}
}
if (ioctl (fd, TUNSETPERSIST, 1)) {
- close (fd);
+ nm_close (fd);
return FALSE;
}
do_request_link (platform, 0, name);
diff --git a/src/platform/nmp-netns.c b/src/platform/nmp-netns.c
index 4acd47617c..34215828ce 100644
--- a/src/platform/nmp-netns.c
+++ b/src/platform/nmp-netns.c
@@ -299,7 +299,7 @@ _netns_new (GError **error)
g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_UNKNOWN,
"Failed opening mntns: %s",
g_strerror (errsv));
- close (fd_net);
+ nm_close (fd_net);
return NULL;
}
@@ -620,7 +620,7 @@ nmp_netns_bind_to_path (NMPNetns *self, const char *filename, int *out_fd)
filename, g_strerror (errsv));
return FALSE;
}
- close (fd);
+ nm_close (fd);
if (mount (PROC_SELF_NS_NET, filename, "none", MS_BIND, NULL) != 0) {
errsv = errno;
@@ -702,15 +702,11 @@ dispose (GObject *object)
NMPNetns *self = NMP_NETNS (object);
NMPNetnsPrivate *priv = NMP_NETNS_GET_PRIVATE (self);
- if (priv->fd_net > 0) {
- close (priv->fd_net);
- priv->fd_net = 0;
- }
+ nm_close (priv->fd_net);
+ priv->fd_net = -1;
- if (priv->fd_mnt > 0) {
- close (priv->fd_mnt);
- priv->fd_mnt = 0;
- }
+ nm_close (priv->fd_mnt);
+ priv->fd_mnt = -1;
G_OBJECT_CLASS (nmp_netns_parent_class)->dispose (object);
}
diff --git a/src/platform/wifi/wifi-utils-wext.c b/src/platform/wifi/wifi-utils-wext.c
index 1bc29ae8c3..c4d3c99962 100644
--- a/src/platform/wifi/wifi-utils-wext.c
+++ b/src/platform/wifi/wifi-utils-wext.c
@@ -97,8 +97,7 @@ wifi_wext_deinit (WifiData *parent)
{
WifiDataWext *wext = (WifiDataWext *) parent;
- if (wext->fd >= 0)
- close (wext->fd);
+ nm_close (wext->fd);
}
static gboolean
@@ -757,7 +756,7 @@ wifi_wext_is_wifi (const char *iface)
nm_utils_ifname_cpy (iwr.ifr_ifrn.ifrn_name, iface);
if (ioctl (fd, SIOCGIWNAME, &iwr) == 0)
is_wifi = TRUE;
- close (fd);
+ nm_close (fd);
}
return is_wifi;
}
diff --git a/src/ppp/nm-ppp-manager.c b/src/ppp/nm-ppp-manager.c
index 75299d1a66..3ef3f3dc84 100644
--- a/src/ppp/nm-ppp-manager.c
+++ b/src/ppp/nm-ppp-manager.c
@@ -1088,7 +1088,7 @@ _ppp_cleanup (NMPPPManager *manager)
if (priv->monitor_fd >= 0) {
/* Get the stats one last time */
monitor_cb (manager);
- close (priv->monitor_fd);
+ nm_close (priv->monitor_fd);
priv->monitor_fd = -1;
}
diff --git a/src/settings/nm-inotify-helper.c b/src/settings/nm-inotify-helper.c
index a0432a25c0..4c65b02da5 100644
--- a/src/settings/nm-inotify-helper.c
+++ b/src/settings/nm-inotify-helper.c
@@ -188,8 +188,7 @@ finalize (GObject *object)
{
NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE ((NMInotifyHelper *) object);
- if (priv->ifd >= 0)
- close (priv->ifd);
+ nm_close (priv->ifd);
g_hash_table_destroy (priv->wd_refs);
diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c
index 87fefd8db6..3c36a87191 100644
--- a/src/settings/plugins/ifcfg-rh/shvar.c
+++ b/src/settings/plugins/ifcfg-rh/shvar.c
@@ -1326,8 +1326,7 @@ svCloseFile (shvarFile *s)
g_return_if_fail (s != NULL);
- if (s->fd != -1)
- close (s->fd);
+ nm_close (s->fd);
g_free (s->fileName);
c_list_for_each_safe (current, safe, &s->lst_head)
line_free (c_list_entry (current, shvarLine, lst));