summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorinfirit <[email protected]>2014-11-27 17:13:02 +0100
committerinfirit <[email protected]>2014-11-27 17:22:11 +0100
commitd09966caa8d208a13a6b5aaf954202109d6e5d45 (patch)
tree42acac052bacfd477cb7c4c7b158ef09cb8bd74b
parent65d5750a3bb2805e71f71bbce381b53174288e1e (diff)
downloadmate-applets-d09966caa8d208a13a6b5aaf954202109d6e5d45.tar.bz2
mate-applets-d09966caa8d208a13a6b5aaf954202109d6e5d45.tar.xz
multiload: Don't unconditionally use PATH_MAX
Since PATH_MAX is not guaranteed to be defined, unconditionally using it will cause a build failure on platforms that don't define it. So stop using it and use dynamic allocation to achieve the same result. Taken from gnome-applets commit: 877359047a4c3327d574955a72a102cc7320f6d3 From: Emilio Pozuelo Monfort <[email protected]> Gnome bug: https://bugzilla.gnome.org/show_bug.cgi?id=603997
-rw-r--r--multiload/linux-proc.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/multiload/linux-proc.c b/multiload/linux-proc.c
index 13ebc5ff..d2149229 100644
--- a/multiload/linux-proc.c
+++ b/multiload/linux-proc.c
@@ -285,21 +285,28 @@ is_net_device_virtual(char *device)
* /sys/class/net/name-of-dev/ . This second method is more complex
* but more reliable.
*/
- char path[PATH_MAX];
+ gboolean ret = FALSE;
+ char *path = malloc (strlen (device) + strlen ("/sys/class/net//device") + 1);
- /* Check if /sys/class/net/name-of-dev/ exists (may be old linux kernel
- * or not linux at all). */
- if (sprintf(path, "/sys/class/net/%s", device) < 0)
- return FALSE;
- if (access(path, F_OK) != 0)
- return FALSE; /* unknown */
-
- if (sprintf(path, "/sys/class/net/%s/device", device) < 0)
+ if (path == NULL)
return FALSE;
- if (access(path, F_OK) != 0)
- return TRUE;
- return FALSE;
+ /* Check if /sys/class/net/name-of-dev/ exists (may be old linux kernel
+ * or not linux at all). */
+ do {
+ if (sprintf(path, "/sys/class/net/%s", device) < 0)
+ break;
+ if (access(path, F_OK) != 0)
+ break; /* unknown */
+
+ if (sprintf(path, "/sys/class/net/%s/device", device) < 0)
+ break;
+ if (access(path, F_OK) != 0)
+ ret = TRUE;
+ } while (0);
+
+ free (path);
+ return ret;
}
void