diff options
| author | Michael Stapelberg <stapelberg@users.noreply.github.com> | 2015-03-01 07:42:59 -0800 | 
|---|---|---|
| committer | Michael Stapelberg <stapelberg@users.noreply.github.com> | 2015-03-01 07:42:59 -0800 | 
| commit | 6996f0a4a34e0744f09dbce39a2164c6fcee875e (patch) | |
| tree | 0fc0175da3af4bb8d48a6750921e649a5a2f1571 /src | |
| parent | df8d69a9953a0a7da48a17dae6d2d1327c330411 (diff) | |
| parent | 562a879f7c40bb7586e2d4b8dc55cf3171e5d43d (diff) | |
Merge pull request #3 from chrko/master
Modify print_disk_info. Now there is no output if the path is no mountpoint.
Diffstat (limited to 'src')
| -rw-r--r-- | src/print_disk_info.c | 22 | 
1 files changed, 21 insertions, 1 deletions
| diff --git a/src/print_disk_info.c b/src/print_disk_info.c index 1671210..e225923 100644 --- a/src/print_disk_info.c +++ b/src/print_disk_info.c @@ -3,7 +3,9 @@  #include <stdlib.h>  #include <string.h>  #include <ctype.h> +#include <mntent.h>  #include <stdint.h> +#include <sys/stat.h>  #include <sys/statvfs.h>  #include <sys/types.h>  #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || (__OpenBSD__) || defined(__DragonFly__) @@ -106,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; @@ -123,6 +125,24 @@ void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const ch          if (statvfs(path, &buf) == -1)                  return; + +        if (format_not_mounted != NULL) { +                FILE *mntentfile = setmntent("/etc/mtab", "r"); +                struct mntent *m; +                bool found = false; + +                while ((m = getmntent(mntentfile)) != NULL) { +                        if (strcmp(m->mnt_dir, path) == 0) { +                                found = true; +                                break; +                        } +                } +                endmntent(mntentfile); + +                if (!found) { +                        format = format_not_mounted; +                } +        }  #endif          if (low_threshold > 0 && below_threshold(buf, prefix_type, threshold_type, low_threshold)) { | 
