Reset watcher descriptor on failed cron and signal init

When uev_cron_init() or uev_signal_init() fails to add the watcher to
the event loop, the watcher is left with a descriptor that is closed.
A later set or start on it then operates on that descriptor, which by
then may belong to something else.

Reset it to -1, as the timer and event watchers do.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-16 15:08:43 +01:00
1 parent 0b5461d5ff
commit aedc189672
3 files changed
+26

No files matched your search

+6
View File
@@ -68,6 +68,11 @@ int uev_cron_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, time_t when
{
int fd;
if (!w || !ctx) {
errno = EINVAL;
return -1;
}
if (when < 0 || interval < 0) {
errno = ERANGE;
return -1;
@@ -84,6 +89,7 @@ int uev_cron_init(uev_ctx_t *ctx, uev_t *w, uev_cb_t *cb, void *arg, time_t when
_uev_watcher_stop(w);
exit:
close(fd);
w->fd = -1;
return -1;
}