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 <khaneliman12@gmail.com>
This commit is contained in:
Austin Horstman
2026-07-04 08:41:35 -05:00
committed by Austin Horstman
parent 5f4b96ad1d
commit fc01c03a20
+14 -5
View File
@@ -2,6 +2,7 @@
#include <spdlog/spdlog.h>
#include <cerrno>
#include <stdexcept>
#include <utility>
@@ -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<pid_t>(*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());