X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fprint_disk_info.c;h=5f12e930074946943cf6b89edad02d0a8f1bb7e1;hb=0e4fd9ad4a4cc7d6c770134a077e91b02f6cd2f0;hp=bc43da0348bd5081946e712190bd459760a44715;hpb=639a67f752874142b1c081345fd36610e9046103;p=i3%2Fi3status diff --git a/src/print_disk_info.c b/src/print_disk_info.c index bc43da0..5f12e93 100644 --- a/src/print_disk_info.c +++ b/src/print_disk_info.c @@ -1,4 +1,5 @@ // vim:ts=4:sw=4:expandtab +#include #include #include #include @@ -145,15 +146,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"); - 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