summaryrefslogtreecommitdiff
path: root/src/print_disk_info.c
diff options
context:
space:
mode:
authoreplanet <emeric.planet@gmail.com>2016-08-16 09:29:08 +0200
committerMichael Stapelberg <stapelberg@users.noreply.github.com>2016-08-16 00:29:08 -0700
commitfde5ebfa1e5132bf33957ace30c70263038391ad (patch)
tree1eb9b43f4c952edb9621d7562ced7cf26e25977f /src/print_disk_info.c
parent7ce0044a03f94b2b0707b087ebb9de78c1d09874 (diff)
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.
Diffstat (limited to 'src/print_disk_info.c')
-rw-r--r--src/print_disk_info.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/print_disk_info.c b/src/print_disk_info.c
index edc69ac..624a8e2 100644
--- a/src/print_disk_info.c
+++ b/src/print_disk_info.c
@@ -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;