diff options
Diffstat (limited to 'conf')
-rw-r--r-- | conf/conf.c | 34 | ||||
-rw-r--r-- | conf/conf.h | 6 |
2 files changed, 37 insertions, 3 deletions
diff --git a/conf/conf.c b/conf/conf.c index 1c5401b..c3f5234 100644 --- a/conf/conf.c +++ b/conf/conf.c @@ -25,6 +25,7 @@ static jmp_buf conf_jmpbuf; struct config *config, *new_config, *old_config, *future_config; static event *config_event; +int shutting_down; struct config * config_alloc(byte *name) @@ -100,11 +101,13 @@ config_del_obstacle(struct config *c) } static int -global_commit(struct config *c, struct config *old) +global_commit(struct config *new, struct config *old) { if (!old) return 0; - if (c->router_id != old->router_id) + if (!new->router_id) + new->router_id = old->router_id; + if (new->router_id != old->router_id) return 1; return 0; } @@ -116,7 +119,7 @@ config_do_commit(struct config *c) DBG("do_commit\n"); old_config = config; - config = c; + config = new_config = c; if (old_config) old_config->obstacle_count++; DBG("sysdep_commit\n"); @@ -144,6 +147,8 @@ config_done(void *unused) DBG("config_done\n"); for(;;) { + if (config->shutdown) + sysdep_shutdown_done(); log(L_INFO "Reconfigured"); if (old_config) { @@ -171,6 +176,12 @@ config_commit(struct config *c) } if (old_config) /* Reconfiguration already in progress */ { + if (shutting_down) + { + log(L_INFO "New configuration discarded due to shutdown"); + config_free(c); + return CONF_SHUTDOWN; + } if (future_config) { log(L_INFO "Queueing new configuration, ignoring the one already queued"); @@ -195,6 +206,23 @@ config_commit(struct config *c) } void +order_shutdown(void) +{ + struct config *c; + + if (shutting_down) + return; + log(L_INFO "Shutting down"); + c = lp_alloc(config->mem, sizeof(struct config)); + memcpy(c, config, sizeof(struct config)); + init_list(&c->protos); + init_list(&c->tables); + c->shutdown = 1; + config_commit(c); + shutting_down = 1; +} + +void cf_error(char *msg, ...) { char buf[1024]; diff --git a/conf/conf.h b/conf/conf.h index 7d13ae9..9fe133e 100644 --- a/conf/conf.h +++ b/conf/conf.h @@ -27,6 +27,7 @@ struct config { struct symbol **sym_hash; /* Lexer: symbol hash table */ struct symbol **sym_fallback; /* Lexer: fallback symbol hash table */ int obstacle_count; /* Number of items blocking freeing of this config */ + int shutdown; /* This is a pseudo-config for daemon shutdown */ }; /* Please don't use these variables in protocols. Use proto_config->global instead. */ @@ -35,6 +36,8 @@ extern struct config *new_config; /* Configuration being parsed */ extern struct config *old_config; /* Old configuration when reconfiguration is in progress */ extern struct config *future_config; /* New config held here if recon requested during recon */ +extern int shutting_down; + struct config *config_alloc(byte *name); int config_parse(struct config *); int cli_parse(struct config *); @@ -43,10 +46,12 @@ int config_commit(struct config *); void cf_error(char *msg, ...) NORET; void config_add_obstacle(struct config *); void config_del_obstacle(struct config *); +void order_shutdown(void); #define CONF_DONE 0 #define CONF_PROGRESS 1 #define CONF_QUEUED 2 +#define CONF_SHUTDOWN 3 /* Pools */ @@ -98,5 +103,6 @@ int cf_parse(void); void sysdep_preconfig(struct config *); int sysdep_commit(struct config *, struct config *); +void sysdep_shutdown_done(void); #endif |