[xiph-cvs] cvs commit: icecast/src connection.c slave.c source.c
Michael Smith
msmith at xiph.org
Mon Feb 17 03:56:12 PST 2003
msmith 03/02/17 06:56:12
Modified: src connection.c slave.c source.c
Log:
Fix a serious bug with source creation in relays when local-mount != mount,
and fix a series of locking bugs in source creation.
Revision Changes Path
1.51 +21 -3 icecast/src/connection.c
Index: connection.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/connection.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- connection.c 14 Feb 2003 10:31:21 -0000 1.50
+++ connection.c 17 Feb 2003 11:56:12 -0000 1.51
@@ -290,6 +290,9 @@
return con;
}
+/* TODO: Make this return an appropriate error code so that we can use HTTP
+ * codes where appropriate
+ */
int connection_create_source(client_t *client, connection_t *con, http_parser_t *parser, char *mount) {
source_t *source;
char *contenttype;
@@ -306,7 +309,7 @@
}
global.sources++;
global_unlock();
-
+
stats_event_inc(NULL, "sources");
contenttype = httpp_getvar(parser, "content-type");
@@ -324,6 +327,21 @@
ERROR0("No content-type header, falling back to backwards compatibility mode for icecast 1.x relays. Assuming content is mp3.");
source = source_create(client, con, parser, mount, format);
}
+
+ /* We did a preliminary check earlier, to catch the common case before
+ * we do any unneccesary processing. Now, we do a check that must be
+ * correct - so we have to take a write lock out, since we need to
+ * add this source if it doesn't already exist.
+ */
+ avl_tree_wlock(global.source_tree);
+ if (source_find_mount(mount) != NULL) {
+ INFO1("Source tried to log in as %s, but mountpoint is already used",
+ mount);
+ avl_tree_unlock(global.source_tree);
+ goto fail;
+ }
+ /* Keep the tree locked - it gets unlocked in source_main */
+
client->respcode = 200;
bytes = sock_write(client->con->sock,
"HTTP/1.0 200 OK\r\n\r\n");
@@ -569,15 +587,15 @@
avl_tree_rlock(global.source_tree);
if (source_find_mount(uri) != NULL) {
+ avl_tree_unlock(global.source_tree);
INFO1("Source tried to log in as %s, but mountpoint is already used", uri);
client_send_404(client, "Mountpoint in use");
- avl_tree_unlock(global.source_tree);
return;
}
avl_tree_unlock(global.source_tree);
if (!connection_create_source(client, con, parser, uri)) {
- client_destroy(client);
+ client_send_404(client, "Mountpoint in use");
}
}
<p><p>1.18 +1 -1 icecast/src/slave.c
Index: slave.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/slave.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- slave.c 12 Feb 2003 11:04:26 -0000 1.17
+++ slave.c 17 Feb 2003 11:56:12 -0000 1.18
@@ -180,7 +180,7 @@
relay = config_get_config()->relay;
while(relay) {
avl_tree_rlock(global.source_tree);
- if(!source_find_mount(relay->mount)) {
+ if(!source_find_mount(relay->localmount)) {
avl_tree_unlock(global.source_tree);
create_relay_stream(relay->server, relay->port, relay->mount,
<p><p>1.33 +6 -3 icecast/src/source.c
Index: source.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/source.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- source.c 6 Feb 2003 13:10:48 -0000 1.32
+++ source.c 17 Feb 2003 11:56:12 -0000 1.33
@@ -48,7 +48,7 @@
src->client = client;
src->mount = (char *)strdup(mount);
src->fallback_mount = NULL;
- src->format = format_get_plugin(type, src->mount);
+ src->format = format_get_plugin(type, src->mount, parser);
src->con = con;
src->parser = parser;
src->client_tree = avl_tree_new(_compare_clients, NULL);
@@ -129,6 +129,9 @@
}
+/* The caller MUST have a current write lock on global.source_tree when calling
+ * this
+ */
void *source_main(void *arg)
{
source_t *source = (source_t *)arg;
@@ -154,8 +157,8 @@
/* grab a read lock, to make sure we get a chance to cleanup */
thread_rwlock_rlock(source->shutdown_rwlock);
- /* get a write lock on the global source tree */
- avl_tree_wlock(global.source_tree);
+ /* The caller has ensured we have a write lock on the tree... */
+
/* insert source onto source tree */
avl_insert(global.source_tree, (void *)source);
/* release write lock on global source tree */
<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