From: Jaroslav Kysela Date: Mon, 3 Sep 2018 13:32:39 +0000 (+0200) Subject: dvr inotify: fixes for the previous IN_MOVED_TO change X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8327b1bf7562b7f250021471a4b73e4dc0cceb73;p=thirdparty%2Ftvheadend.git dvr inotify: fixes for the previous IN_MOVED_TO change --- diff --git a/src/dvr/dvr_inotify.c b/src/dvr/dvr_inotify.c index a8db57c09..038e3c094 100644 --- a/src/dvr/dvr_inotify.c +++ b/src/dvr/dvr_inotify.c @@ -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 (tvheadend_is_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); } diff --git a/src/tvhlog.c b/src/tvhlog.c index 1c97ffe55..f0838458e 100644 --- a/src/tvhlog.c +++ b/src/tvhlog.c @@ -141,6 +141,7 @@ tvhlog_subsys_t tvhlog_subsystems[] = { [LS_CCCAM] = { "cccam", N_("CWC CCCam 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") }, diff --git a/src/tvhlog.h b/src/tvhlog.h index b12184a92..f6b20b329 100644 --- a/src/tvhlog.h +++ b/src/tvhlog.h @@ -165,6 +165,7 @@ enum { LS_CCCAM, LS_DVBCAM, LS_DVR, + LS_DVR_INOTIFY, LS_EPG, LS_EPGDB, LS_EPGGRAB,