scron

simple cron daemon
git clone git://git.2f30.org/scron.git
Log | Files | Refs | README | LICENSE

commit 94225521e4e042faebef595e73a0c6cca6baaa6e
parent 283b23c892feba290a8e0c7a1995119cb53a1074
Author: sin <sin@2f30.org>
Date:   Thu Jul 24 13:54:18 +0100

If tm is 0 then match only if we have to

if tm is 0 and div != 0, only match if the length of interval modulo
div is 0.

Also while at it, make sure the days in month is properly calculated
based on current month and year.

Diffstat:
crond.c | 28++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/crond.c b/crond.c @@ -195,17 +195,29 @@ waitjob(void) } static int +daysinmonth(int month, int year) +{ + int months[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + + if (year % 4 == 0) + if (!(year % 100 == 0 && year % 400 != 0)) + months[1]++; + return months[month]; +} + +static int matchentry(struct ctabentry *cte, struct tm *tm) { struct { struct field *f; int tm; + int len; } matchtbl[] = { - { .f = &cte->min, .tm = tm->tm_min }, - { .f = &cte->hour, .tm = tm->tm_hour }, - { .f = &cte->mday, .tm = tm->tm_mday }, - { .f = &cte->mon, .tm = tm->tm_mon }, - { .f = &cte->wday, .tm = tm->tm_wday }, + { .f = &cte->min, .tm = tm->tm_min, .len = 60 }, + { .f = &cte->hour, .tm = tm->tm_hour, .len = 24 }, + { .f = &cte->mday, .tm = tm->tm_mday, .len = daysinmonth(tm->tm_mon, tm->tm_year) }, + { .f = &cte->mon, .tm = tm->tm_mon, .len = 12 }, + { .f = &cte->wday, .tm = tm->tm_wday, .len = 7 }, }; size_t i; @@ -214,9 +226,13 @@ matchentry(struct ctabentry *cte, struct tm *tm) if (matchtbl[i].f->low == -1) { continue; } else if (matchtbl[i].f->div > 0) { - if (matchtbl[i].tm > 0 || matchtbl[i].f->div % 2 == 0) + if (matchtbl[i].tm > 0) { if (matchtbl[i].tm % matchtbl[i].f->div == 0) continue; + } else { + if (matchtbl[i].len % matchtbl[i].f->div == 0) + continue; + } } else if (matchtbl[i].f->low == matchtbl[i].tm) { continue; }