]> git.sur5r.net Git - i3/i3status/commitdiff
Adding optional configuration option to "print_disk_info".
authorChristian Kohlstedde <christian@kohlsted.de>
Wed, 18 Feb 2015 22:43:25 +0000 (23:43 +0100)
committerChristian Kohlstedde <christian@kohlsted.de>
Wed, 18 Feb 2015 22:43:25 +0000 (23:43 +0100)
i3status.c
include/i3status.h
src/print_disk_info.c

index 7c98d06ede4ebe50d19768b6a475ceeccbd0521d..6491e1c6015371115de7382941fdd96d2820cd89 100644 (file)
@@ -386,6 +386,7 @@ int main(int argc, char *argv[]) {
 
         cfg_opt_t disk_opts[] = {
                 CFG_STR("format", "%free", CFGF_NONE),
+                CFG_STR("format_not_mounted", NULL, CFGF_NONE),
                 CFG_STR("prefix_type", "binary", CFGF_NONE),
                 CFG_STR("threshold_type", "percentage_avail", CFGF_NONE),
                 CFG_FLOAT("low_threshold", 0, CFGF_NONE),
@@ -621,7 +622,7 @@ int main(int argc, char *argv[]) {
 
                         CASE_SEC_TITLE("disk") {
                                 SEC_OPEN_MAP("disk_info");
-                                print_disk_info(json_gen, buffer, title, cfg_getstr(sec, "format"), cfg_getstr(sec, "prefix_type"), cfg_getstr(sec, "threshold_type"), cfg_getfloat(sec, "low_threshold"));
+                                print_disk_info(json_gen, buffer, title, cfg_getstr(sec, "format"), cfg_getstr(sec, "format_not_mounted"), cfg_getstr(sec, "prefix_type"), cfg_getstr(sec, "threshold_type"), cfg_getfloat(sec, "low_threshold"));
                                 SEC_CLOSE_MAP;
                         }
 
index ef212c83fd1a964784d8ea600025b92df9184ae7..6e20af3009ae884cfe32cb0b6ac3df9d81a8a318 100644 (file)
@@ -178,7 +178,7 @@ typedef enum {
 const char *first_eth_interface(const net_type_t type);
 
 void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, const char *format_down);
-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);
 void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, const char *format_down, const char *status_chr, const char *status_bat, const char *status_full, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity, bool hide_seconds);
 void print_time(yajl_gen json_gen, char *buffer, const char *format, const char *tz, time_t t);
 void print_ddate(yajl_gen json_gen, char *buffer, const char *format, time_t t);
index 609f6d3537e7e7ff45a1bcb2d25857b09337f64c..4ed2f22c7bfee30a44db1ed520fc5e26eac628be 100644 (file)
@@ -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