]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
cclang: supress thread sanitizer warnings, fix some data concurrency clashes
authorJaroslav Kysela <perex@perex.cz>
Mon, 15 Jan 2018 12:13:56 +0000 (13:13 +0100)
committerJaroslav Kysela <perex@perex.cz>
Mon, 15 Jan 2018 12:13:56 +0000 (13:13 +0100)
src/descrambler/capmt.c
src/dvr/dvr_inotify.c
src/epggrab/module.c
src/fsmonitor.c
src/packet.c
src/streaming.c
src/tvheadend.h
src/wrappers.c

index 8f27477c22068fd71e98bb07ba89cdf3d45a1f56..b9148616e13e841de4e3952d27783b892f23db0b 100644 (file)
@@ -190,6 +190,7 @@ typedef struct capmt_service {
 
   /* PIDs list */
   uint16_t ct_pids[MAX_PIDS];
+  uint8_t  ct_multipid;
 
   /* Elementary stream types */
   uint8_t ct_types[MAX_PIDS];
@@ -1117,7 +1118,7 @@ capmt_process_key(capmt_t *capmt, uint8_t adapter, ca_info_t *cai,
   mpegts_service_t *t;
   capmt_service_t *ct;
   uint16_t *pids;
-  int i, j, pid, multipid;
+  int i, j, pid;
 
   pthread_mutex_lock(&capmt->capmt_mutex);
   LIST_FOREACH(ct, &capmt->capmt_services, ct_link) {
@@ -1136,8 +1137,6 @@ capmt_process_key(capmt_t *capmt, uint8_t adapter, ca_info_t *cai,
     if (adapter != ct->ct_adapter)
       continue;
 
-    multipid = descrambler_multi_pid((th_descrambler_t *)ct);
-
     pids = cai->pids;
 
     for (i = 0; i < MAX_PIDS; i++) {
@@ -1146,7 +1145,7 @@ capmt_process_key(capmt_t *capmt, uint8_t adapter, ca_info_t *cai,
         pid = ct->ct_pids[j];
         if (pid == 0) break;
         if (pid == pids[i]) {
-          if (multipid) {
+          if (ct->ct_multipid) {
             ct->ct_ok_flag = 1;
             descrambler_keys((th_descrambler_t *)ct, type, pid, even, odd);
             continue;
@@ -2456,6 +2455,7 @@ capmt_service_start(caclient_t *cac, service_t *s)
   ct              = calloc(1, sizeof(capmt_service_t));
   ct->ct_capmt    = capmt;
   ct->ct_adapter  = tuner;
+  ct->ct_multipid = descrambler_multi_pid((th_descrambler_t *)ct);
 
   i = 0;
   TAILQ_FOREACH(st, &t->s_filt_components, es_filt_link) {
index 5d7a41a80bf3fb5413a0fc8daaef944bce993bda..979fb02892871df944baa4074854d98b3be16c5d 100644 (file)
@@ -85,7 +85,7 @@ void dvr_inotify_init ( void )
 void dvr_inotify_done ( void )
 {
   int fd = atomic_exchange(&_inot_fd, -1);
-  if (fd >= 0) close(fd);
+  if (fd >= 0) blacklisted_close(fd);
   pthread_kill(dvr_inotify_tid, SIGTERM);
   pthread_join(dvr_inotify_tid, NULL);
   SKEL_FREE(dvr_inotify_entry_skel);
index 9e502138099178c2e599370ba37ee59efe4d5b1f..9ba1a277c9b23a5ce69ef483eca94edd0ca68ac1 100644 (file)
@@ -581,13 +581,13 @@ static void _epggrab_socket_handler ( epggrab_module_ext_t *mod, int s )
  */
 static void *_epggrab_socket_thread ( void *p )
 {
-  int s;
+  int s, s1;
   epggrab_module_ext_t *mod = (epggrab_module_ext_t*)p;
   tvhinfo(mod->subsys, "%s: external socket enabled", mod->id);
 
-  while ( mod->enabled && mod->sock ) {
+  while ( mod->enabled && (s1 = atomic_get(&mod->sock)) ) {
     tvhdebug(mod->subsys, "%s: waiting for connection", mod->id);
-    s = accept(mod->sock, NULL, NULL);
+    s = accept(s1, NULL, NULL);
     if (s <= 0) continue;
     tvhdebug(mod->subsys, "%s: got connection %d", mod->id, s);
     _epggrab_socket_handler(mod, s);
@@ -608,8 +608,7 @@ epggrab_module_done_socket( void *m )
 
   assert(mod->type == EPGGRAB_EXT);
   mod->active = 0;
-  sock = mod->sock;
-  mod->sock = 0;
+  sock = atomic_exchange(&mod->sock, 0);
   shutdown(sock, SHUT_RDWR);
   close(sock);
   if (mod->tid) {
@@ -647,8 +646,8 @@ epggrab_module_activate_socket ( void *m, int a )
     unlink(mod->path); // just in case!
     hts_settings_makedirs(mod->path);
 
-    mod->sock = socket(AF_UNIX, SOCK_STREAM, 0);
-    assert(mod->sock);
+    atomic_set(&mod->sock, socket(AF_UNIX, SOCK_STREAM, 0));
+    assert(atomic_get(&mod->sock));
 
     memset(&addr, 0, sizeof(struct sockaddr_un));
     addr.sun_family = AF_UNIX;
index 5993b1d83a6de2ab3f2d63706bcd587eeacc7dc8..f5a8ef7eb68256060497e7e4658058123c90a0ad 100644 (file)
@@ -120,7 +120,7 @@ void
 fsmonitor_done ( void )
 {
   int fd = atomic_exchange(&fsmonitor_fd, -1);
-  if (fd >= 0) close(fd);
+  if (fd >= 0) blacklisted_close(fd);
   pthread_kill(fsmonitor_tid, SIGTERM);
   pthread_join(fsmonitor_tid, NULL);
 }
index 688b8a953a49ce0480e51d2d763a5008bcd67117..f8012ec3e8bea5fbf440231ea162d146a076318b 100644 (file)
@@ -92,7 +92,7 @@ pkt_copy_shallow(th_pkt_t *pkt)
   th_pkt_t *n = malloc(sizeof(th_pkt_t));
 
   if (n) {
-    *n = *pkt;
+    blacklisted_memcpy(n, pkt, sizeof(*pkt));
 
     n->pkt_refcount = 1;
 
index 2d55f210a10b71bccbcb282ed35a8e87af32a875..a6af42a94c51947571f43d5f49b74a369a9e1987 100644 (file)
@@ -95,8 +95,12 @@ static htsmsg_t *
 streaming_queue_info(void *opaque, htsmsg_t *list)
 {
   streaming_queue_t *sq = opaque;
+  size_t size;
   char buf[256];
-  snprintf(buf, sizeof(buf), "streaming queue %p size %zd", sq, sq->sq_size);
+  pthread_mutex_lock(&sq->sq_mutex);
+  size = sq->sq_size;
+  pthread_mutex_unlock(&sq->sq_mutex);
+  snprintf(buf, sizeof(buf), "streaming queue %p size %zd", sq, size);
   htsmsg_add_str(list, NULL, buf);
   return list;
 }
index 6f7274afb3a2163a449a22dd72006320a0be4405..e84a62f0ad46a9b72586a2acd121da607abd5a70 100644 (file)
@@ -831,4 +831,13 @@ void tvh_qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void
 #define TVH_NAME_LEN 32
 #define TVH_TITLE_LEN 256
 
+/* sanitizer helpers */
+#if __has_feature(thread_sanitizer)
+void *blacklisted_memcpy(void *dest, const void *src, size_t n);
+int blacklisted_close(int fildes);
+#else
+#define blacklisted_memcpy memcpy
+#define blacklisted_close close
+#endif
+
 #endif /* TVHEADEND_H */
index 83a69e135d4a50f41118b5a32dfe0d4cb93a5c2c..02a58be85c1a3f0632a498a820f82f57c9c36ab5 100644 (file)
@@ -650,3 +650,25 @@ int regex_match_substring_length(tvh_regex_t *regex, unsigned number)
   }
 #endif
 }
+
+/*
+ * Sanitizer helpers to avoid false positives
+ */
+#if __has_feature(thread_sanitizer)
+void *blacklisted_memcpy(void *dest, const void *src, size_t n)
+  __attribute__((no_sanitize("thread")))
+{
+  uint8_t *d = dest, *s = src;
+  while (n-- > 0) *d++ = *s++;
+  return dest;
+}
+
+void *dlsym(void *handle, const char *symbol);
+
+int blacklisted_close(int fd)
+  __attribute__((no_sanitize("thread")))
+{
+  // close(fd); // sanitizer reports errors in close()
+  return 0;
+}
+#endif