Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in which "dead" subscribers would not be removed right away leading to bspwm running out of file descriptors #1126

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/bspwm.c
Expand Up @@ -215,6 +215,8 @@ int main(int argc, char *argv[])
if (!check_connection(dpy)) {
running = false;
}

prune_dead_subscribers();
}

if (restart) {
Expand Down
16 changes: 16 additions & 0 deletions src/subscribe.c
Expand Up @@ -163,3 +163,19 @@ void put_status(subscriber_mask_t mask, ...)
sb = next;
}
}

void prune_dead_subscribers() {
subscriber_list_t *sb = subscribe_head;
while (sb != NULL) {
subscriber_list_t *next = sb->next;
// To check if a subscriber's stream is still open and writable call
// write with an empty buffer and check the returned value. If the
// stream is not writable anymore (i.e. it has been closed because the
// process associated to this subscriber no longer exists) then write()
// will return -1.
if (write(fileno(sb->stream), 0, 0) == -1) {
remove_subscriber(sb);
}
sb = next;
}
}
4 changes: 4 additions & 0 deletions src/subscribe.h
Expand Up @@ -68,4 +68,8 @@ void add_subscriber(subscriber_list_t *sb);
int print_report(FILE *stream);
void put_status(subscriber_mask_t mask, ...);

/* Remove any subscriber for which the stream as been closed and is no longer
* writable. */
void prune_dead_subscribers();

#endif