From fc01c03a202ed84688ed900ed78048db57bf20ef Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Sun, 8 Mar 2026 22:33:12 -0500 Subject: [PATCH] fix(custom): avoid blocking child reaps in interval worker Stop the interval worker from waiting synchronously on every pid in pid_children_ before it refreshes the module. Switching this reap pass to waitpid(..., WNOHANG) keeps the worker responsive when an older event-triggered child is still running, while still removing children that have already exited. Signed-off-by: Austin Horstman --- src/modules/custom.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index 54fda760..f010209e 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -2,6 +2,7 @@ #include +#include #include #include @@ -50,13 +51,21 @@ void waybar::modules::Custom::delayWorker() { } thread_ = [this] { - for (int i : this->pid_children_) { - int status; - waitpid(i, &status, 0); + for (auto it = this->pid_children_.begin(); it != this->pid_children_.end();) { + int status = 0; + const auto pid = static_cast(*it); + const auto waited = waitpid(pid, &status, WNOHANG); + if (waited == 0) { + ++it; + continue; + } + if (waited == -1 && errno != ECHILD) { + ++it; + continue; + } + it = this->pid_children_.erase(it); } - this->pid_children_.clear(); - bool can_update = true; if (config_["exec-if"].isString()) { output_ = util::command::execNoRead(config_["exec-if"].asString());