[xiph-cvs] cvs commit: icecast/src source.c

Karl Heyes karl at xiph.org
Mon Feb 16 16:09:15 PST 2004



karl        04/02/16 19:09:14

  Modified:    src      source.c
  Log:
  fix possible bad pointer reference when finding fallback mount

Revision  Changes    Path
1.69      +36 -35    icecast/src/source.c

Index: source.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/source.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -r1.68 -r1.69
--- source.c	16 Feb 2004 21:59:08 -0000	1.68
+++ source.c	17 Feb 2004 00:09:14 -0000	1.69
@@ -145,55 +145,56 @@
     return NULL;
 }
 
-static source_t *source_find_mount_recursive(const char *mount, int depth)
+
+/* Search for mount, if the mount is there but not currently running then
+ * check it's fallback, and so on.  Must have a global source lock to call
+ * this function.
+ */
+source_t *source_find_mount (const char *mount)
 {
-    source_t *source = source_find_mount_raw(mount);
-    mount_proxy *mountinfo;
+    source_t *source = NULL;
     ice_config_t *config;
-    char *fallback_mount;
-    
-    if(source == NULL) {
-        if(depth > MAX_FALLBACK_DEPTH)
-            return NULL;
+    mount_proxy *mountinfo;
+    int depth = 0;
+
+    config = config_get_config();
+    while (mount != NULL)
+    {
+        /* limit the number of times through, maybe infinite */
+        if (depth > MAX_FALLBACK_DEPTH)
+        {
+            source = NULL;
+            break;
+        }
 
-        /* Look for defined mounts to find a fallback source */
+        source = source_find_mount_raw(mount);
+        if (source == NULL)
+            break; /* fallback to missing mountpoint */
 
-        config = config_get_config();
-        mountinfo = config->mounts;
-        thread_mutex_lock(&(config_locks()->mounts_lock));
-        config_release_config();
+        if (source->running)
+            break;
 
-        while(mountinfo) {
-            if(!strcmp(mountinfo->mountname, mount))
+        /* source is not running, meaning that the fallback is not configured
+           within the source, we need to check the mount list */
+        mountinfo = config->mounts;
+        source = NULL;
+        while (mountinfo)
+        {
+            if (strcmp (mountinfo->mountname, mount) == 0)
                 break;
             mountinfo = mountinfo->next;
         }
-        
-        if(mountinfo)
-            fallback_mount = mountinfo->fallback_mount;
+        if (mountinfo)
+            mount = mountinfo->fallback_mount;
         else
-            fallback_mount = NULL;
-
-        thread_mutex_unlock(&(config_locks()->mounts_lock));
-
-        if(fallback_mount != NULL) {
-            return source_find_mount_recursive(fallback_mount, depth+1);
-        }
+            mount = NULL;
+        depth++;
     }
 
+    config_release_config();
     return source;
 }
 
-/* you must already have a read lock on the global source tree
-** to call this function
-*/
-source_t *source_find_mount(const char *mount)
-{
-    if (!mount)
-        return NULL;
-
-    return source_find_mount_recursive(mount, 0);
-}
 
 int source_compare_sources(void *arg, void *a, void *b)
 {

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list