Skip to content

Commit

Permalink
stop updating filesystems that are dynamically removed from the text
Browse files Browse the repository at this point in the history
fixes brndnmtthws#208 hopefully properly by tracking which fs_stats entries are
actually being used

as an aside, also fixes the niche but possible issue of slowly running out of
fs_stats entries despite never having too many at one time
  • Loading branch information
quiescens committed Aug 29, 2024
1 parent c428663 commit 9e6880a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
8 changes: 7 additions & 1 deletion src/fs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}

Expand All @@ -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 {
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand Down

0 comments on commit 9e6880a

Please sign in to comment.