From 33aec50e5066729467f6bbe25f257449f51b75d3 Mon Sep 17 00:00:00 2001 From: Robert Love Date: Thu, 25 May 2006 22:37:41 +0000 Subject: [PATCH] 2006-05-25 Robert Love * src/nm-device.h: Introduce nm_ioctl_info(), which defines to nm_info() if IOCTL_DEBUG is set and a no-op if not. We can use this instead of dumping ifdef's throughout the code. * src/NetworkManagerSystem.c, src/nm-device-802-11-wireless.c, src/nm-device-802-3-ethernet.c, src/nm-device.c: Remove ifdef's and use nm_ioctl_info() in lieu. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1768 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 9 +++++ src/NetworkManagerSystem.c | 24 +++--------- src/nm-device-802-11-wireless.c | 67 ++++++++++++--------------------- src/nm-device-802-3-ethernet.c | 26 ++++--------- src/nm-device.c | 20 ++++------ src/nm-device.h | 11 +++++- 6 files changed, 66 insertions(+), 91 deletions(-) diff --git a/ChangeLog b/ChangeLog index d6d9896c63..3a6832f62b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-05-25 Robert Love + + * src/nm-device.h: Introduce nm_ioctl_info(), which defines to + nm_info() if IOCTL_DEBUG is set and a no-op if not. We can use this + instead of dumping ifdef's throughout the code. + * src/NetworkManagerSystem.c, src/nm-device-802-11-wireless.c, + src/nm-device-802-3-ethernet.c, src/nm-device.c: Remove ifdef's and + use nm_ioctl_info() in lieu. + 2006-05-25 Robert Love Patch Valentine Sinitsyn to fix GNOME bug #342400: diff --git a/src/NetworkManagerSystem.c b/src/NetworkManagerSystem.c index 036b2ce1d6..b1e28b784d 100644 --- a/src/NetworkManagerSystem.c +++ b/src/NetworkManagerSystem.c @@ -99,13 +99,9 @@ static gboolean nm_system_device_set_ip4_route (NMDevice *dev, int ip4_gateway, rtent.rt_mtu = mss; } -#ifdef IOCTL_DEBUG - nm_info ("%s: About to CADDRT\n", nm_device_get_iface (dev)); -#endif + nm_ioctl_info ("%s: About to CADDRT\n", nm_device_get_iface (dev)); err = ioctl (nm_dev_sock_get_fd (sk), SIOCADDRT, &rtent); -#ifdef IOCTL_DEBUG - nm_info ("%s: About to CADDRT\n", nm_device_get_iface (dev)); -#endif + nm_ioctl_info ("%s: About to CADDRT\n", nm_device_get_iface (dev)); if (err == -1) { @@ -132,23 +128,15 @@ static gboolean nm_system_device_set_ip4_route (NMDevice *dev, int ip4_gateway, rtent2.rt_mtu = mss; } -#ifdef IOCTL_DEBUG - nm_info ("%s: About to CADDRT (2)\n", nm_device_get_iface (dev)); -#endif + nm_ioctl_info ("%s: About to CADDRT (2)\n", nm_device_get_iface (dev)); err = ioctl (nm_dev_sock_get_fd (sk), SIOCADDRT, &rtent2); -#ifdef IOCTL_DEBUG - nm_info ("%s: About to CADDRT (2)\n", nm_device_get_iface (dev)); -#endif + nm_ioctl_info ("%s: About to CADDRT (2)\n", nm_device_get_iface (dev)); if (!err) { -#ifdef IOCTL_DEBUG - nm_info ("%s: About to CADDRT (3)\n", nm_device_get_iface (dev)); -#endif + nm_ioctl_info ("%s: About to CADDRT (3)\n", nm_device_get_iface (dev)); err = ioctl (nm_dev_sock_get_fd (sk), SIOCADDRT, &rtent); -#ifdef IOCTL_DEBUG - nm_info ("%s: About to CADDRT (3)\n", nm_device_get_iface (dev)); -#endif + nm_ioctl_info ("%s: About to CADDRT (3)\n", nm_device_get_iface (dev)); if (!err) success = TRUE; diff --git a/src/nm-device-802-11-wireless.c b/src/nm-device-802-11-wireless.c index dddc00f3b7..549f79c75e 100644 --- a/src/nm-device-802-11-wireless.c +++ b/src/nm-device-802-11-wireless.c @@ -235,13 +235,11 @@ nm_device_802_11_wireless_update_signal_strength (NMDevice80211Wireless *self) memset (&range, 0, sizeof (iwrange)); memset (&stats, 0, sizeof (iwstats)); -#ifdef IOCTL_DEBUG - nm_info ("%s: About to GET 'iwrange'.", iface); -#endif + + nm_ioctl_info ("%s: About to GET 'iwrange'.", iface); has_range = (iw_get_range_info (nm_dev_sock_get_fd (sk), iface, &range) >= 0); -#ifdef IOCTL_DEBUG - nm_info ("%s: About to GET 'iwstats'.", iface); -#endif + nm_ioctl_info ("%s: About to GET 'iwstats'.", iface); + if (iw_get_stats (nm_dev_sock_get_fd (sk), iface, &stats, &range, has_range) == 0) { percent = wireless_qual_to_percent (&stats.qual, (const iwqual *)(&self->priv->max_qual), @@ -1161,9 +1159,9 @@ nm_device_802_11_wireless_get_mode (NMDevice80211Wireless *self) struct iwreq wrq; memset (&wrq, 0, sizeof (struct iwreq)); -#ifdef IOCTL_DEBUG - nm_info ("%s: About to GET IWMODE.", nm_device_get_iface (NM_DEVICE (self))); -#endif + + nm_ioctl_info ("%s: About to GET IWMODE.", nm_device_get_iface (NM_DEVICE (self))); + if (iw_get_ext (nm_dev_sock_get_fd (sk), nm_device_get_iface (NM_DEVICE (self)), SIOCGIWMODE, &wrq) == 0) { if ((mode == IW_MODE_ADHOC) || (mode == IW_MODE_INFRA)) @@ -1206,9 +1204,9 @@ nm_device_802_11_wireless_set_mode (NMDevice80211Wireless *self, const char * iface = nm_device_get_iface (NM_DEVICE (self)); struct iwreq wreq; -#ifdef IOCTL_DEBUG - nm_info ("%s: About to SET IWMODE.", iface); -#endif + + nm_ioctl_info ("%s: About to SET IWMODE.", iface); + wreq.u.mode = mode; if (iw_set_ext (nm_dev_sock_get_fd (sk), iface, SIOCSIWMODE, &wreq) == 0) success = TRUE; @@ -1387,9 +1385,8 @@ nm_device_802_11_wireless_get_essid (NMDevice80211Wireless *self) { wireless_config info; -#ifdef IOCTL_DEBUG - nm_info ("%s: About to GET 'basic config' for ESSID.", iface); -#endif + nm_ioctl_info ("%s: About to GET 'basic config' for ESSID.", iface); + err = iw_get_basic_config (nm_dev_sock_get_fd (sk), iface, &info); if (err >= 0) { @@ -1445,9 +1442,8 @@ nm_device_802_11_wireless_set_essid (NMDevice80211Wireless *self, wreq.u.essid.length = len + 1; wreq.u.essid.flags = (len > 0) ? 1 : 0; /* 1=enable ESSID, 0=disable/any */ -#ifdef IOCTL_DEBUG - nm_info ("%s: About to SET IWESSID.", iface); -#endif + nm_ioctl_info ("%s: About to SET IWESSID.", iface); + if ((err = iw_set_ext (nm_dev_sock_get_fd (sk), iface, SIOCSIWESSID, &wreq)) == -1) { if (errno != ENODEV) @@ -1492,9 +1488,8 @@ nm_device_802_11_wireless_get_frequency (NMDevice80211Wireless *self) { struct iwreq wrq; -#ifdef IOCTL_DEBUG - nm_info ("%s: About to GET IWFREQ.", iface); -#endif + nm_ioctl_info ("%s: About to GET IWFREQ.", iface); + err = iw_get_ext (nm_dev_sock_get_fd (sk), iface, SIOCGIWFREQ, &wrq); if (err >= 0) freq = iw_freq2float (&wrq.u.freq); @@ -1565,9 +1560,9 @@ nm_device_802_11_wireless_set_frequency (NMDevice80211Wireless *self, wrq.u.freq.flags = IW_FREQ_FIXED; iw_float2freq (freq, &wrq.u.freq); } -#ifdef IOCTL_DEBUG - nm_info ("%s: About to SET IWFREQ.", iface); -#endif + + nm_ioctl_info ("%s: About to SET IWFREQ.", iface); + if ((err = iw_set_ext (nm_dev_sock_get_fd (sk), iface, SIOCSIWFREQ, &wrq)) == -1) { gboolean success = FALSE; @@ -1607,9 +1602,7 @@ nm_device_802_11_wireless_get_bitrate (NMDevice80211Wireless *self) iface = nm_device_get_iface (NM_DEVICE (self)); if ((sk = nm_dev_sock_open (NM_DEVICE (self), DEV_WIRELESS, __FUNCTION__, NULL))) { -#ifdef IOCTL_DEBUG - nm_info ("%s: About to GET IWRATE.", iface); -#endif + nm_ioctl_info ("%s: About to GET IWRATE.", iface); err = iw_get_ext (nm_dev_sock_get_fd (sk), iface, SIOCGIWRATE, &wrq); nm_dev_sock_close (sk); } @@ -1654,9 +1647,7 @@ nm_device_802_11_wireless_set_bitrate (NMDevice80211Wireless *self, wrq.u.bitrate.fixed = 0; } /* Silently fail as not all drivers support setting bitrate yet (ipw2x00 for example) */ -#ifdef IOCTL_DEBUG - nm_info ("%s: About to SET IWRATE.", iface); -#endif + nm_ioctl_info ("%s: About to SET IWRATE.", iface); iw_set_ext (nm_dev_sock_get_fd (sk), iface, SIOCSIWRATE, &wrq); nm_dev_sock_close (sk); @@ -1687,9 +1678,7 @@ nm_device_802_11_wireless_get_bssid (NMDevice80211Wireless *self, iface = nm_device_get_iface (NM_DEVICE (self)); if ((sk = nm_dev_sock_open (NM_DEVICE (self), DEV_WIRELESS, __FUNCTION__, NULL))) { -#ifdef IOCTL_DEBUG - nm_info ("%s: About to GET IWAP.", iface); -#endif + nm_ioctl_info ("%s: About to GET IWAP.", iface); if (iw_get_ext (nm_dev_sock_get_fd (sk), iface, SIOCGIWAP, &wrq) >= 0) memcpy (bssid, &(wrq.u.ap_addr.sa_data), sizeof (struct ether_addr)); nm_dev_sock_close (sk); @@ -1719,9 +1708,7 @@ nm_device_802_11_wireless_disable_encryption (NMDevice80211Wireless *self) .u.data.flags = IW_ENCODE_DISABLED }; -#ifdef IOCTL_DEBUG - nm_info ("%s: About to SET IWENCODE.", iface); -#endif + nm_ioctl_info ("%s: About to SET IWENCODE.", iface); if (iw_set_ext (nm_dev_sock_get_fd (sk), iface, SIOCSIWENCODE, &wreq) == -1) { if (errno != ENODEV) @@ -2167,9 +2154,7 @@ is_associated (NMDevice80211Wireless *self) */ memset (&wrq, 0, sizeof (struct iwreq)); iface = nm_device_get_iface (NM_DEVICE (self)); -#ifdef IOCTL_DEBUG - nm_info ("%s: About to GET IWNAME.", iface); -#endif + nm_ioctl_info ("%s: About to GET IWNAME.", iface); if (iw_get_ext (nm_dev_sock_get_fd (sk), iface, SIOCGIWNAME, &wrq) >= 0) { if (!strcmp (wrq.u.name, "unassociated")) @@ -2187,9 +2172,7 @@ is_associated (NMDevice80211Wireless *self) * Is there a better way? Some cards don't work too well with this check, ie * Lucent WaveLAN. */ -#ifdef IOCTL_DEBUG - nm_info ("%s: About to GET IWAP.", iface); -#endif + nm_ioctl_info ("%s: About to GET IWAP.", iface); if (iw_get_ext (nm_dev_sock_get_fd (sk), iface, SIOCGIWAP, &wrq) >= 0) if (nm_ethernet_address_is_valid ((struct ether_addr *)(&(wrq.u.ap_addr.sa_data)))) associated = TRUE; diff --git a/src/nm-device-802-3-ethernet.c b/src/nm-device-802-3-ethernet.c index cf2155f867..99861a97f1 100644 --- a/src/nm-device-802-3-ethernet.c +++ b/src/nm-device-802-3-ethernet.c @@ -412,18 +412,15 @@ supports_ethtool_carrier_detect (NMDevice8023Ethernet *self) strncpy (ifr.ifr_name, iface, sizeof(ifr.ifr_name) - 1); edata.cmd = ETHTOOL_GLINK; ifr.ifr_data = (char *) &edata; -#ifdef IOCTL_DEBUG - nm_info ("%s: About to ETHTOOL\n", iface); -#endif + + nm_ioctl_info ("%s: About to ETHTOOL\n", iface); if (ioctl (nm_dev_sock_get_fd (sk), SIOCETHTOOL, &ifr) == -1) goto out; supports_ethtool = TRUE; out: -#ifdef IOCTL_DEBUG - nm_info ("%s: Done with ETHTOOL\n", iface); -#endif + nm_ioctl_info ("%s: Done with ETHTOOL\n", iface); nm_dev_sock_close (sk); return supports_ethtool; } @@ -481,14 +478,10 @@ mdio_read (NMDevice8023Ethernet *self, NMSock *sk, struct ifreq *ifr, int locati mii = (struct mii_ioctl_data *) &ifr->ifr_ifru; mii->reg_num = location; -#ifdef IOCTL_DEBUG - nm_info ("%s: About to GET MIIREG\n", iface); -#endif + nm_ioctl_info ("%s: About to GET MIIREG\n", iface); if (ioctl (nm_dev_sock_get_fd (sk), SIOCGMIIREG, ifr) >= 0) val = mii->val_out; -#ifdef IOCTL_DEBUG - nm_info ("%s: Done with GET MIIREG\n", iface); -#endif + nm_ioctl_info ("%s: Done with GET MIIREG\n", iface); return val; } @@ -514,13 +507,10 @@ supports_mii_carrier_detect (NMDevice8023Ethernet *self) } strncpy (ifr.ifr_name, iface, sizeof (ifr.ifr_name) - 1); -#ifdef IOCTL_DEBUG - nm_info ("%s: About to GET MIIPHY\n", iface); -#endif + nm_ioctl_info ("%s: About to GET MIIPHY\n", iface); err = ioctl (nm_dev_sock_get_fd (sk), SIOCGMIIPHY, &ifr); -#ifdef IOCTL_DEBUG - nm_info ("%s: Done with GET MIIPHY\n", iface); -#endif + nm_ioctl_info ("%s: Done with GET MIIPHY\n", iface); + if (err < 0) goto out; diff --git a/src/nm-device.c b/src/nm-device.c index 311cfaa343..9e6e0b034d 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -1684,13 +1684,11 @@ nm_device_update_ip4_address (NMDevice *self) iface = nm_device_get_iface (self); memset (&req, 0, sizeof (struct ifreq)); strncpy (req.ifr_name, iface, sizeof (req.ifr_name) - 1); -#ifdef IOCTL_DEBUG - nm_info ("%s: About to GET IFADDR.", iface); -#endif + + nm_ioctl_info ("%s: About to GET IFADDR.", iface); err = ioctl (nm_dev_sock_get_fd (sk), SIOCGIFADDR, &req); -#ifdef IOCTL_DEBUG - nm_info ("%s: Done with GET IFADDR.", iface); -#endif + nm_ioctl_info ("%s: Done with GET IFADDR.", iface); + nm_dev_sock_close (sk); if (err != 0) return; @@ -1744,13 +1742,11 @@ nm_device_is_up (NMDevice *self) /* Get device's flags */ strncpy (ifr.ifr_name, nm_device_get_iface (self), sizeof (ifr.ifr_name) - 1); -#ifdef IOCTL_DEBUG - nm_info ("%s: About to GET IFFLAGS.", nm_device_get_iface (self)); -#endif + + nm_ioctl_info ("%s: About to GET IFFLAGS.", nm_device_get_iface (self)); err = ioctl (nm_dev_sock_get_fd (sk), SIOCGIFFLAGS, &ifr); -#ifdef IOCTL_DEBUG - nm_info ("%s: Done with GET IFFLAGS.", nm_device_get_iface (self)); -#endif + nm_ioctl_info ("%s: Done with GET IFFLAGS.", nm_device_get_iface (self)); + nm_dev_sock_close (sk); if (!err) return (!((ifr.ifr_flags^IFF_UP) & IFF_UP)); diff --git a/src/nm-device.h b/src/nm-device.h index 59f68f8db5..424a4e1b84 100644 --- a/src/nm-device.h +++ b/src/nm-device.h @@ -30,7 +30,16 @@ #include "nm-ip4-config.h" #if 0 -#define IOCTL_DEBUG +# define IOCTL_DEBUG 1 +#endif + +#ifdef IOCTL_DEBUG +# define nm_ioctl_info(fmt, args...) \ + G_STMT_START { \ + g_message ("\t" fmt "\n", ##args); \ + } G_STMT_END +#else +# define nm_ioctl_info(fmt, args...) do { } while(0) #endif typedef enum NMWirelessScanInterval