Allows clean termination when killed via SIGTERM.
It's a temporal hack; not safe because of the multithreading.
It's meant to be enabled during the controlled environment of Rapport
tests, and nowhere else.
Compile with -DOVERRIDE_SIGTERM to enable.
*/
}
+volatile bool fort_end = false;
+
+#ifdef OVERRIDE_SIGTERM
+
+static void
+sigterm_handler(int signum)
+{
+ fort_end = true;
+}
+
+#endif
+
/*
* Register better handlers for some signals.
*
}
#endif
+#ifdef OVERRIDE_SIGTERM
+ /* SIGTERM handler */
+ memset(&action, 0, sizeof(action));
+ action.sa_handler = sigterm_handler;
+ sigemptyset(&action.sa_mask);
+ if (sigaction(SIGTERM, &action, NULL) == -1)
+ pr_op_err("SIGTERM handler registration failure: %s",
+ strerror(errno));
+#endif
+
/* SIGUSR1 handler */
memset(&action, 0, sizeof(action));
action.sa_handler = sigusr1_handler;
#define CHECK_FORMAT(str, args) /* Nothing */
#endif
+extern volatile bool fort_end;
+
/*
* Only call this group of functions when you know there's only one thread.
*
return error;
error = vrps_update(NULL);
+ if (fort_end)
+ goto end;
if (error) {
pr_op_err("Main loop: Validation unsuccessful; results unusable.");
- return error;
+ goto end;
}
rtr_notify();
do {
pr_op_info("Main loop: Sleeping.");
sleep(config_get_validation_interval());
+ if (fort_end)
+ goto end;
pr_op_info("Main loop: Time to work!");
error = vrps_update(&changed);
- if (error == -EINTR)
+ if (fort_end || error == -EINTR)
break;
if (error) {
pr_op_debug("Main loop: Error %d (%s)", error,
rtr_notify();
} while (true);
- rtr_stop();
+end: rtr_stop();
return error;
}
};
static pthread_t server_thread;
-static volatile bool stop_server_thread;
STATIC_ARRAY_LIST(server_arraylist, struct rtr_server)
STATIC_ARRAY_LIST(client_arraylist, struct pdu_stream *)
error = poll(pollfds, servers.len + clients.len, 1000);
- if (stop_server_thread)
+ if (fort_end)
goto stop;
if (error == 0)
{
int error;
- stop_server_thread = true;
+ fort_end = true;
error = pthread_join(server_thread, NULL);
if (error) {
pr_op_err("pthread_join() returned error %d: %s", error,