]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
dvr inotify: fixes for the previous IN_MOVED_TO change
authorJaroslav Kysela <perex@perex.cz>
Mon, 3 Sep 2018 13:32:39 +0000 (15:32 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 3 Sep 2018 13:43:04 +0000 (15:43 +0200)
src/dvr/dvr_inotify.c
src/tvhlog.c
src/tvhlog.h

index ef6b82e42b43e0c7c43e6d015530f17ca2a263f6..b96c3866df4bf6b61b58f4840bbdfd54ab0f5d7e 100644 (file)
@@ -31,9 +31,9 @@
 #include "htsp_server.h"
 
 /* inotify limits */
-#define EVENT_SIZE    ( sizeof (struct inotify_event) )
-#define EVENT_BUF_LEN ( 10 * ( EVENT_SIZE + 16 ) )
-#define EVENT_MASK    IN_DELETE     | IN_DELETE_SELF |\
+#define EVENT_SIZE    (sizeof(struct inotify_event))
+#define EVENT_BUF_LEN (5 * EVENT_SIZE + NAME_MAX)
+#define EVENT_MASK    IN_DELETE    | IN_DELETE_SELF | \
                       IN_MOVE_SELF | IN_MOVED_FROM | IN_MOVED_TO
                       
 static int                         _inot_fd;
@@ -378,11 +378,10 @@ void* _dvr_inotify_thread ( void *p )
   const char *from;
   int fromfd;
   int cookie;
-  char from_prev[50];
-  int fromfd_prev =0;
-  int cookie_prev =0;
-
-  from_prev[0] = '\0';
+  struct inotify_event *ev;
+  char from_prev[NAME_MAX + 1] = "";
+  int fromfd_prev = 0;
+  int cookie_prev = 0;
 
   while (atomic_get(&tvheadend_running)) {
 
@@ -400,9 +399,9 @@ void* _dvr_inotify_thread ( void *p )
 
     /* Process */
     pthread_mutex_lock(&global_lock);
-    while ( i < len ) {
-      struct inotify_event *ev = (struct inotify_event*)&buf[i];
-    tvhdebug(LS_DVR, "inotify: i= %d   len= %d   ", i, len);
+    while (i < len) {
+      ev = (struct inotify_event *)&buf[i];
+      tvhtrace(LS_DVR_INOTIFY, "i=%d len=%d name=%s", i, len, ev->name);
       i += EVENT_SIZE + ev->len;
       if (i > len)
         break;
@@ -412,12 +411,12 @@ void* _dvr_inotify_thread ( void *p )
         from   = ev->name;
         fromfd = ev->wd;
         cookie = ev->cookie;
-      tvhdebug(LS_DVR, "inotify: i= %d   len= %d   from = %s   cookie = %d ", i, len, from, cookie);
+        tvhtrace(LS_DVR_INOTIFY, "i=%d len=%d from=%s cookie=%d ", i, len, from, cookie);
         continue;
 
       } else if (ev->mask & IN_MOVED_TO) {
-    tvhdebug(LS_DVR, "inotify: i= %d   len= %d    to_cookie= %d   from_cookie = %d   cookie_prev = %d", i, len, ev->cookie,cookie,cookie_prev);
-          if ( from && ev->cookie == cookie) {
+        tvhtrace(LS_DVR_INOTIFY, "i=%d len=%d to_cookie=%d from_cookie=%d cookie_prev=%d", i, len, ev->cookie, cookie, cookie_prev);
+          if (from && ev->cookie == cookie) {
             _dvr_inotify_moved(fromfd, from, ev->name, ev->wd);
             from = NULL;
            cookie = 0;
@@ -439,26 +438,19 @@ void* _dvr_inotify_thread ( void *p )
       } else if (ev->mask & IN_DELETE_SELF) {
         _dvr_inotify_delete_all(ev->wd);
       }
-/*
-      if (from) {
-        _dvr_inotify_moved(fromfd, from, NULL, -1);
-        from   = NULL;
-        cookie = 0;
-      }
-*/
     }
-    //  if still old "from", assume matching "to" is not coming
+    // if still old "from", assume matching "to" is not coming
     if (from_prev[0] != '\0') {
       _dvr_inotify_moved(fromfd_prev, from_prev, NULL, -1);
       from_prev[0] = '\0';
       cookie_prev = 0;
     }
-    //  if unmatched "from", save in case matching "to" is coming in next read
+    // if unmatched "from", save in case matching "to" is coming in next read
     if (from) {
-      strcpy ( from_prev, from);
+      strcpy(from_prev, from);
       fromfd_prev = fromfd;
       cookie_prev = cookie;
-      tvhdebug(LS_DVR, "inotify: i= %d   len= %d      cookie_prev = %d   from_prev = %s  fd = %d   END OF READ", i, len, cookie_prev, from_prev, fromfd_prev);
+      tvhdebug(LS_DVR_INOTIFY, "i=%d len=%d cookie_prev=%d from_prev=%s fd=%d EOR", i, len, cookie_prev, from_prev, fromfd_prev);
     }
     pthread_mutex_unlock(&global_lock);
   }
index 26d7e3733e08a8c6f573febd23eb1e01677433a6..f0e3ec61ac0f4b127475cf640bcf80c2346f04a3 100644 (file)
@@ -139,6 +139,7 @@ tvhlog_subsys_t tvhlog_subsystems[] = {
   [LS_CWC]           = { "cwc",           N_("CWC CA Client") },
   [LS_DVBCAM]        = { "dvbcam",        N_("DVB CAM Client") },
   [LS_DVR]           = { "dvr",           N_("Digital Video Recorder") },
+  [LS_DVR_INOTIFY]   = { "dvr-inotify",   N_("DVR Inotify") },
   [LS_EPG]           = { "epg",           N_("Electronic Program Guide") },
   [LS_EPGDB]         = { "epgdb",         N_("EPG Database") },
   [LS_EPGGRAB]       = { "epggrab",       N_("EPG Grabber") },
index c4aff87c9e6007b29ec06a4678374a4c29dd9cdc..34530959ac5573784e2249a31febc45c49d9e549 100644 (file)
@@ -163,6 +163,7 @@ enum {
   LS_CWC,
   LS_DVBCAM,
   LS_DVR,
+  LS_DVR_INOTIFY,
   LS_EPG,
   LS_EPGDB,
   LS_EPGGRAB,