]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
idnode api: fix the broken locking in api_idnode_load()
authorJaroslav Kysela <perex@perex.cz>
Tue, 8 Sep 2015 18:10:56 +0000 (20:10 +0200)
committerJaroslav Kysela <perex@perex.cz>
Fri, 25 Sep 2015 13:56:19 +0000 (15:56 +0200)
src/api/api_idnode.c

index 7a4221a077541dbf73192e446d2570647b99863a..a969fadeaaeaaae87a38645ee93b92c96680e85f 100644 (file)
@@ -165,8 +165,8 @@ api_idnode_grid
   return 0;
 }
 
-int
-api_idnode_load_by_class
+static int
+api_idnode_load_by_class0
   ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
 {
   int i, _enum;
@@ -178,8 +178,6 @@ api_idnode_load_by_class
   // TODO: this only works if pass as integer
   _enum = htsmsg_get_bool_or_default(args, "enum", 0);
 
-  pthread_mutex_lock(&global_lock);
-
   /* Find class */
   idc = opaque;
   assert(idc);
@@ -211,14 +209,24 @@ api_idnode_load_by_class
     free(is->is_array);
     free(is);
   }
+
   *resp = htsmsg_create_map();
   htsmsg_add_msg(*resp, "entries", l);
 
-  pthread_mutex_unlock(&global_lock);
-
   return 0;
 }
 
+int
+api_idnode_load_by_class
+  ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
+{
+  int ret;
+  pthread_mutex_lock(&global_lock);
+  ret = api_idnode_load_by_class0(perm, opaque, op, args, resp);
+  pthread_mutex_unlock(&global_lock);
+  return ret;
+}
+
 static int
 api_idnode_load
   ( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
@@ -235,11 +243,12 @@ api_idnode_load
     const idclass_t *idc;
     pthread_mutex_lock(&global_lock);
     idc = idclass_find(class);
+    if (idc)
+      err = api_idnode_load_by_class0(perm, (void*)idc, NULL, args, resp);
+    else
+      err = EINVAL;
     pthread_mutex_unlock(&global_lock);
-    if (!idc)
-      return EINVAL;
-    // TODO: bit naff that 2 locks are required here
-    return api_idnode_load_by_class(perm, (void*)idc, NULL, args, resp);
+    return err;
   }
   
   /* UUIDs */