diff --git a/src/common.cc b/src/common.cc index 4a270ce0fa..87aa718996 100644 --- a/src/common.cc +++ b/src/common.cc @@ -301,6 +301,9 @@ void update_stuff() { /* if you registered a callback with conky::register_cb, this will run it */ conky::run_all_callbacks(); + /* reset fs_stats in_use flags */ + clear_fs_stats(); + #if !defined(__linux__) /* XXX: move the following into the update_meminfo() functions? */ if (no_buffers.get(*state)) { diff --git a/src/fs.cc b/src/fs.cc index 061ef5ac9b..2ed4919350 100644 --- a/src/fs.cc +++ b/src/fs.cc @@ -79,6 +79,10 @@ int update_fs_stats() { if (current_update_time - last_fs_update < 13) { return 0; } for (i = 0; i < MAX_FS_STATS; ++i) { + /* stop monitoring the fs if isn't in_use */ + if (fs_stats[i].set != 0 && !fs_stats[i].in_use) { + memset(&fs_stats[i], 0, sizeof(struct fs_stat)); + } if (fs_stats[i].set != 0) { update_fs_stat(&fs_stats[i]); } } last_fs_update = current_update_time; @@ -88,7 +92,7 @@ int update_fs_stats() { void clear_fs_stats() { unsigned i; for (i = 0; i < MAX_FS_STATS; ++i) { - memset(&fs_stats[i], 0, sizeof(struct fs_stat)); + fs_stats[i].in_use = false; } } @@ -100,6 +104,7 @@ struct fs_stat *prepare_fs_stat(const char *s) { for (i = 0; i < MAX_FS_STATS; ++i) { if (fs_stats[i].set != 0) { if (strncmp(fs_stats[i].path, s, DEFAULT_TEXT_BUFFER_SIZE) == 0) { + fs_stats[i].in_use = true; return &fs_stats[i]; } } else { @@ -111,6 +116,7 @@ struct fs_stat *prepare_fs_stat(const char *s) { NORM_ERR("too many fs stats"); return nullptr; } + strncpy(next->path, s, DEFAULT_TEXT_BUFFER_SIZE); next->set = 1; update_fs_stat(next); diff --git a/src/fs.h b/src/fs.h index 16bcafcb19..aa60abbcbe 100644 --- a/src/fs.h +++ b/src/fs.h @@ -40,6 +40,7 @@ struct fs_stat { long long avail; long long free; char set; + bool in_use; }; /* forward declare to make gcc happy (fs.h <-> text_object.h include) */