mirror of
https://github.com/troglobit/libuev.git
synced 2026-11-19 19:51:06 +00:00
Fix restart of a stopped cron watcher
uev_cron_start() on a stopped cron watcher brings it back as a regular timer, with a timeout made up of parts of the cron schedule. It calls uev_timer_start(), which reads the timer fields of the watcher and creates a monotonic timer. Restart with uev_cron_set() and the cron schedule instead.
This commit is contained in:
1 parent
e699cb7f5f
commit
ae28276f3f
4 files changed
+40
-1
No files matched your search
+9
-1
@@ -144,7 +144,15 @@ int uev_cron_set(uev_t *w, time_t when, time_t interval)
|
|||||||
*/
|
*/
|
||||||
int uev_cron_start(uev_t *w)
|
int uev_cron_start(uev_t *w)
|
||||||
{
|
{
|
||||||
return uev_timer_start(w);
|
if (!w) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-1 != w->fd)
|
||||||
|
_uev_watcher_stop(w);
|
||||||
|
|
||||||
|
return uev_cron_set(w, w->u.c.when, w->u.c.interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ active
|
|||||||
api
|
api
|
||||||
complete
|
complete
|
||||||
cronrun
|
cronrun
|
||||||
|
cronstart
|
||||||
io
|
io
|
||||||
signal
|
signal
|
||||||
stdin
|
stdin
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ TESTS += active
|
|||||||
TESTS += api
|
TESTS += api
|
||||||
TESTS += complete
|
TESTS += complete
|
||||||
TESTS += cronrun
|
TESTS += cronrun
|
||||||
|
TESTS += cronstart
|
||||||
TESTS += io
|
TESTS += io
|
||||||
TESTS += signal
|
TESTS += signal
|
||||||
TESTS += stdin
|
TESTS += stdin
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/* Verifies that a stopped cron watcher can be started again */
|
||||||
|
#include "check.h"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
time_t when = time(NULL) + 3600;
|
||||||
|
uev_ctx_t ctx;
|
||||||
|
uev_t cron;
|
||||||
|
|
||||||
|
fail_unless(uev_init(&ctx) == 0);
|
||||||
|
fail_unless(uev_cron_init(&ctx, &cron, NULL, NULL, when, 3600) == 0);
|
||||||
|
fail_unless(uev_cron_stop(&cron) == 0);
|
||||||
|
fail_unless(!uev_cron_active(&cron));
|
||||||
|
|
||||||
|
fail_unless(uev_cron_start(&cron) == 0);
|
||||||
|
fail_unless(uev_cron_active(&cron));
|
||||||
|
fail_unless(cron.type == UEV_CRON_TYPE);
|
||||||
|
fail_unless(cron.u.c.when == when);
|
||||||
|
fail_unless(cron.u.c.interval == 3600);
|
||||||
|
|
||||||
|
return uev_exit(&ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local Variables:
|
||||||
|
* indent-tabs-mode: t
|
||||||
|
* c-file-style: "linux"
|
||||||
|
* End:
|
||||||
|
*/
|
||||||
Reference in new issue
Block a user