Reload configuration through control socket
authorScott Lamb <slamb@slamb.org>
Wed, 7 Nov 2007 02:51:24 +0000 (02:51 +0000)
committerScott Lamb <slamb@slamb.org>
Wed, 7 Nov 2007 02:51:24 +0000 (02:51 +0000)
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.

doc/tincctl.8.in
src/control.c
src/net.c
src/net.h
src/tincctl.c

index 899b066..493adfd 100644 (file)
@@ -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
index 6a39e02..57e0ce0 100644 (file)
@@ -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;
 
index 4a680d8..b811754 100644 (file)
--- 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) {
index b8e9e37..c97d931 100644 (file)
--- 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)
index 9b16a7b..39f8942 100644 (file)
@@ -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);