Read /proc/mounts if /etc/mtab can't be read

This commit is contained in:
eplanet 2018-11-07 22:39:22 +01:00
parent 1492868b80
commit e545525148

View 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");
struct mntent *m;
while ((m = getmntent(mntentfile)) != NULL) {
if (strcmp(m->mnt_dir, sanitized) == 0) {
mounted = true;
break;
}
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;
}
}
endmntent(mntentfile);
}
endmntent(mntentfile);
free(sanitized);
}
#endif