diff --git a/src/cron.c b/src/cron.c index 94bd7cf..bc01149 100644 --- a/src/cron.c +++ b/src/cron.c @@ -144,7 +144,15 @@ int uev_cron_set(uev_t *w, time_t when, time_t interval) */ 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); } /** diff --git a/test/.gitignore b/test/.gitignore index 99ad772..01a9842 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -4,6 +4,7 @@ active api complete cronrun +cronstart io signal stdin diff --git a/test/Makefile.am b/test/Makefile.am index a389f6e..e3fb6a1 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -9,6 +9,7 @@ TESTS += active TESTS += api TESTS += complete TESTS += cronrun +TESTS += cronstart TESTS += io TESTS += signal TESTS += stdin diff --git a/test/cronstart.c b/test/cronstart.c new file mode 100644 index 0000000..b1b253b --- /dev/null +++ b/test/cronstart.c @@ -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: + */