]> git.sur5r.net Git - i3/i3status/commitdiff
Read /proc/mounts if /etc/mtab can't be read 319/head
authoreplanet <emeric.planet@gmail.com>
Wed, 7 Nov 2018 21:39:22 +0000 (22:39 +0100)
committereplanet <emeric.planet@gmail.com>
Thu, 8 Nov 2018 06:59:15 +0000 (07:59 +0100)
src/print_disk_info.c

index bc43da0348bd5081946e712190bd459760a44715..03c95e5dd93c08638abba90e8d4a620084b50e42 100644 (file)
@@ -145,15 +145,22 @@ void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const ch
         if (strlen(sanitized) > 1 && sanitized[strlen(sanitized) - 1] == '/')
             sanitized[strlen(sanitized) - 1] = '\0';
         FILE *mntentfile = setmntent("/etc/mtab", "r");
         if (strlen(sanitized) > 1 && sanitized[strlen(sanitized) - 1] == '/')
             sanitized[strlen(sanitized) - 1] = '\0';
         FILE *mntentfile = setmntent("/etc/mtab", "r");
-        struct mntent *m;
+        if (mntentfile == NULL) {
+            mntentfile = setmntent("/proc/mounts", "r");
+        }
+        if (mntentfile == NULL) {
+            fprintf(stderr, "i3status: files /etc/mtab and /proc/mounts aren't accessible\n");
+        } else {
+            struct mntent *m;
 
 
-        while ((m = getmntent(mntentfile)) != NULL) {
-            if (strcmp(m->mnt_dir, sanitized) == 0) {
-                mounted = true;
-                break;
+            while ((m = getmntent(mntentfile)) != NULL) {
+                if (strcmp(m->mnt_dir, sanitized) == 0) {
+                    mounted = true;
+                    break;
+                }
             }
             }
+            endmntent(mntentfile);
         }
         }
-        endmntent(mntentfile);
         free(sanitized);
     }
 #endif
         free(sanitized);
     }
 #endif