From 1665a4f7d96c28c60e89a8192b0c3b238e231f75 Mon Sep 17 00:00:00 2001 From: Karl Heyes Date: Mon, 26 Jan 2004 22:42:22 +0000 Subject: [PATCH] fix potential deadlock case at source stream startup svn path=/trunk/icecast/; revision=5786 --- src/event.c | 2 ++ src/yp.c | 29 +++++++++++++++++------------ src/yp.h | 5 +++++ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/event.c b/src/event.c index 97f32a86..73be57bc 100644 --- a/src/event.c +++ b/src/event.c @@ -4,6 +4,7 @@ #include "event.h" #include "cfgfile.h" +#include "yp.h" #include "refbuf.h" #include "client.h" @@ -44,6 +45,7 @@ void event_config_read(void *arg) config_clear(config); config_set_config(&new_config); restart_logging (); + yp_recheck_config (config); config_release_config(); } diff --git a/src/yp.c b/src/yp.c index 2c35089c..73beef37 100644 --- a/src/yp.c +++ b/src/yp.c @@ -21,20 +21,25 @@ #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() { + ice_config_t *config = config_get_config(); + yp_recheck_config (config); + config_release_config (); thread_create("YP Touch Thread", yp_touch_thread, (void *)NULL, THREAD_DETACHED); } static int yp_submit_url(int curl_con, char *yp_url, char *url, char *type, - int i) + int timeout) { 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 of 30 seconds */ if (timeout == 0) { @@ -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) { yp_touch(); - thread_exit(0); return NULL; } @@ -114,7 +118,7 @@ int yp_remove(source_t *source) else { /* specify URL to get */ ret = yp_submit_url(curl_con, source->ypdata[i]->yp_url, - url, "yp_remove", i); + url, "yp_remove", yp_url_timeout[i]); } if (url) { free(url); @@ -197,6 +201,7 @@ int yp_touch() if (source->ypdata[i]->sid != 0) { if (strlen(source->ypdata[i]->sid) != 0) { if (source->ypdata) { + struct tm tm; url_size = strlen("action=touch&sid=&st=&listeners=") + 1; if (source->ypdata[i]->current_song) { @@ -231,7 +236,7 @@ int yp_touch() /* specify URL to get */ ret = yp_submit_url(curl_con, source->ypdata[i]->yp_url, - url, "yp_touch", i); + url, "yp_touch", yp_url_timeout[i]); if (!ret) { source->ypdata[i]->sid[0] = 0; } @@ -241,8 +246,8 @@ int yp_touch() } curl_release_connection(curl_con); memset(tyme, '\000', sizeof(tyme)); - strftime(tyme, 128, "%Y-%m-%d %H:%M:%S", - localtime(¤t_time)); + localtime_r (¤t_time, &tm); + strftime(tyme, 128, "%Y-%m-%d %H:%M:%S", &tm); stats_event(source->mount, "yp_last_touch", tyme); source->ypdata[i]->yp_last_touch = current_time; } @@ -378,7 +383,7 @@ int yp_add(source_t *source, int which) else { /* specify URL to get */ 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 (strlen(curl_get_header_result(curl_con)->sid) > 0) { diff --git a/src/yp.h b/src/yp.h index 8ae95280..56679cfd 100644 --- a/src/yp.h +++ b/src/yp.h @@ -43,6 +43,11 @@ ypdata_t *yp_create_ypdata(); void yp_destroy_ypdata(ypdata_t *ypdata); void add_yp_info(struct source_tag *source, char *stat_name, void *info, 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(); #endif