From: Scott Lamb Date: Wed, 7 Nov 2007 02:51:24 +0000 (+0000) Subject: Reload configuration through control socket X-Git-Tag: import-tinc-1.1~610 X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=d82fcc88f355e3c8144478a860dfae0b299004a9;p=meshlink Reload configuration through control socket I also kept the SIGHUP handler, which many people will expect to see. The control socket is better, though - it will tell you if there is a problem. --- diff --git a/doc/tincctl.8.in b/doc/tincctl.8.in index 899b0667..493adfd0 100644 --- a/doc/tincctl.8.in +++ b/doc/tincctl.8.in @@ -93,9 +93,15 @@ and if .Xr tincd 8 didn't succeed to connect to an uplink the first time after it started, it defaults to the maximum time of 15 minutes. +.It reload +Partially rereads configuration files. +Connections to hosts whose host config files are removed are closed. +New outgoing connections specified in +.Pa tinc.conf +will be made. .El .Sh BUGS -The "start", "restart", and "reload" commands are not yet implemented. +The "start" and "restart" commands are not yet implemented. .Pp If you find any bugs, report them to tinc@tinc-vpn.org. .Sh SEE ALSO diff --git a/src/control.c b/src/control.c index 6a39e02e..57e0ce09 100644 --- a/src/control.c +++ b/src/control.c @@ -130,6 +130,12 @@ static void handle_control_data(struct bufferevent *event, void *data) { goto respond; } + if(req.type == REQ_RELOAD) { + logger(LOG_NOTICE, _("Got '%s' command"), "reload"); + res.res_errno = reload_configuration(); + goto respond; + } + logger(LOG_DEBUG, _("Malformed control command received")); res.res_errno = EINVAL; diff --git a/src/net.c b/src/net.c index 4a680d8e..b811754a 100644 --- a/src/net.c +++ b/src/net.c @@ -234,13 +234,16 @@ static void sigterm_handler(int signal, short events, void *data) { } static void sighup_handler(int signal, short events, void *data) { + logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal)); + reload_configuration(); +} + +int reload_configuration(void) { connection_t *c; splay_node_t *node, *next; char *fname; struct stat s; static time_t last_config_check = 0; - - logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal)); /* Reread our own configuration file */ @@ -250,7 +253,7 @@ static void sighup_handler(int signal, short events, void *data) { if(!read_server_config()) { logger(LOG_ERR, _("Unable to reread configuration file, exitting.")); event_loopexit(NULL); - return; + return EINVAL; } /* Close connections to hosts that have a changed or deleted host config file */ @@ -278,6 +281,8 @@ static void sighup_handler(int signal, short events, void *data) { /* Try to make outgoing connections */ try_outgoing_connections(); + + return 0; } void retry(void) { diff --git a/src/net.h b/src/net.h index b8e9e377..c97d9312 100644 --- a/src/net.h +++ b/src/net.h @@ -157,6 +157,7 @@ extern void handle_meta_connection_data(int, short, void *); extern void regenerate_key(); extern void purge(void); extern void retry(void); +extern int reload_configuration(void); #ifndef HAVE_MINGW #define closesocket(s) close(s) diff --git a/src/tincctl.c b/src/tincctl.c index 9b16a7b7..39f89426 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -92,6 +92,7 @@ static void usage(bool status) { " purge Purge unreachable nodes\n" " debug N Set debug level\n" " retry Retry all outgoing connections\n" + " reload Partial reload of configuration\n" "\n")); printf(_("Report bugs to tinc@tinc-vpn.org.\n")); } @@ -601,6 +602,10 @@ int main(int argc, char *argv[], char *envp[]) { return send_ctl_request_cooked(fd, REQ_RETRY, NULL, 0) != -1; } + if(!strcasecmp(argv[optind], "reload")) { + return send_ctl_request_cooked(fd, REQ_RELOAD, NULL, 0) != -1; + } + fprintf(stderr, _("Unknown command `%s'.\n"), argv[optind]); usage(true);