From: Jaroslav Kysela Date: Sun, 13 Mar 2016 16:42:56 +0000 (+0100) Subject: cron: fix the cron_next for DST change, fixes #3627 X-Git-Tag: v4.0.9^0 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dc6bd3a3efd7534912177698fd8ffe2b8726f9ed;p=thirdparty%2Ftvheadend.git cron: fix the cron_next for DST change, fixes #3627 --- diff --git a/src/cron.c b/src/cron.c index 908f18af9..c019fa7d2 100644 --- a/src/cron.c +++ b/src/cron.c @@ -19,6 +19,7 @@ #include "build.h" #include "cron.h" +#include "tvheadend.h" #include #include @@ -323,6 +324,16 @@ cron_next ( cron_t *c, const time_t now, time_t *ret ) mktime(&tmp); nxt.tm_isdst = tmp.tm_isdst; *ret = mktime(&nxt); + if (*ret <= now) + *ret = mktime(&tmp); + if (*ret <= now) { +#ifndef CRON_TEST + tvherror("cron", "invalid time, now %"PRItime_t", result %"PRItime_t, now, *ret); +#else + printf("ERROR: invalid time, now %"PRItime_t", result %"PRItime_t"\n", now, *ret); +#endif + *ret = now + 600; + } return 0; } @@ -350,7 +361,7 @@ cron_multi_next ( cron_multi_t *cm, const time_t now, time_t *ret ) /* * Testing */ -#if 0 +#ifdef CRON_TEST static void print_bits ( uint64_t b, int n ) { @@ -369,7 +380,14 @@ main ( int argc, char **argv ) struct tm tm; char buf[128]; - time(&n); + if (argc < 2) { + printf("Specify: CRON [NOW]\n"); + return 1; + } + if (argc > 2) + n = atol(argv[2]); + else + time(&n); if (cron_set(&c, argv[1])) printf("INVALID CRON: %s\n", argv[1]); else { @@ -381,7 +399,7 @@ main ( int argc, char **argv ) localtime_r(&n, &tm); strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", &tm); - printf("NOW: %s\n", buf); + printf("NOW: %ld - %s (DST %d) (ZONE %s)\n", (long)n, buf, tm.tm_isdst, tm.tm_zone); if (cron_next(&c, n, &n)) { printf("FAILED to find NEXT\n"); @@ -389,7 +407,7 @@ main ( int argc, char **argv ) } localtime_r(&n, &tm); strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", &tm); - printf("NXT: %s\n", buf); + printf("NXT: %ld - %s (DST %d) (ZONE %s)\n", (long)n, buf, tm.tm_isdst, tm.tm_zone); } return 0;