From abac31682d30ab87671a285e0bb67958886445aa Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Wed, 19 Feb 2025 05:48:55 +0100 Subject: [PATCH] Handle UEV_ERROR properly in all libuev callbacks Signed-off-by: Joachim Wiberg --- src/api.c | 7 +++++-- src/cgroup.c | 5 +++++ src/conf.c | 5 +++++ src/schedule.c | 2 ++ src/service.c | 10 ++++++++-- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/api.c b/src/api.c index 8d29a236..f53eff97 100644 --- a/src/api.c +++ b/src/api.c @@ -332,6 +332,11 @@ static void api_cb(uev_t *w, void *arg, int events) int sd, lvl; svc_t *svc; + if (UEV_ERROR == events) { + dbg("%s(): api socket %d invalid.", __func__, w->fd); + goto error; + } + sd = accept(w->fd, NULL, NULL); if (sd < 0) { err(1, "Failed serving API request"); @@ -578,8 +583,6 @@ static void api_cb(uev_t *w, void *arg, int events) leave: close(sd); - if (UEV_ERROR == events) - goto error; return; error: api_exit(); diff --git a/src/cgroup.c b/src/cgroup.c index e184b62b..d1790d96 100644 --- a/src/cgroup.c +++ b/src/cgroup.c @@ -259,6 +259,11 @@ static void cgroup_events_cb(uev_t *w, void *arg, int events) ssize_t sz; size_t off; + if (UEV_ERROR == events) { + dbg("%s(): inotify socket %d invalid.", __func__, w->fd); + return; + } + sz = read(w->fd, ev_buf, sizeof(ev_buf) - 1); if (sz <= 0) { err(1, "invalid inotify event"); diff --git a/src/conf.c b/src/conf.c index 908bc919..be2ecb9b 100644 --- a/src/conf.c +++ b/src/conf.c @@ -1542,6 +1542,11 @@ static int conf_iwatch_read(int fd) static void conf_cb(uev_t *w, void *arg, int events) { + if (UEV_ERROR == events) { + dbg("%s(): iwatch socket %d invalid.", __func__, w->fd); + return; + } + if (conf_iwatch_read(w->fd)) { err(1, "invalid inotify event"); return; diff --git a/src/schedule.c b/src/schedule.c index 31fffe6b..c5d463d9 100644 --- a/src/schedule.c +++ b/src/schedule.c @@ -23,6 +23,7 @@ #include "config.h" #include "finit.h" +#include "log.h" #include "schedule.h" #define SC_INIT 0x494E4954 /* "INIT", see ascii(7) */ @@ -35,6 +36,7 @@ static void cb(uev_t *w, void *arg, int events) struct wq *work = (struct wq *)arg; if (UEV_ERROR == events) { + dbg("%s(): spurious problem with schedule work timer, restarting.", __func__); uev_timer_start(w); return; } diff --git a/src/service.c b/src/service.c index 84675956..f39b2b0a 100644 --- a/src/service.c +++ b/src/service.c @@ -81,7 +81,12 @@ static void service_timeout_cb(uev_t *w, void *arg, int events) { svc_t *svc = arg; - /* Ignore any UEV_ERROR, we're a one-shot cb so just run it. */ + if (UEV_ERROR == events) { + dbg("%s(): spurious problem, svc %s.", __func__, svc_ident(svc, NULL, 0)); + uev_timer_start(w); + return; + } + if (svc->timer_cb) svc->timer_cb(svc); } @@ -2875,7 +2880,7 @@ void service_notify_cb(uev_t *w, void *arg, int events) ssize_t len; if (UEV_ERROR == events) { - warn("Spurious problem with %s notify callback, restarting.", svc_ident(svc, NULL, 0)); + dbg("Spurious problem with %s notify callback, restarting.", svc_ident(svc, NULL, 0)); uev_io_start(w); return; } @@ -2933,6 +2938,7 @@ static void service_interval_cb(uev_t *w, void *arg, int events) (void)arg; if (UEV_ERROR == events) { + dbg("%s(): spurious problem, restarting.", __func__); uev_timer_start(w); return; }