hamnet70/impl/test/test_jsonlogger.c
Simon Ruderich f689c4ec15 Fix compiler warnings
- implicit declaration of built-in function 'strncpy'
- control reaches end of non-void function
- assignment to 'void (*)(int,  siginfo_t *, void *)' from incompatible pointer type 'void (*)(int)'
2024-05-09 14:37:39 +02:00

74 lines
1.3 KiB
C

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.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;
fprintf(stderr, "\nGracefully shutting down on signal %d.\n", signal);
m_running = false;
}
int main()
{
if(!jsonlogger_init("jsonlog_test.fifo")) {
fprintf(stderr, "Could not initialize JSON logger.\n");
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) {
perror("sigaction");
exit(EXIT_FAILURE);
}
if(sigaction(SIGINT, &term_action, NULL) < 0) {
perror("sigaction");
exit(EXIT_FAILURE);
}
// ignore SIGPIPE
struct sigaction term_action_ign = {
.sa_handler = SIG_IGN,
};
if(sigaction(SIGPIPE, &term_action_ign, NULL) < 0) {
perror("sigaction");
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();
fprintf(stderr, "Done.\n");
}