From 0229900e10d3e614af0ff68f2d5771f165e658e6 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Fri, 10 Apr 2009 11:17:37 -0400 Subject: [PATCH] Fixes requested during code review --- server/monitor/monitor.c | 41 +++++++++++++++++++++++++---------------- 1 files changed, 25 insertions(+), 16 deletions(-) diff --git a/server/monitor/monitor.c b/server/monitor/monitor.c index a98e2a6..605fa93 100644 --- a/server/monitor/monitor.c +++ b/server/monitor/monitor.c @@ -45,6 +45,7 @@ struct mt_conn { }; struct mt_svc { + struct mt_svc *first; struct mt_svc *prev; struct mt_svc *next; @@ -790,23 +791,21 @@ static int update_monitor_config(struct mt_ctx *ctx) /* New service added */ add_new_service(ctx, new_config->services[i]); } - else { /* if (ctx->services[j] == NULL) */ + else { /* Service already enabled, check for changes */ /* Locate the service object in the list */ cur_svc = ctx->svc_list; - while (cur_svc != NULL) { + for (cur_svc = ctx->svc_list; cur_svc; cur_svc = cur_svc->next) { if (strcasecmp(ctx->services[i], cur_svc->name) == 0) break; - cur_svc = cur_svc->next; } if (cur_svc == NULL) { DEBUG(0, ("Service entry missing data\n")); - /* This shouldn't be possible, but we'll create a - * new service entry and start the service if this - * happens. + /* This shouldn't be possible, but if it happens + * we'll throw an error */ - add_new_service(ctx, ctx->services[i]); - continue; + talloc_free(new_config); + return EIO; } /* Read in the new configuration and compare it with the @@ -844,13 +843,12 @@ static int update_monitor_config(struct mt_ctx *ctx) cur_svc->ping_time = new_svc->ping_time; talloc_free(new_svc); - } /* else (ctx->services[j] == NULL) */ + } } /* Replace the old service list with the new one */ talloc_free(ctx->services); - talloc_steal(ctx, new_config->services); - ctx->services = new_config->services; + ctx->services = talloc_steal(ctx, new_config->services); /* Compare data providers */ /* Have any providers been disabled? */ @@ -890,12 +888,10 @@ static int update_monitor_config(struct mt_ctx *ctx) } if (cur_svc == NULL) { DEBUG(0, ("Service entry missing data\n")); - /* This shouldn't be possible, but we'll create a - * new provider entry and start the service if this - * happens. + /* This shouldn't be possible */ - add_new_provider(ctx, new_dom->name); - continue; + talloc_free(new_config); + return EIO; } /* Read in the new configuration and compare it with @@ -937,6 +933,10 @@ static int update_monitor_config(struct mt_ctx *ctx) } + /* Replace the old domain list with the new one */ + talloc_free(ctx->domains); + ctx->domains = talloc_steal(ctx, new_config->domains); + /* Signal all services to reload their configuration */ for(cur_svc = ctx->svc_list; cur_svc; cur_svc = cur_svc->next) { service_signal_reload(cur_svc); @@ -1491,6 +1491,13 @@ static int start_service(struct mt_svc *svc) return EOK; } +static int delist_service(void *ptr) { + struct mt_svc *svc = + talloc_get_type(ptr, struct mt_svc); + if (svc->first) DLIST_REMOVE(svc->first, svc); + return EOK; +} + static void service_startup_handler(struct tevent_context *ev, struct tevent_timer *te, struct timeval t, void *ptr) @@ -1513,6 +1520,8 @@ static void service_startup_handler(struct tevent_context *ev, /* Parent */ mt_svc->last_pong = time(NULL); DLIST_ADD(mt_svc->mt_ctx->svc_list, mt_svc); + mt_svc->first = mt_svc->mt_ctx->svc_list; + talloc_set_destructor((TALLOC_CTX *)mt_svc, delist_service); set_tasks_checker(mt_svc); return; -- 1.6.0.6