79 lines
1.5 KiB
C
79 lines
1.5 KiB
C
#include <signal.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
|
|
#include "logger.h"
|
|
|
|
#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;
|
|
|
|
LOG(LVL_INFO, "Gracefully shutting down on signal %d.", signal);
|
|
|
|
m_running = false;
|
|
}
|
|
|
|
|
|
int main(void)
|
|
{
|
|
logger_init();
|
|
|
|
if(!jsonlogger_init("jsonlog_test.fifo")) {
|
|
LOG(LVL_ERR, "Could not initialize JSON logger.");
|
|
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) {
|
|
LOG(LVL_ERR, "sigaction: %s", strerror(errno));
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
if(sigaction(SIGINT, &term_action, NULL) < 0) {
|
|
LOG(LVL_ERR, "sigaction: %s", strerror(errno));
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
// ignore SIGPIPE
|
|
struct sigaction term_action_ign = {
|
|
.sa_handler = SIG_IGN,
|
|
};
|
|
if(sigaction(SIGPIPE, &term_action_ign, NULL) < 0) {
|
|
LOG(LVL_ERR, "sigaction: %s", strerror(errno));
|
|
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();
|
|
|
|
LOG(LVL_INFO, "Done.");
|
|
}
|