From: Scott Lamb Date: Wed, 7 Nov 2007 02:50:27 +0000 (+0000) Subject: Alter debugging levels through control socket X-Git-Tag: release-1.1pre1~137 X-Git-Url: http://tinc-vpn.org/git/browse?a=commitdiff_plain;h=a62a6825a8a69e279ee0688a4cd9e51fbc52054b;p=tinc Alter debugging levels through control socket --- diff --git a/doc/tinc.texi b/doc/tinc.texi index e9534728..b3f570c6 100644 --- a/doc/tinc.texi +++ b/doc/tinc.texi @@ -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 diff --git a/doc/tincctl.8.in b/doc/tincctl.8.in index 40bd1361..623c908b 100644 --- a/doc/tincctl.8.in +++ b/doc/tincctl.8.in @@ -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. diff --git a/doc/tincd.8.in b/doc/tincd.8.in index 96c773f1..b3142e82 100644 --- a/doc/tincd.8.in +++ b/doc/tincd.8.in @@ -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. diff --git a/src/control.c b/src/control.c index 2c5d4be8..3e57f551 100644 --- a/src/control.c +++ b/src/control.c @@ -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; diff --git a/src/control_common.h b/src/control_common.h index bceaa710..2b779556 100644 --- a/src/control_common.h +++ b/src/control_common.h @@ -32,6 +32,7 @@ enum request_type { REQ_DUMP_CONNECTIONS, REQ_DUMP_GRAPH, REQ_PURGE, + REQ_SET_DEBUG, }; #define TINC_CTL_VERSION_CURRENT 0 diff --git a/src/net.c b/src/net.c index 9d4a0a2b..aaa035fe 100644 --- 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); diff --git a/src/tincctl.c b/src/tincctl.c index 56179c6e..bff122b0 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -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);