Project

General

Profile

Bug #1040 ยป xmltv.c.diff

Richard Lloyd, 2012-06-24 20:21

View differences:

src/xmltv.c 2012-06-24 18:57:53.723225195 +0100
24 24
#include <unistd.h>
25 25
#include <stdlib.h>
26 26
#include <dirent.h>
27
#include <fcntl.h>
27 28

  
28 29
#include "htsmsg_xml.h"
29 30
#include "settings.h"
......
66 67

  
67 68
} parse_stats_t;
68 69

  
69

  
70

  
70
#define XMLTV_GRABBER_STAMP_FILE "/tmp/xmltv_grabber.stamp"
71 71

  
72 72
static xmltv_grabber_t *xg_current;
73 73

  
......
658 658
  int confver = 0;
659 659
  struct timespec ts;
660 660
  char *p;
661
  struct stat xmltv_stamp_info;
661 662

  
662 663
  pthread_mutex_lock(&xmltv_mutex);
663 664

  
......
685 686
    if(xmltv_grab_enabled == 0)
686 687
      continue;
687 688

  
688
    ts.tv_sec = time(NULL) + xmltv_grab_interval * 3600;
689
    /* If we don't have a grabber stamp file, run grabber right away */
690
    if (stat(XMLTV_GRABBER_STAMP_FILE,&xmltv_stamp_info)) ts.tv_sec = time((time_t *)NULL);
691
    /* But if we do have one, set the next grabber run to be in the future
692
       based on the grabber stamp file age plus the interval */
693
    else ts.tv_sec = xmltv_stamp_info.st_mtime + xmltv_grab_interval * 3600;
689 694

  
690 695
    if(xg_current != NULL) {
691 696
      tvhlog(LOG_INFO, "xmltv",
......
697 702

  
698 703
      pthread_mutex_unlock(&xmltv_mutex);
699 704
      
700
      xmltv_grab(p);
705
      /* See if current time has reach last grab + interval */
706
      if (time((time_t *)NULL) >= ts.tv_sec)
707
      {
708
         int xmltv_grabber_handle;
709
         /* Want to do a grab, so remove the old grab stamp file... */
710
         (void)unlink(XMLTV_GRABBER_STAMP_FILE);
711
         /* ...and create a fresh one if we can.
712
            Note that XMLTV_GRABBER_STAMP_FILE isn't deleted if
713
            tvheadend exits, so that we can retain the correct
714
            interval between runs. */
715
         xmltv_grabber_handle = creat(XMLTV_GRABBER_STAMP_FILE,S_IRUSR | S_IWUSR);
716
         if (xmltv_grabber_handle >= 0) (void)close(xmltv_grabber_handle);
717
       
718
         /* Now do the xmltv grab */
719
         xmltv_grab(p);
720
      }
701 721

  
702 722
      pthread_mutex_lock(&xmltv_mutex);
703 723
      free(p);
    (1-1/1)