From 85bb373095d296a90a7a1e8741229dc4dcb9acc8 Mon Sep 17 00:00:00 2001 From: Christian Kohlstedde Date: Wed, 18 Feb 2015 23:43:25 +0100 Subject: Adding optional configuration option to "print_disk_info". --- src/print_disk_info.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/print_disk_info.c') diff --git a/src/print_disk_info.c b/src/print_disk_info.c index 609f6d3..4ed2f22 100644 --- a/src/print_disk_info.c +++ b/src/print_disk_info.c @@ -108,7 +108,7 @@ static bool below_threshold(struct statvfs buf, const char *prefix_type, const c * human readable manner. * */ -void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const char *format, const char *prefix_type, const char *threshold_type, const double low_threshold) { +void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const char *format, const char *format_not_mounted, const char *prefix_type, const char *threshold_type, const double low_threshold) { const char *walk; char *outwalk = buffer; bool colorful_output = false; @@ -126,22 +126,22 @@ void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const ch if (statvfs(path, &buf) == -1) return; - FILE *mntentfile = setmntent("/etc/mtab", "r"); - struct mntent *m; - bool found = false; + if (format_not_mounted != NULL) { + FILE *mntentfile = setmntent("/etc/mtab", "r"); + struct mntent *m; + bool found = false; - while (NULL != (m = getmntent(mntentfile))) { - if (strcmp(m->mnt_dir, path) == 0) { - found = true; - break; + while (NULL != (m = getmntent(mntentfile))) { + if (strcmp(m->mnt_dir, path) == 0) { + found = true; + break; + } } - } - endmntent(mntentfile); + endmntent(mntentfile); - if (!found) { - *buffer = '\0'; - OUTPUT_FULL_TEXT(buffer); - return; + if (!found) { + format = format_not_mounted; + } } #endif -- cgit v1.2.3