Skip to content

Commit

Permalink
Handle UEV_ERROR properly in all libuev callbacks
Browse files Browse the repository at this point in the history
Signed-off-by: Joachim Wiberg <[email protected]>
  • Loading branch information
troglobit committed Feb 22, 2025
1 parent 3cb9d06 commit 8db6b17
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
5 changes: 5 additions & 0 deletions src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "config.h"
#include "finit.h"
#include "log.h"
#include "schedule.h"

#define SC_INIT 0x494E4954 /* "INIT", see ascii(7) */
Expand All @@ -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;
}
Expand Down
10 changes: 8 additions & 2 deletions src/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 8db6b17

Please sign in to comment.