--- src/xmltv.c.cln 2012-06-19 11:27:14.000000000 +0100 +++ src/xmltv.c 2012-06-24 18:57:53.723225195 +0100 @@ -24,6 +24,7 @@ #include #include #include +#include #include "htsmsg_xml.h" #include "settings.h" @@ -66,8 +67,7 @@ } parse_stats_t; - - +#define XMLTV_GRABBER_STAMP_FILE "/tmp/xmltv_grabber.stamp" static xmltv_grabber_t *xg_current; @@ -658,6 +658,7 @@ int confver = 0; struct timespec ts; char *p; + struct stat xmltv_stamp_info; pthread_mutex_lock(&xmltv_mutex); @@ -685,7 +686,11 @@ if(xmltv_grab_enabled == 0) continue; - ts.tv_sec = time(NULL) + xmltv_grab_interval * 3600; + /* If we don't have a grabber stamp file, run grabber right away */ + if (stat(XMLTV_GRABBER_STAMP_FILE,&xmltv_stamp_info)) ts.tv_sec = time((time_t *)NULL); + /* But if we do have one, set the next grabber run to be in the future + based on the grabber stamp file age plus the interval */ + else ts.tv_sec = xmltv_stamp_info.st_mtime + xmltv_grab_interval * 3600; if(xg_current != NULL) { tvhlog(LOG_INFO, "xmltv", @@ -697,7 +702,22 @@ pthread_mutex_unlock(&xmltv_mutex); - xmltv_grab(p); + /* See if current time has reach last grab + interval */ + if (time((time_t *)NULL) >= ts.tv_sec) + { + int xmltv_grabber_handle; + /* Want to do a grab, so remove the old grab stamp file... */ + (void)unlink(XMLTV_GRABBER_STAMP_FILE); + /* ...and create a fresh one if we can. + Note that XMLTV_GRABBER_STAMP_FILE isn't deleted if + tvheadend exits, so that we can retain the correct + interval between runs. */ + xmltv_grabber_handle = creat(XMLTV_GRABBER_STAMP_FILE,S_IRUSR | S_IWUSR); + if (xmltv_grabber_handle >= 0) (void)close(xmltv_grabber_handle); + + /* Now do the xmltv grab */ + xmltv_grab(p); + } pthread_mutex_lock(&xmltv_mutex); free(p);