diff options
author | Martin Mares <mj@ucw.cz> | 2000-01-16 17:44:50 +0100 |
---|---|---|
committer | Martin Mares <mj@ucw.cz> | 2000-01-16 17:44:50 +0100 |
commit | 50fe90edf3deab409ea7887c131bfe6ce89fa556 (patch) | |
tree | d9aad4ed34285a59cfcc0286a22ca5ccdb63a82f /sysdep/unix | |
parent | 394aec8fdd112a81da1e2f6f0e09ee74256dc24e (diff) | |
download | bird-50fe90edf3deab409ea7887c131bfe6ce89fa556.tar bird-50fe90edf3deab409ea7887c131bfe6ce89fa556.zip |
First attempt on dynamic reconfiguration. There are still lots of bugs
and problems to solve, but the hardest part works.
Diffstat (limited to 'sysdep/unix')
-rw-r--r-- | sysdep/unix/config.Y | 13 | ||||
-rw-r--r-- | sysdep/unix/krt.c | 10 | ||||
-rw-r--r-- | sysdep/unix/main.c | 85 | ||||
-rw-r--r-- | sysdep/unix/unix.h | 3 |
4 files changed, 94 insertions, 17 deletions
diff --git a/sysdep/unix/config.Y b/sysdep/unix/config.Y index f0a517e..299cc41 100644 --- a/sysdep/unix/config.Y +++ b/sysdep/unix/config.Y @@ -1,7 +1,7 @@ /* * BIRD -- UNIX Configuration * - * (c) 1999 Martin Mares <mj@ucw.cz> + * (c) 1999--2000 Martin Mares <mj@ucw.cz> * * Can be freely distributed and used under the terms of the GNU GPL. */ @@ -16,6 +16,7 @@ CF_KEYWORDS(LOG, SYSLOG, ALL, DEBUG, TRACE, INFO, REMOTE, WARNING, ERROR, AUTH, %type <i> log_mask log_mask_list log_cat %type <g> log_file +%type <t> cfg_name CF_GRAMMAR @@ -61,6 +62,16 @@ log_cat: | BUG { $$ = L_BUG[0]; } ; +/* Unix specific commands */ + +CF_CLI(CONFIGURE, cfg_name, [<file>], [[Reload configuration]]) +{ cmd_reconfig($2); } ; + +cfg_name: + /* empty */ { $$ = NULL; } + | TEXT + ; + CF_CODE CF_END diff --git a/sysdep/unix/krt.c b/sysdep/unix/krt.c index aa9a9c4..7c92c55 100644 --- a/sysdep/unix/krt.c +++ b/sysdep/unix/krt.c @@ -1,7 +1,7 @@ /* * BIRD -- UNIX Kernel Synchronization * - * (c) 1998--1999 Martin Mares <mj@ucw.cz> + * (c) 1998--2000 Martin Mares <mj@ucw.cz> * * Can be freely distributed and used under the terms of the GNU GPL. */ @@ -68,6 +68,12 @@ static timer *kif_scan_timer; static bird_clock_t kif_last_shot; static void +kif_preconfig(struct protocol *P, struct config *c) +{ + cf_kif = NULL; +} + +static void kif_scan(timer *t) { struct kif_proto *p = t->data; @@ -137,6 +143,7 @@ kif_shutdown(struct proto *P) struct protocol proto_unix_iface = { name: "Device", priority: 100, + preconfig: kif_preconfig, init: kif_init, start: kif_start, shutdown: kif_shutdown, @@ -646,6 +653,7 @@ struct proto_config *cf_krt; static void krt_preconfig(struct protocol *P, struct config *c) { + cf_krt = NULL; krt_scan_preconfig(c); } diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c index 4b9ab61..97b9dc6 100644 --- a/sysdep/unix/main.c +++ b/sysdep/unix/main.c @@ -1,7 +1,7 @@ /* * BIRD Internet Routing Daemon -- Unix Entry Point * - * (c) 1998--1999 Martin Mares <mj@ucw.cz> + * (c) 1998--2000 Martin Mares <mj@ucw.cz> * * Can be freely distributed and used under the terms of the GNU GPL. */ @@ -74,30 +74,89 @@ sysdep_preconfig(struct config *c) init_list(&c->logfiles); } -void -sysdep_commit(struct config *c) +int +sysdep_commit(struct config *new, struct config *old) { - log_switch(&c->logfiles); + log_switch(&new->logfiles); + return 0; } -static void -read_config(void) +static int +unix_read_config(struct config **cp, char *name) { - struct config *conf = config_alloc(config_name); + struct config *conf = config_alloc(name); - conf_fd = open(config_name, O_RDONLY); + *cp = conf; + conf_fd = open(name, O_RDONLY); if (conf_fd < 0) - die("Unable to open configuration file %s: %m", config_name); + return 0; cf_read_hook = cf_read; - if (!config_parse(conf)) - die("%s, line %d: %s", config_name, conf->err_lino, conf->err_msg); + return config_parse(conf); +} + +static void +read_config(void) +{ + struct config *conf; + + if (!unix_read_config(&conf, config_name)) + { + if (conf->err_msg) + die("%s, line %d: %s", config_name, conf->err_lino, conf->err_msg); + else + die("Unable to open configuration file %s: %m", config_name); + } config_commit(conf); } void async_config(void) { - debug("Asynchronous reconfigurations are not supported in demo version\n"); + struct config *conf; + + log(L_INFO "Reconfiguration requested by SIGHUP"); + if (!unix_read_config(&conf, config_name)) + { + if (conf->err_msg) + log(L_ERR "%s, line %d: %s", config_name, conf->err_lino, conf->err_msg); + else + log(L_ERR "Unable to open configuration file %s: %m", config_name); + config_free(conf); + } + else + config_commit(conf); +} + +void +cmd_reconfig(char *name) +{ + struct config *conf; + + if (!name) + name = config_name; + cli_msg(-2, "Reading configuration from %s", name); + if (!unix_read_config(&conf, name)) + { + if (conf->err_msg) + cli_msg(8002, "%s, line %d: %s", name, conf->err_lino, conf->err_msg); + else + cli_msg(8002, "%s: %m", name); + config_free(conf); + } + else + { + switch (config_commit(conf)) + { + case CONF_DONE: + cli_msg(3, "Reconfigured."); + break; + case CONF_PROGRESS: + cli_msg(4, "Reconfiguration in progress."); + break; + default: + cli_msg(5, "Reconfiguration already in progress, queueing new config"); + } + } } /* @@ -350,8 +409,6 @@ main(int argc, char **argv) cli_init_unix(); - protos_start(); - ev_run_list(&global_event_list); async_dump(); diff --git a/sysdep/unix/unix.h b/sysdep/unix/unix.h index 8dd7249..68850bc 100644 --- a/sysdep/unix/unix.h +++ b/sysdep/unix/unix.h @@ -1,7 +1,7 @@ /* * BIRD -- Declarations Common to Unix Port * - * (c) 1998 Martin Mares <mj@ucw.cz> + * (c) 1998--2000 Martin Mares <mj@ucw.cz> * * Can be freely distributed and used under the terms of the GNU GPL. */ @@ -16,6 +16,7 @@ struct pool; void async_config(void); void async_dump(void); void async_shutdown(void); +void cmd_reconfig(char *name); /* io.c */ |