diff options
author | Orestis <orestisf1993@gmail.com> | 2018-11-08 11:52:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-08 11:52:47 +0200 |
commit | 2d38178063d13dd3a1e477dadb31ebad53a2a471 (patch) | |
tree | bb0fdc18399f423b8f6728e67f518af6d075b63e /src | |
parent | 226cb229f702d02954e7ce77c995ab2158a2f869 (diff) | |
parent | e5455251481d396f11dc87c734a91a319c44773c (diff) |
Merge pull request #319 from eplanet/fix-etc-mtab
Read /proc/mounts if /etc/mtab can't be read
Diffstat (limited to 'src')
-rw-r--r-- | src/print_disk_info.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/print_disk_info.c b/src/print_disk_info.c index bc43da0..03c95e5 100644 --- a/src/print_disk_info.c +++ b/src/print_disk_info.c @@ -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"); - 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 |