]> git.sur5r.net Git - i3/i3status/blobdiff - src/first_network_device.c
Be more cautious about handling invalid battery measurements.
[i3/i3status] / src / first_network_device.c
index 593238531223bd401696d94d9cc3e389db05a7d2..3f34cf2ed1bc031221389278f1d9ccca62d22f4e 100644 (file)
@@ -50,6 +50,22 @@ static bool sysfs_devtype(char *dest, size_t n, const char *ifnam) {
     return true;
 }
 
+static bool is_virtual(const char *ifname) {
+    char path[1024];
+    char *target = NULL;
+    bool is_virtual = false;
+
+    snprintf(path, sizeof(path), "/sys/class/net/%s", ifname);
+    if ((target = realpath(path, NULL))) {
+        if (BEGINS_WITH(target, "/sys/devices/virtual/")) {
+            is_virtual = true;
+        }
+    }
+
+    free(target);
+    return is_virtual;
+}
+
 static net_type_t iface_type(const char *ifname) {
 #ifdef __linux__
     char devtype[32];
@@ -57,6 +73,7 @@ static net_type_t iface_type(const char *ifname) {
     if (!sysfs_devtype(devtype, sizeof(devtype), ifname))
         return NET_TYPE_OTHER;
 
+    /* Default to Ethernet when no devtype is available */
     if (!devtype[0])
         return NET_TYPE_ETHERNET;
 
@@ -147,6 +164,8 @@ const char *first_eth_interface(const net_type_t type) {
         iftype = iface_type(addrp->ifa_name);
         if (iftype != type)
             continue;
+        if (is_virtual(addrp->ifa_name))
+            continue;
         interface = strdup(addrp->ifa_name);
         break;
     }