Skip to content

Commit abac316

Browse files
committed
Handle UEV_ERROR properly in all libuev callbacks
Signed-off-by: Joachim Wiberg <[email protected]>
1 parent cfe915e commit abac316

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

src/api.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ static void api_cb(uev_t *w, void *arg, int events)
332332
int sd, lvl;
333333
svc_t *svc;
334334

335+
if (UEV_ERROR == events) {
336+
dbg("%s(): api socket %d invalid.", __func__, w->fd);
337+
goto error;
338+
}
339+
335340
sd = accept(w->fd, NULL, NULL);
336341
if (sd < 0) {
337342
err(1, "Failed serving API request");
@@ -578,8 +583,6 @@ static void api_cb(uev_t *w, void *arg, int events)
578583

579584
leave:
580585
close(sd);
581-
if (UEV_ERROR == events)
582-
goto error;
583586
return;
584587
error:
585588
api_exit();

src/cgroup.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ static void cgroup_events_cb(uev_t *w, void *arg, int events)
259259
ssize_t sz;
260260
size_t off;
261261

262+
if (UEV_ERROR == events) {
263+
dbg("%s(): inotify socket %d invalid.", __func__, w->fd);
264+
return;
265+
}
266+
262267
sz = read(w->fd, ev_buf, sizeof(ev_buf) - 1);
263268
if (sz <= 0) {
264269
err(1, "invalid inotify event");

src/conf.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,11 @@ static int conf_iwatch_read(int fd)
15421542

15431543
static void conf_cb(uev_t *w, void *arg, int events)
15441544
{
1545+
if (UEV_ERROR == events) {
1546+
dbg("%s(): iwatch socket %d invalid.", __func__, w->fd);
1547+
return;
1548+
}
1549+
15451550
if (conf_iwatch_read(w->fd)) {
15461551
err(1, "invalid inotify event");
15471552
return;

src/schedule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "config.h"
2525
#include "finit.h"
26+
#include "log.h"
2627
#include "schedule.h"
2728

2829
#define SC_INIT 0x494E4954 /* "INIT", see ascii(7) */
@@ -35,6 +36,7 @@ static void cb(uev_t *w, void *arg, int events)
3536
struct wq *work = (struct wq *)arg;
3637

3738
if (UEV_ERROR == events) {
39+
dbg("%s(): spurious problem with schedule work timer, restarting.", __func__);
3840
uev_timer_start(w);
3941
return;
4042
}

src/service.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ static void service_timeout_cb(uev_t *w, void *arg, int events)
8181
{
8282
svc_t *svc = arg;
8383

84-
/* Ignore any UEV_ERROR, we're a one-shot cb so just run it. */
84+
if (UEV_ERROR == events) {
85+
dbg("%s(): spurious problem, svc %s.", __func__, svc_ident(svc, NULL, 0));
86+
uev_timer_start(w);
87+
return;
88+
}
89+
8590
if (svc->timer_cb)
8691
svc->timer_cb(svc);
8792
}
@@ -2875,7 +2880,7 @@ void service_notify_cb(uev_t *w, void *arg, int events)
28752880
ssize_t len;
28762881

28772882
if (UEV_ERROR == events) {
2878-
warn("Spurious problem with %s notify callback, restarting.", svc_ident(svc, NULL, 0));
2883+
dbg("Spurious problem with %s notify callback, restarting.", svc_ident(svc, NULL, 0));
28792884
uev_io_start(w);
28802885
return;
28812886
}
@@ -2933,6 +2938,7 @@ static void service_interval_cb(uev_t *w, void *arg, int events)
29332938

29342939
(void)arg;
29352940
if (UEV_ERROR == events) {
2941+
dbg("%s(): spurious problem, restarting.", __func__);
29362942
uev_timer_start(w);
29372943
return;
29382944
}

0 commit comments

Comments
 (0)