Run cron watcher with start time zero when the event loop starts

A cron watcher with start time zero, documented to mean 'now', never
runs:

    uev_cron_init(ctx, w, cb, NULL, 0, 3600);

Zero is passed as is to the timerfd, where it disarms the timer.

Replace it with the current time when the event loop is running.  This
also goes for uev_cron_set(), where zero no longer disarms the watcher,
use uev_cron_stop() for that.

The event loop used a start time of zero to mark an at job as done.
Stop the watcher there instead and keep its time, so restarting an at
job that was interrupted by a clock change does not run it at once.

Closes #30
This commit is contained in:
NefelibateLG authored and Joachim Wiberg committed 2026-11-16 15:08:42 +01:00
1 parent 28643fa599
commit 397247d567
5 files changed
+44 -8

No files matched your search

+1
View File
@@ -3,6 +3,7 @@
active
api
complete
cronnow
cronrun
cronstart
error
+1
View File
@@ -8,6 +8,7 @@ TESTS =
TESTS += active
TESTS += api
TESTS += complete
TESTS += cronnow
TESTS += cronrun
TESTS += cronstart
TESTS += error
+32
View File
@@ -0,0 +1,32 @@
/* Verifies that a cron watcher with start time zero runs now */
#include "check.h"
static int fired;
static void cb(uev_t *w, void *arg, int events)
{
fired++;
uev_exit(w->ctx);
}
int main(void)
{
uev_ctx_t ctx;
uev_t w;
fail_unless(uev_init(&ctx) == 0);
fail_unless(uev_cron_init(&ctx, &w, cb, NULL, 0, 0) == 0);
alarm(2);
fail_unless(uev_run(&ctx, 0) == 0);
fail_unless(fired == 1);
return 0;
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/