Commit 1665a4f7 authored by Karl Heyes's avatar Karl Heyes

fix potential deadlock case at source stream startup

svn path=/trunk/icecast/; revision=5786
parent fbd92a91
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "event.h" #include "event.h"
#include "cfgfile.h" #include "cfgfile.h"
#include "yp.h"
#include "refbuf.h" #include "refbuf.h"
#include "client.h" #include "client.h"
...@@ -44,6 +45,7 @@ void event_config_read(void *arg) ...@@ -44,6 +45,7 @@ void event_config_read(void *arg)
config_clear(config); config_clear(config);
config_set_config(&new_config); config_set_config(&new_config);
restart_logging (); restart_logging ();
yp_recheck_config (config);
config_release_config(); config_release_config();
} }
......
...@@ -21,20 +21,25 @@ ...@@ -21,20 +21,25 @@
#define CATMODULE "yp" #define CATMODULE "yp"
static int yp_url_timeout [MAX_YP_DIRECTORIES];
void yp_recheck_config (ice_config_t *config)
{
memcpy (&config->yp_url_timeout[0], yp_url_timeout, (sizeof yp_url_timeout));
}
void yp_initialize() void yp_initialize()
{ {
ice_config_t *config = config_get_config();
yp_recheck_config (config);
config_release_config ();
thread_create("YP Touch Thread", yp_touch_thread, thread_create("YP Touch Thread", yp_touch_thread,
(void *)NULL, THREAD_DETACHED); (void *)NULL, THREAD_DETACHED);
} }
static int yp_submit_url(int curl_con, char *yp_url, char *url, char *type, static int yp_submit_url(int curl_con, char *yp_url, char *url, char *type,
int i) int timeout)
{ {
int ret = 0; int ret = 0;
int timeout;
ice_config_t *config = config_get_config();
timeout = config->yp_url_timeout[i];
config_release_config();
/* If not specified, use a reasonable timeout /* If not specified, use a reasonable timeout
of 30 seconds */ of 30 seconds */
if (timeout == 0) { if (timeout == 0) {
...@@ -74,7 +79,6 @@ static int yp_submit_url(int curl_con, char *yp_url, char *url, char *type, ...@@ -74,7 +79,6 @@ static int yp_submit_url(int curl_con, char *yp_url, char *url, char *type,
void *yp_touch_thread(void *arg) void *yp_touch_thread(void *arg)
{ {
yp_touch(); yp_touch();
thread_exit(0);
return NULL; return NULL;
} }
...@@ -114,7 +118,7 @@ int yp_remove(source_t *source) ...@@ -114,7 +118,7 @@ int yp_remove(source_t *source)
else { else {
/* specify URL to get */ /* specify URL to get */
ret = yp_submit_url(curl_con, source->ypdata[i]->yp_url, ret = yp_submit_url(curl_con, source->ypdata[i]->yp_url,
url, "yp_remove", i); url, "yp_remove", yp_url_timeout[i]);
} }
if (url) { if (url) {
free(url); free(url);
...@@ -197,6 +201,7 @@ int yp_touch() ...@@ -197,6 +201,7 @@ int yp_touch()
if (source->ypdata[i]->sid != 0) { if (source->ypdata[i]->sid != 0) {
if (strlen(source->ypdata[i]->sid) != 0) { if (strlen(source->ypdata[i]->sid) != 0) {
if (source->ypdata) { if (source->ypdata) {
struct tm tm;
url_size = url_size =
strlen("action=touch&sid=&st=&listeners=") + 1; strlen("action=touch&sid=&st=&listeners=") + 1;
if (source->ypdata[i]->current_song) { if (source->ypdata[i]->current_song) {
...@@ -231,7 +236,7 @@ int yp_touch() ...@@ -231,7 +236,7 @@ int yp_touch()
/* specify URL to get */ /* specify URL to get */
ret = yp_submit_url(curl_con, ret = yp_submit_url(curl_con,
source->ypdata[i]->yp_url, source->ypdata[i]->yp_url,
url, "yp_touch", i); url, "yp_touch", yp_url_timeout[i]);
if (!ret) { if (!ret) {
source->ypdata[i]->sid[0] = 0; source->ypdata[i]->sid[0] = 0;
} }
...@@ -241,8 +246,8 @@ int yp_touch() ...@@ -241,8 +246,8 @@ int yp_touch()
} }
curl_release_connection(curl_con); curl_release_connection(curl_con);
memset(tyme, '\000', sizeof(tyme)); memset(tyme, '\000', sizeof(tyme));
strftime(tyme, 128, "%Y-%m-%d %H:%M:%S", localtime_r (&current_time, &tm);
localtime(&current_time)); strftime(tyme, 128, "%Y-%m-%d %H:%M:%S", &tm);
stats_event(source->mount, "yp_last_touch", tyme); stats_event(source->mount, "yp_last_touch", tyme);
source->ypdata[i]->yp_last_touch = current_time; source->ypdata[i]->yp_last_touch = current_time;
} }
...@@ -378,7 +383,7 @@ int yp_add(source_t *source, int which) ...@@ -378,7 +383,7 @@ int yp_add(source_t *source, int which)
else { else {
/* specify URL to get */ /* specify URL to get */
ret = yp_submit_url(curl_con, source->ypdata[i]->yp_url, ret = yp_submit_url(curl_con, source->ypdata[i]->yp_url,
url, "yp_add", i); url, "yp_add", yp_url_timeout[i]);
if (ret) { if (ret) {
if (strlen(curl_get_header_result(curl_con)->sid) > 0) { if (strlen(curl_get_header_result(curl_con)->sid) > 0) {
......
...@@ -43,6 +43,11 @@ ypdata_t *yp_create_ypdata(); ...@@ -43,6 +43,11 @@ ypdata_t *yp_create_ypdata();
void yp_destroy_ypdata(ypdata_t *ypdata); void yp_destroy_ypdata(ypdata_t *ypdata);
void add_yp_info(struct source_tag *source, char *stat_name, void *info, void add_yp_info(struct source_tag *source, char *stat_name, void *info,
int type); int type);
#ifdef USE_YP
void yp_recheck_config (ice_config_t *config);
#else
#define yp_recheck_config(x) do{}while(0)
#endif
void yp_initialize(); void yp_initialize();
#endif #endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment