diff --git a/src/cfgfile.c b/src/cfgfile.c index 4a4f94f9..8cf7dddc 100644 --- a/src/cfgfile.c +++ b/src/cfgfile.c @@ -87,13 +87,13 @@ static void _add_server(xmlDocPtr doc, xmlNodePtr node, ice_config_t *c); static void create_locks() { thread_mutex_create(&_locks.relay_lock); thread_mutex_create(&_locks.mounts_lock); - thread_mutex_create(&_locks.config_lock); + thread_rwlock_create(&_locks.config_lock); } static void release_locks() { thread_mutex_destroy(&_locks.relay_lock); thread_mutex_destroy(&_locks.mounts_lock); - thread_mutex_destroy(&_locks.config_lock); + thread_rwlock_destroy(&_locks.config_lock); } void config_initialize(void) { @@ -226,7 +226,7 @@ void config_clear(ice_config_t *c) } #ifdef USE_YP i = 0; - while (i < c->num_yp_directories) + while (i < c->num_yp_directories) { xmlFree (c->yp_url[i]); i++; @@ -291,12 +291,18 @@ ice_config_locks *config_locks(void) void config_release_config(void) { - thread_mutex_unlock(&(_locks.config_lock)); + thread_rwlock_unlock(&(_locks.config_lock)); } ice_config_t *config_get_config(void) { - thread_mutex_lock(&(_locks.config_lock)); + thread_rwlock_rlock(&(_locks.config_lock)); + return &_current_configuration; +} + +ice_config_t *config_grab_config(void) +{ + thread_rwlock_wlock(&(_locks.config_lock)); return &_current_configuration; } @@ -614,7 +620,6 @@ static void _parse_mount(xmlDocPtr doc, xmlNodePtr node, mount->burst_size = atoi(tmp); if (tmp) xmlFree(tmp); } else if (strcmp(node->name, "cluster-password") == 0) { - tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); mount->cluster_password = (char *)xmlNodeListGetString( doc, node->xmlChildrenNode, 1); } diff --git a/src/cfgfile.h b/src/cfgfile.h index 1d8e8837..3617fba1 100644 --- a/src/cfgfile.h +++ b/src/cfgfile.h @@ -146,7 +146,7 @@ typedef struct ice_config_tag } ice_config_t; typedef struct { - mutex_t config_lock; + rwlock_t config_lock; mutex_t relay_lock; mutex_t mounts_lock; } ice_config_locks; @@ -165,6 +165,7 @@ int config_rehash(void); ice_config_locks *config_locks(void); ice_config_t *config_get_config(void); +ice_config_t *config_grab_config(void); void config_release_config(void); /* To be used ONLY in one-time startup code */ diff --git a/src/event.c b/src/event.c index f8564aa0..0aa032e4 100644 --- a/src/event.c +++ b/src/event.c @@ -32,7 +32,7 @@ void event_config_read(void *arg) ice_config_t new_config; /* reread config file */ - config = config_get_config(); /* Both to get the lock, and to be able + config = config_grab_config(); /* Both to get the lock, and to be able to find out the config filename */ ret = config_parse_file(config->config_filename, &new_config); if(ret < 0) {