+ connection_t *c = data;
+ int result;
+ socklen_t len = sizeof(result);
+
+ if (c->status.remove)
+ return;
+
+ if(c->status.connecting) {
+ getsockopt(c->socket, SOL_SOCKET, SO_ERROR, &result, &len);
+
+ if(!result)
+ finish_connecting(c);
+ else {
+ ifdebug(CONNECTIONS) logger(LOG_DEBUG,
+ _("Error while connecting to %s (%s): %s"),
+ c->name, c->hostname, strerror(result));
+ c->status.connecting = false;
+ closesocket(c->socket);
+ do_outgoing_connection(c);
+ return;
+ }
+ }
+
+ if (!receive_meta(c)) {
+ terminate_connection(c, c->status.active);
+ return;
+ }
+}
+
+static void dummy(int a, short b, void *c)
+{
+}
+
+static void sigterm_handler(int signal, short events, void *data) {
+ logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
+ running = false;
+ 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 sigusr1_handler(int signal, short events, void *data) {
+ logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
+ dump_connections();
+}
+
+static void sigusr2_handler(int signal, short events, void *data) {
+ logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
+ dump_device_stats();
+ dump_nodes();
+ dump_edges();
+ dump_subnets();
+}
+
+static void sigwinch_handler(int signal, short events, void *data) {
+ logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal));
+ purge();
+}
+
+static void sighup_handler(int signal, short events, void *data) {