]> git.sur5r.net Git - i3/i3status/blobdiff - src/print_disk_info.c
Merge pull request #39 from vikstrous/master
[i3/i3status] / src / print_disk_info.c
index b9047e5388e9baa465cd23f334fbdf9755c7f9a9..7fd47b9d916ded11ef2352de930ef41fe12c9ac9 100644 (file)
@@ -3,7 +3,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
-#include <mntent.h>
 #include <stdint.h>
 #include <sys/stat.h>
 #include <sys/statvfs.h>
@@ -11,6 +10,8 @@
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || (__OpenBSD__) || defined(__DragonFly__)
 #include <sys/param.h>
 #include <sys/mount.h>
+#else
+#include <mntent.h>
 #endif
 #include <yajl/yajl_gen.h>
 #include <yajl/yajl_version.h>
@@ -123,10 +124,11 @@ void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const ch
 #else
     struct statvfs buf;
 
-    if (statvfs(path, &buf) == -1)
-        return;
-
-    if (format_not_mounted != NULL) {
+    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. */
+        format = format_not_mounted;
+    } else if (format_not_mounted != NULL) {
         FILE *mntentfile = setmntent("/etc/mtab", "r");
         struct mntent *m;
         bool found = false;