From d09966caa8d208a13a6b5aaf954202109d6e5d45 Mon Sep 17 00:00:00 2001 From: infirit Date: Thu, 27 Nov 2014 17:13:02 +0100 Subject: 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 Gnome bug: https://bugzilla.gnome.org/show_bug.cgi?id=603997 --- multiload/linux-proc.c | 31 +++++++++++++++++++------------ 1 file 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 -- cgit v1.2.1