NetworkManager r4236 - in trunk: . src src/ppp-manager system-settings/plugins/ifcfg-fedora



Author: dcbw
Date: Thu Oct 30 05:52:20 2008
New Revision: 4236
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=4236&view=rev

Log:
2008-10-30  Dan Williams  <dcbw redhat com>

	* src/nm-device-ethernet.c
	  src/nm-device-wifi.c
	  src/nm-device.c
	  src/ppp-manager/nm-ppp-manager.c
		- Harmonize return checking of ioctl

	* system-settings/plugins/ifcfg-fedora/reader.c
		- (is_wireless_device): fall back to SIOCGIWNAME (rh #466340)



Modified:
   trunk/ChangeLog
   trunk/src/nm-device-ethernet.c
   trunk/src/nm-device-wifi.c
   trunk/src/nm-device.c
   trunk/src/ppp-manager/nm-ppp-manager.c
   trunk/system-settings/plugins/ifcfg-fedora/reader.c

Modified: trunk/src/nm-device-ethernet.c
==============================================================================
--- trunk/src/nm-device-ethernet.c	(original)
+++ trunk/src/nm-device-ethernet.c	Thu Oct 30 05:52:20 2008
@@ -451,7 +451,7 @@
 	strncpy (ifr.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
 	ifr.ifr_data = (char *) &edata;
 
-	if (ioctl (fd, SIOCETHTOOL, &ifr) == -1)
+	if (ioctl (fd, SIOCETHTOOL, &ifr) < 0)
 		goto out;
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
@@ -474,7 +474,7 @@
 	NMDeviceEthernet *self = NM_DEVICE_ETHERNET (dev);
 	NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
 	struct ifreq req;
-	int ret, fd;
+	int fd;
 
 	fd = socket (PF_INET, SOCK_DGRAM, 0);
 	if (fd < 0) {
@@ -484,8 +484,7 @@
 
 	memset (&req, 0, sizeof (struct ifreq));
 	strncpy (req.ifr_name, nm_device_get_iface (dev), IFNAMSIZ);
-	ret = ioctl (fd, SIOCGIFHWADDR, &req);
-	if (ret) {
+	if (ioctl (fd, SIOCGIFHWADDR, &req) < 0) {
 		nm_warning ("%s: (%s) error getting hardware address: %d",
 		            __func__, nm_device_get_iface (dev), errno);
 		goto out;
@@ -1616,7 +1615,7 @@
 	edata.cmd = ETHTOOL_GLINK;
 	ifr.ifr_data = (char *) &edata;
 
-	if (ioctl (fd, SIOCETHTOOL, &ifr) == -1)
+	if (ioctl (fd, SIOCETHTOOL, &ifr) < 0)
 		goto out;
 
 	supports_ethtool = TRUE;
@@ -1649,7 +1648,7 @@
 	mii = (struct mii_ioctl_data *) &ifr->ifr_ifru;
 	mii->reg_num = location;
 
-	if (ioctl (fd, SIOCGMIIREG, ifr) >= 0)
+	if (ioctl (fd, SIOCGMIIREG, ifr) == 0)
 		val = mii->val_out;
 
 	return val;
@@ -1658,7 +1657,7 @@
 static gboolean
 supports_mii_carrier_detect (NMDeviceEthernet *self)
 {
-	int err, fd, bmsr;
+	int fd, bmsr;
 	struct ifreq ifr;
 	gboolean supports_mii = FALSE;
 
@@ -1673,8 +1672,7 @@
 	memset (&ifr, 0, sizeof (struct ifreq));
 	strncpy (ifr.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
 
-	err = ioctl (fd, SIOCGMIIPHY, &ifr);
-	if (err < 0)
+	if (ioctl (fd, SIOCGMIIPHY, &ifr) < 0)
 		goto out;
 
 	/* If we can read the BMSR register, we assume that the card supports MII link detection */

Modified: trunk/src/nm-device-wifi.c
==============================================================================
--- trunk/src/nm-device-wifi.c	(original)
+++ trunk/src/nm-device-wifi.c	Thu Oct 30 05:52:20 2008
@@ -310,7 +310,7 @@
                     struct iw_range *range,
                     guint32 *response_len)
 {
-	int fd, err, i = 26;
+	int fd, i = 26;
 	gboolean success = FALSE;
 	const char *iface;
 	struct iwreq wrq;
@@ -336,8 +336,7 @@
 	 * see rh bz#362421)
 	 */
 	while (i-- > 0) {
-		err = ioctl (fd, SIOCGIWRANGE, &wrq);
-		if (err == 0) {
+		if (ioctl (fd, SIOCGIWRANGE, &wrq) == 0) {
 			if (response_len)
 				*response_len = wrq.u.data.length;
 			success = TRUE;
@@ -390,8 +389,7 @@
 	strncpy (wrq.ifr_name, iface, IFNAMSIZ);
 	err = ioctl (fd, SIOCSIWSCAN, &wrq);
 	close (fd);
-
-	if ((err == -1) && (errno == EOPNOTSUPP))
+	if ((err < 0) && (errno == EOPNOTSUPP))
 		caps = NM_DEVICE_CAP_NONE;
 	else
 		caps |= NM_DEVICE_CAP_NM_SUPPORTED;
@@ -1239,14 +1237,13 @@
 	iface = nm_device_get_iface (NM_DEVICE (self));
 	strncpy (wrq.ifr_name, iface, IFNAMSIZ);
 
-	if (ioctl (fd, SIOCSIWMODE, &wrq) == 0)
-		success = TRUE;
-	else {
+	if (ioctl (fd, SIOCSIWMODE, &wrq) < 0) {
 		if (errno != ENODEV) {
 			nm_warning ("error setting card %s to mode %d: %s",
 			            iface, mode, strerror (errno));
 		}
-	}
+	} else
+		success = TRUE;
 	close (fd);
 
 out:
@@ -1263,7 +1260,7 @@
 static guint32
 nm_device_wifi_get_frequency (NMDeviceWifi *self)
 {
-	int err, fd;
+	int fd;
 	guint32 freq = 0;
 	const char *iface;
 	struct iwreq wrq;
@@ -1278,11 +1275,10 @@
 	iface = nm_device_get_iface (NM_DEVICE (self));
 	strncpy (wrq.ifr_name, iface, IFNAMSIZ);
 
-	err = ioctl (fd, SIOCGIWFREQ, &wrq);
-	if (err >= 0)
-		freq = iw_freq_to_uint32 (&wrq.u.freq);
-	else if (err == -1)
+	if (ioctl (fd, SIOCGIWFREQ, &wrq) < 0)
 		nm_warning ("(%s): error getting frequency: %s", iface, strerror (errno));
+	else
+		freq = iw_freq_to_uint32 (&wrq.u.freq);
 
 	close (fd);
 	return freq;
@@ -1555,7 +1551,7 @@
 	err = ioctl (fd, SIOCGIWRATE, &wrq);
 	close (fd);
 
-	return ((err >= 0) ? wrq.u.bitrate.value / 1000 : 0);
+	return ((err == 0) ? wrq.u.bitrate.value / 1000 : 0);
 }
 
 /*
@@ -1584,7 +1580,7 @@
 
 	memset (&wrq, 0, sizeof (wrq));
 	strncpy (wrq.ifr_name, nm_device_get_iface (NM_DEVICE (self)), IFNAMSIZ);
-	if (ioctl (fd, SIOCGIWAP, &wrq) >= 0)
+	if (ioctl (fd, SIOCGIWAP, &wrq) == 0)
 		memcpy (bssid->ether_addr_octet, &(wrq.u.ap_addr.sa_data), ETH_ALEN);
 
 	close (fd);
@@ -1619,7 +1615,7 @@
 	iface = nm_device_get_iface (NM_DEVICE (self));
 	strncpy (wrq.ifr_name, iface, IFNAMSIZ);
 
-	if (ioctl (fd, SIOCSIWENCODE, &wrq) == -1) {
+	if (ioctl (fd, SIOCSIWENCODE, &wrq) < 0) {
 		if (errno != ENODEV) {
 			nm_warning ("error setting key for device %s: %s",
 			            iface, strerror (errno));
@@ -2714,7 +2710,7 @@
 	NMDeviceWifi *self = NM_DEVICE_WIFI (dev);
 	NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
 	struct ifreq req;
-	int ret, fd;
+	int fd;
 
 	fd = socket (PF_INET, SOCK_DGRAM, 0);
 	if (fd < 0) {
@@ -2724,8 +2720,7 @@
 
 	memset (&req, 0, sizeof (struct ifreq));
 	strncpy (req.ifr_name, nm_device_get_iface (dev), IFNAMSIZ);
-	ret = ioctl (fd, SIOCGIFHWADDR, &req);
-	if (ret) {
+	if (ioctl (fd, SIOCGIFHWADDR, &req) < 0) {
 		nm_warning ("%s: (%s) error getting hardware address: %d",
 		            __func__, nm_device_get_iface (dev), errno);
 		goto out;

Modified: trunk/src/nm-device.c
==============================================================================
--- trunk/src/nm-device.c	(original)
+++ trunk/src/nm-device.c	Thu Oct 30 05:52:20 2008
@@ -1970,7 +1970,7 @@
 {
 	struct ifreq req;
 	guint32 new_address;
-	int fd, err;
+	int fd;
 	
 	g_return_if_fail (self  != NULL);
 
@@ -1982,15 +1982,12 @@
 
 	memset (&req, 0, sizeof (struct ifreq));
 	strncpy (req.ifr_name, nm_device_get_ip_iface (self), IFNAMSIZ);
-	err = ioctl (fd, SIOCGIFADDR, &req);
+	if (ioctl (fd, SIOCGIFADDR, &req) == 0) {
+		new_address = ((struct sockaddr_in *)(&req.ifr_addr))->sin_addr.s_addr;
+		if (new_address != nm_device_get_ip4_address (self))
+			self->priv->ip4_address = new_address;
+	}
 	close (fd);
-
-	if (err != 0)
-		return;
-
-	new_address = ((struct sockaddr_in *)(&req.ifr_addr))->sin_addr.s_addr;
-	if (new_address != nm_device_get_ip4_address (self))
-		self->priv->ip4_address = new_address;
 }
 
 static gboolean

Modified: trunk/src/ppp-manager/nm-ppp-manager.c
==============================================================================
--- trunk/src/ppp-manager/nm-ppp-manager.c	(original)
+++ trunk/src/ppp-manager/nm-ppp-manager.c	Thu Oct 30 05:52:20 2008
@@ -306,7 +306,7 @@
 	req.stats_ptr = (caddr_t) &req.stats;
 
 	strncpy (req.ifr__name, priv->ip_iface, sizeof (req.ifr__name));
-	if (!ioctl (priv->monitor_fd, SIOCGPPPSTATS, &req) < 0)
+	if (ioctl (priv->monitor_fd, SIOCGPPPSTATS, &req) < 0)
 		nm_warning ("Could not read ppp stats: %s", strerror (errno));
 	else
 		g_signal_emit (manager, signals[STATS], 0, 

Modified: trunk/system-settings/plugins/ifcfg-fedora/reader.c
==============================================================================
--- trunk/system-settings/plugins/ifcfg-fedora/reader.c	(original)
+++ trunk/system-settings/plugins/ifcfg-fedora/reader.c	Thu Oct 30 05:52:20 2008
@@ -880,17 +880,14 @@
 }
 
 static gboolean
-is_wireless_device (const char *iface, gboolean *is_wireless)
+is_wireless_device (const char *iface)
 {
 	int fd;
 	struct iw_range range;
 	struct iwreq wrq;
-	gboolean success = FALSE;
+	gboolean is_wireless = FALSE;
 
 	g_return_val_if_fail (iface != NULL, FALSE);
-	g_return_val_if_fail (is_wireless != NULL, FALSE);
-
-	*is_wireless = FALSE;
 
 	fd = socket(AF_INET, SOCK_DGRAM, 0);
 	if (!fd)
@@ -902,18 +899,25 @@
 	wrq.u.data.pointer = (caddr_t) &range;
 	wrq.u.data.length = sizeof (struct iw_range);
 
-	if (ioctl (fd, SIOCGIWRANGE, &wrq) < 0) {
+	if (ioctl (fd, SIOCGIWRANGE, &wrq) == 0)
+		is_wireless = TRUE;
+	else {
 		if (errno == EOPNOTSUPP)
-			success = TRUE;
-		goto out;
+			is_wireless = FALSE;
+		else {
+			/* Sigh... some wired devices (kvm/qemu) return EINVAL when the
+			 * device is down even though it's not a wireless device.  So try
+			 * IWNAME as a fallback.
+			 */
+			memset (&wrq, 0, sizeof (struct iwreq));
+			strncpy (wrq.ifr_name, iface, IFNAMSIZ);
+			if (ioctl (fd, SIOCGIWNAME, &wrq) == 0)
+				is_wireless = TRUE;
+		}
 	}
 
-	*is_wireless = TRUE;
-	success = TRUE;
-
-out:
 	close (fd);
-	return success;
+	return is_wireless;
 }
 
 NMConnection *
@@ -953,7 +957,6 @@
 	type = svGetValue (parsed, "TYPE");
 	if (!type) {
 		char *device;
-		gboolean is_wireless = FALSE;
 
 		/* If no type, if the device has wireless extensions, it's wifi,
 		 * otherwise it's ethernet.
@@ -973,15 +976,7 @@
 		}
 
 		/* Test wireless extensions */
-		if (!is_wireless_device (device, &is_wireless)) {
-			g_set_error (error, ifcfg_plugin_error_quark (), 0,
-			             "File '%s' specified device '%s', but the device's "
-			             "type could not be determined.", filename, device);
-			g_free (device);
-			goto done;
-		}
-
-		if (is_wireless)
+		if (is_wireless_device (device))
 			type = g_strdup (TYPE_WIRELESS);
 		else
 			type = g_strdup (TYPE_ETHERNET);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]