Print empty string for not mounted disks. (#148)

An empty string becomes the default value for format_not_mounted parameter
for any disk entry. This avoids printing erroneous values when a
filesystem is not mounted.
This commit is contained in:
eplanet 2016-08-16 09:29:08 +02:00 committed by Michael Stapelberg
parent 7ce0044a03
commit fde5ebfa1e
2 changed files with 7 additions and 7 deletions

View File

@ -249,9 +249,7 @@ is assumed to be "percentage_avail" and low_threshold to be set to 0, which
implies no coloring at all.
You can define a different format with the option "format_not_mounted"
which is used if the path does not exist or is not a mount point. So you can just empty
the output for the given path with adding +format_not_mounted=""+
to the config section.
which is used if the path does not exist or is not a mount point. Defaults to "".
*Example order*: +disk /mnt/usbstick+

View File

@ -130,13 +130,15 @@ void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const ch
#else
struct statvfs buf;
if (format_not_mounted == NULL) {
format_not_mounted = "";
}
if (statvfs(path, &buf) == -1) {
/* If statvfs errors, e.g., due to the path not existing,
* we use the format for a not mounted device. */
if (format_not_mounted != NULL) {
format = format_not_mounted;
}
} else if (format_not_mounted != NULL) {
format = format_not_mounted;
} else {
FILE *mntentfile = setmntent("/etc/mtab", "r");
struct mntent *m;
bool found = false;