Commit f0347f53 authored by Joanne Hugé's avatar Joanne Hugé

Handle signals differently in order to debug the issue with empty outputs

parent a0727bde
......@@ -56,7 +56,7 @@ typedef struct network_config {
static void process_options(int argc, char *argv[]);
static void do_tsn_task(struct thread_param *param, char * data, uint64_t next_txtime);
static void print_histograms();
static void sigint_handler(int sig_num);
static void sighand(int sig_num);
// Static variables
......@@ -160,9 +160,6 @@ int main(int argc, char *argv[]) {
pthread_t thread;
thread_stat_t *stats;
// Catch breaks with sigint_handler
signal(SIGINT, sigint_handler);
param = malloc(sizeof(thread_param_t));
stats = &param->stats;
......@@ -191,6 +188,9 @@ int main(int argc, char *argv[]) {
memset((int64_t *)histograms, 0, NB_HISTOGRAMS * MAX_HIST_VAL);
}
// Catch breaks with sighand to print the histograms
init_signals(sighand, enable_histograms);
// Initialize the UDP packet sending socket
init_udp_send(enable_etf, enable_timestamps,
network_config.packet_priority,
......@@ -328,10 +328,9 @@ static void print_histograms() {
printf( "]}]}\n");
}
static void sigint_handler(int sig_num) {
static void sighand(int sig_num) {
(void)sig_num;
if (enable_histograms)
print_histograms();
print_histograms();
exit(EXIT_SUCCESS);
}
......
......@@ -60,7 +60,7 @@ typedef struct main_param {
static void process_options(int argc, char *argv[]);
static void print_histograms();
static void sigint_handler(int sig_num);
static void sighand(int sig_num);
// Static variables
......@@ -81,6 +81,7 @@ static enum TSNTask tsn_task;
struct timespec measures_start;
struct timespec measures_end;
static void help(char *argv[]) {
printf("Usage: %s [-aghtv] [-b CLIENT_IP] [-d BUF_LEN] [-f IF] [-i USEC] [-p PRIO] [-r USEC]\n\n", argv[0]);
printf(" -a Run the real time thread on CPU1\n");
......@@ -182,9 +183,6 @@ int main(int argc, char *argv[]) {
thread_stat_t *stats;
int64_t diff;
// Catch breaks with sigint_handler
signal(SIGINT, sigint_handler);
param = malloc(sizeof(thread_param_t));
stats = &param->stats;
......@@ -210,6 +208,9 @@ int main(int argc, char *argv[]) {
memset((int64_t *)histograms, 0, NB_HISTOGRAMS * MAX_HIST_VAL);
}
// Catch breaks with sighand to print the histograms
init_signals(sighand, enable_histograms);
// Initialize the UDP packet receiving socket
init_udp_recv(enable_timestamps, network_config.network_if);
......@@ -324,12 +325,10 @@ static void print_histograms() {
printf( "]]}]}\n");
}
static void sigint_handler(int sig_num) {
static void sighand(int sig_num) {
(void)sig_num;
if (enable_histograms)
print_histograms();
print_histograms();
if(param->stats.lost_packets)
fprintf(stderr, "%d packets were lost\n", param->stats.lost_packets);
......
#define _GNU_SOURCE
#include <inttypes.h>
#include <stdint.h>
#include <signal.h>
#include <time.h>
#include <unistd.h>
#include "utilities.h"
(void)(*previous_handlers[NSIG])(int);
static (void)(*sighand)(int);
uint64_t ts_to_uint(struct timespec t) {
return t.tv_sec * NSEC_PER_SEC + t.tv_nsec;
}
......@@ -28,3 +32,34 @@ uint64_t calcdiff_ns(struct timespec t1, struct timespec t2) {
uint64_t max(uint64_t a, uint64_t b) { return a > b ? a : b; }
uint64_t min(uint64_t a, uint64_t b) { return a < b ? a : b; }
static void sighand_wrapper(int sig) {
// If we get un unexpected signal, report it, if not print the histogram
if(sig == SIGINT || sig == SIGTERM)
(*sighand)(sig); // Will print the histogram
else
printf("Uknown signal interrupt: %s (%d)\n", strsignal(sig), sig);
// Execute the default handler
if(previous_handlers[sig] == SIG_DFL) {
signal(sig, SIG_DFL);
raise(sig);
}
else if(previous_handlers[sig] == SIG_IGN) {
return;
}
else {
(*previous_handlers[sig])(sig);
}
}
void init_signals((void)(*_sighand(int)), int enable_histograms) {
sighand = _sighand;
if(enable_histograms)
for(int i = 0; i < NSIG; i++)
signal(i, sighand_wrapper);
}
......@@ -4,6 +4,7 @@
#define _GNU_SOURCE
#include <inttypes.h>
#include <stdint.h>
#include <signal.h>
#include <time.h>
#include <unistd.h>
......@@ -27,4 +28,9 @@ uint64_t calcdiff_ns(struct timespec t1, struct timespec t2);
uint64_t max(uint64_t a, uint64_t b);
uint64_t min(uint64_t a, uint64_t b);
void init_signals((void)(*_sighand(int)), int enable_histograms);
extern (void)(*previous_handlers[NSIG])(int);
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment