Alter debugging levels through control socket
authorScott Lamb <slamb@slamb.org>
Wed, 7 Nov 2007 02:50:27 +0000 (02:50 +0000)
committerScott Lamb <slamb@slamb.org>
Wed, 7 Nov 2007 02:50:27 +0000 (02:50 +0000)
doc/tinc.texi
doc/tincctl.8.in
doc/tincd.8.in
src/control.c
src/control_common.h
src/net.c
src/tincctl.c

index e9534728fdff9d1ae7c42542645dcdcb8df1a352..b3f570c69d03b263b9ee6ceb5d69eed9a370a46b 100644 (file)
@@ -1565,10 +1565,6 @@ Partially rereads configuration files.
 Connections to hosts whose host config file are removed are closed.
 New outgoing connections specified in @file{tinc.conf} will be made.
 
-@item INT
-Temporarily increases debug level to 5.
-Send this signal again to revert to the original level.
-
 @end table
 
 @c ==================================================================
@@ -1854,6 +1850,9 @@ Dump a graph of the VPN in dotty format.
 @item purge
 Purges all information remembered about unreachable nodes.
 
+@item debug @var{level}
+Sets debug level to @var{level}.
+
 @end table
 
 
index 40bd13618720b3eb04aa543114e2d165d722f86a..623c908b6c5447e13f0c66e99f75d788ce717668 100644 (file)
@@ -78,6 +78,9 @@ Dump a graph of the VPN in
 format.
 .It purge
 Purges all information remembered about unreachable nodes.
+.It debug Ar N
+Sets debug level to
+.Ar N .
 .El
 .Sh BUGS
 The "start", "restart", and "reload" commands are not yet implemented.
index 96c773f15ec0884c63cfa70709da662c72eb901a..b3142e829006cba0253aac93d2ac184eac95fd43 100644 (file)
@@ -95,9 +95,6 @@ Connections to hosts whose host config file are removed are closed.
 New outgoing connections specified in
 .Pa tinc.conf
 will be made.
-.It INT
-Temporarily increases debug level to 5.
-Send this signal again to revert to the original level.
 .El
 .Sh DEBUG LEVELS
 The tinc daemon can send a lot of messages to the syslog.
index 2c5d4be847eba078069795c134f4cce929ff2d64..3e57f5512f4f759b1043ea23d0634232b7c0cdef 100644 (file)
@@ -38,6 +38,7 @@ static void handle_control_data(struct bufferevent *event, void *data) {
        size_t size;
        tinc_ctl_request_t res;
        struct evbuffer *res_data = NULL;
+       void *req_data;
 
        if(EVBUFFER_LENGTH(event->input) < sizeof(tinc_ctl_request_t))
                return;
@@ -47,6 +48,7 @@ static void handle_control_data(struct bufferevent *event, void *data) {
 
        if(EVBUFFER_LENGTH(event->input) < req.length)
                return;
+       req_data = EVBUFFER_DATA(event->input) + sizeof(tinc_ctl_request_t);
 
        if(req.length < sizeof(tinc_ctl_request_t))
                goto failure;
@@ -103,6 +105,25 @@ static void handle_control_data(struct bufferevent *event, void *data) {
                goto respond;
        }
 
+       if(req.type == REQ_SET_DEBUG) {
+               debug_t new_debug_level;
+
+               logger(LOG_NOTICE, _("Got '%s' command"), "debug");
+               if(req.length != sizeof(req) + sizeof debug_level)
+                       res.res_errno = EINVAL;
+               else {
+                       memcpy(&new_debug_level, req_data, sizeof(debug_t));
+                       logger(LOG_NOTICE, _("Changing debug level from %d to %d"),
+                                  debug_level, new_debug_level);
+                       if(evbuffer_add_printf(res_data,
+                                                                  _("Changing debug level from %d to %d\n"),
+                                                                  debug_level, new_debug_level) == -1)
+                               res.res_errno = errno;
+                       debug_level = new_debug_level;
+               }
+               goto respond;
+       }
+
        logger(LOG_DEBUG, _("Malformed control command received"));
        res.res_errno = EINVAL;
 
index bceaa7106ebfce0a7cb519755618d8e46b685c88..2b7795562299ae91da1029c14132bb0ed580da4f 100644 (file)
@@ -32,6 +32,7 @@ enum request_type {
        REQ_DUMP_CONNECTIONS,
        REQ_DUMP_GRAPH,
        REQ_PURGE,
+       REQ_SET_DEBUG,
 };
 
 #define TINC_CTL_VERSION_CURRENT 0
index 9d4a0a2bf6e7bd889fff7b8d554bc9141feb7c56..aaa035feadce092ca19b4746649e780815cd2688 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -233,25 +233,6 @@ static void sigterm_handler(int signal, short events, void *data) {
        event_loopexit(NULL);
 }
 
-static void sigint_handler(int signal, short events, void *data) {
-       static int saved_debug_level = -1;
-
-       logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
-
-       if(saved_debug_level != -1) {
-               logger(LOG_NOTICE, _("Reverting to old debug level (%d)"),
-                       saved_debug_level);
-               debug_level = saved_debug_level;
-               saved_debug_level = -1;
-       } else {
-               logger(LOG_NOTICE,
-                       _("Temporarily setting debug level to 5.  Kill me with SIGINT again to go back to level %d."),
-                       debug_level);
-               saved_debug_level = debug_level;
-               debug_level = 5;
-       }
-}
-
 static void sighup_handler(int signal, short events, void *data) {
        connection_t *c;
        splay_node_t *node, *next;
@@ -325,7 +306,6 @@ static void sigalrm_handler(int signal, short events, void *data) {
 int main_loop(void) {
        struct event timeout_event;
        struct event sighup_event;
-       struct event sigint_event;
        struct event sigterm_event;
        struct event sigquit_event;
        struct event sigalrm_event;
@@ -336,8 +316,6 @@ int main_loop(void) {
        event_add(&timeout_event, &(struct timeval){pingtimeout, 0});
        signal_set(&sighup_event, SIGHUP, sighup_handler, NULL);
        signal_add(&sighup_event, NULL);
-       signal_set(&sigint_event, SIGINT, sigint_handler, NULL);
-       signal_add(&sigint_event, NULL);
        signal_set(&sigterm_event, SIGTERM, sigterm_handler, NULL);
        signal_add(&sigterm_event, NULL);
        signal_set(&sigquit_event, SIGQUIT, sigterm_handler, NULL);
@@ -351,7 +329,6 @@ int main_loop(void) {
        }
 
        signal_del(&sighup_event);
-       signal_del(&sigint_event);
        signal_del(&sigterm_event);
        signal_del(&sigquit_event);
        signal_del(&sigalrm_event);
index 56179c6ec19d3576246463c54493b80220cd2c3f..bff122b0efc5518f0403272a9226f153b73bceb3 100644 (file)
@@ -90,6 +90,7 @@ static void usage(bool status) {
                                "    connections              - all meta connections with ourself\n"
                                "    graph                    - graph of the VPN in dotty format\n"
                                "  purge                      Purge unreachable nodes\n"
+                               "  debug N                    Set debug level\n"
                                "\n"));
                printf(_("Report bugs to tinc@tinc-vpn.org.\n"));
        }
@@ -583,6 +584,18 @@ int main(int argc, char *argv[], char *envp[]) {
                return send_ctl_request_cooked(fd, REQ_PURGE, NULL, 0) != -1;
        }
 
+       if(!strcasecmp(argv[optind], "debug")) {
+               int debuglevel;
+
+               if(argc != optind + 2) {
+                       fprintf(stderr, "Invalid arguments.\n");
+                       return 1;
+               }
+               debuglevel = atoi(argv[optind+1]);
+               return send_ctl_request_cooked(fd, REQ_SET_DEBUG, &debuglevel,
+                                                                          sizeof(debuglevel)) != -1;
+       }
+
        fprintf(stderr, _("Unknown command `%s'.\n"), argv[optind]);
        usage(true);