2024-08-23 11:53:40 +02:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*
|
|
|
|
* Copyright (C) 2024 Thomas Kolb
|
|
|
|
* Copyright (C) 2024 Simon Ruderich
|
|
|
|
*/
|
|
|
|
|
2024-05-05 18:40:50 +02:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2024-05-30 11:00:34 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2024-05-05 18:40:50 +02:00
|
|
|
|
2024-05-30 10:44:42 +02:00
|
|
|
#include "logger.h"
|
|
|
|
|
2024-05-05 18:40:50 +02:00
|
|
|
#include "../src/jsonlogger.h"
|
|
|
|
#include "../src/debug_structs.h"
|
|
|
|
|
|
|
|
static rx_stats_t m_rx_stats;
|
|
|
|
|
|
|
|
static bool m_running;
|
|
|
|
|
|
|
|
static void signal_handler(int signal, siginfo_t *info, void *ctx)
|
|
|
|
{
|
|
|
|
(void)signal;
|
|
|
|
(void)info;
|
|
|
|
(void)ctx;
|
|
|
|
|
2024-05-30 10:44:42 +02:00
|
|
|
LOG(LVL_INFO, "Gracefully shutting down on signal %d.", signal);
|
2024-05-05 18:40:50 +02:00
|
|
|
|
|
|
|
m_running = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-05-30 10:44:42 +02:00
|
|
|
int main(void)
|
2024-05-05 18:40:50 +02:00
|
|
|
{
|
2024-05-30 10:44:42 +02:00
|
|
|
logger_init();
|
|
|
|
|
2024-05-05 18:40:50 +02:00
|
|
|
if(!jsonlogger_init("jsonlog_test.fifo")) {
|
2024-05-30 10:44:42 +02:00
|
|
|
LOG(LVL_ERR, "Could not initialize JSON logger.");
|
2024-05-05 18:40:50 +02:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ** Set up signal handling
|
|
|
|
|
|
|
|
struct sigaction term_action = {0};
|
|
|
|
term_action.sa_sigaction = signal_handler;
|
|
|
|
|
|
|
|
if(sigaction(SIGTERM, &term_action, NULL) < 0) {
|
2024-05-30 11:00:34 +02:00
|
|
|
LOG(LVL_ERR, "sigaction: %s", strerror(errno));
|
2024-05-05 18:40:50 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(sigaction(SIGINT, &term_action, NULL) < 0) {
|
2024-05-30 11:00:34 +02:00
|
|
|
LOG(LVL_ERR, "sigaction: %s", strerror(errno));
|
2024-05-05 18:40:50 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore SIGPIPE
|
2024-05-09 14:37:39 +02:00
|
|
|
struct sigaction term_action_ign = {
|
|
|
|
.sa_handler = SIG_IGN,
|
|
|
|
};
|
|
|
|
if(sigaction(SIGPIPE, &term_action_ign, NULL) < 0) {
|
2024-05-30 11:00:34 +02:00
|
|
|
LOG(LVL_ERR, "sigaction: %s", strerror(errno));
|
2024-05-05 18:40:50 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_running = true;
|
|
|
|
while(m_running) {
|
|
|
|
m_rx_stats.preambles_found++;
|
|
|
|
m_rx_stats.successful_decodes += 2;
|
|
|
|
m_rx_stats.failed_decodes += 3;
|
|
|
|
m_rx_stats.header_errors += 4;
|
|
|
|
|
|
|
|
jsonlogger_log_rx_stats(&m_rx_stats);
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ** Cleanup **
|
|
|
|
|
|
|
|
jsonlogger_shutdown();
|
|
|
|
|
2024-05-30 10:44:42 +02:00
|
|
|
LOG(LVL_INFO, "Done.");
|
2024-05-05 18:40:50 +02:00
|
|
|
}
|