From 7e74d4c43ef89cd33b335e2f597fa9fe482c7661 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Thu, 12 Feb 2026 12:10:46 +0100 Subject: [PATCH 1/4] T: macpdu2wireshark: gentle exit When outputting to a file, typing ctrl+c exits the program without calling fclose(), leading to loss of traces in the output file. Let's intercept ctrl+c and exit gently, calling fclose(). --- common/utils/T/tracer/macpdu2wireshark.c | 29 ++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/common/utils/T/tracer/macpdu2wireshark.c b/common/utils/T/tracer/macpdu2wireshark.c index 831488d485..407e565bf3 100644 --- a/common/utils/T/tracer/macpdu2wireshark.c +++ b/common/utils/T/tracer/macpdu2wireshark.c @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include #include #include @@ -387,6 +389,7 @@ void sr(void *_d, event e) #define MAC_NR_HARQID 0x06 #define MAC_NR_FRAME_SLOT_TAG 0x07 +#define NR_FDD_RADIO 1 #define NR_TDD_RADIO 2 #define NR_DIRECTION_UPLINK 0 @@ -948,6 +951,18 @@ void usage(void) exit(1); } +volatile int run = 1; + +static int sock = -1; + +void force_stop(int x) +{ + printf("\ngently quit...\n"); + close(sock); + sock = -1; + run = 0; +} + int main(int n, char **v) { char *database_filename = NULL; @@ -968,6 +983,9 @@ int main(int n, char **v) int live = 0; memset(&d, 0, sizeof(ev_data)); + /* write on a socket fails if the other end is closed and we get SIGPIPE */ + if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) abort(); + for (i = 0; i < 65536; i++) { d.lte_rnti_to_ueid[i] = -1; d.nr_rnti_to_ueid[i] = -1; @@ -1014,8 +1032,10 @@ int main(int n, char **v) perror(input_filename); return 1; } - } else + } else { in = connect_to(live_ip, live_port); + sock = in; + } database = parse_database(database_filename); load_config_file(database_filename); @@ -1121,10 +1141,15 @@ int main(int n, char **v) new_thread(receiver, &d); } + /* exit on ctrl+c and ctrl+z */ + if (signal(SIGQUIT, force_stop) == SIG_ERR) abort(); + if (signal(SIGINT, force_stop) == SIG_ERR) abort(); + if (signal(SIGTSTP, force_stop) == SIG_ERR) abort(); + OBUF ebuf = {.osize = 0, .omaxsize = 0, .obuf = NULL}; /* read messages */ - while (1) { + while (run) { event e; e = get_event(in, &ebuf, database); From 0c4655448f7f790bf4f80f627a7d63d3d34f188c Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Thu, 12 Feb 2026 12:14:39 +0100 Subject: [PATCH 2/4] T: minor: fix compilation of _check_vcd "make _check_vcd" was failing. --- common/utils/T/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/utils/T/Makefile b/common/utils/T/Makefile index e1b3d8c0c2..82797a93cc 100644 --- a/common/utils/T/Makefile +++ b/common/utils/T/Makefile @@ -21,7 +21,7 @@ incgen/T_IDs.h: $(GENIDS) T_messages.txt ./$(GENIDS) T_messages.txt incgen/T_IDs.h check_vcd: incgen/T_IDs.h incgen/T_messages.txt.h - gcc -Wall -I. -I.. -I../itti -I../../../openair2/COMMON -Itracer -o _check_vcd check_vcd.c tracer/database.c tracer/utils.c -lm -pthread + gcc -Wall -I. -I.. -I../../.. -I../itti -I../../../openair2/COMMON -Itracer -Iincgen -o _check_vcd check_vcd.c tracer/database.c tracer/utils.c -lm -pthread ./_check_vcd T_messages.txt ../LOG/vcd_signal_dumper.h || (rm -rf ./_check_vcd ./incgen && false) rm -f ./_check_vcd From 61bdee3e615eb69c9977cc47172ef435175e2bc0 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Sat, 14 Feb 2026 15:30:46 +0100 Subject: [PATCH 3/4] T: extract: extract all traces by default --- common/utils/T/tracer/extract.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/common/utils/T/tracer/extract.c b/common/utils/T/tracer/extract.c index 445b166f09..a5490cdb16 100644 --- a/common/utils/T/tracer/extract.c +++ b/common/utils/T/tracer/extract.c @@ -18,6 +18,7 @@ void usage(void) " (you can use several -f options)\n" " -after 'event' time has to be greater than this\n" " -count dump 'n' matching events (less if EOF reached)\n" +" (default: no limit)\n" ); exit(1); } @@ -53,7 +54,7 @@ int main(int n, char **v) int filter_count = 0; int buffer_arg; int found; - int count = 1; + int count = -1; int check_time = 0; time_t sec = 0; /* initialization not necessary but gcc is not happy */ long nsec = 0; /* initialization not necessary but gcc is not happy */ @@ -132,12 +133,12 @@ int main(int n, char **v) if (fwrite(e.e[buffer_arg].b, e.e[buffer_arg].bsize, 1, out) != 1) { perror(output_file); exit(1); } found++; - if (found == count) + if (count != -1 && found == count) break; } if (found == 0) printf("ERROR: event not found\n"); - if (found != count) + if (count != -1 && found != count) printf("WARNING: dumped %d events (wanted %d)\n", found, count); fclose(out); From c1f41caa8dcfe6fe2d681082302160760d2e598b Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Sat, 14 Feb 2026 15:31:38 +0100 Subject: [PATCH 4/4] T: hacks: plot-ofdm: handle more skipped samples --- common/utils/T/tracer/hacks/plot-ofdm.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/common/utils/T/tracer/hacks/plot-ofdm.c b/common/utils/T/tracer/hacks/plot-ofdm.c index 3f6e0b9dce..cd73891172 100644 --- a/common/utils/T/tracer/hacks/plot-ofdm.c +++ b/common/utils/T/tracer/hacks/plot-ofdm.c @@ -135,7 +135,7 @@ int main(int n, char **v) int input_is_float = 0; int no_fft = 0; int delay = 0; - int skip = 0; + uint64_t skip = 0; int symbols_per_subframe; long sampling_rate = 61440000; int mu = 1; @@ -152,7 +152,7 @@ int main(int n, char **v) if (!strcmp(v[i], "-srate")) { if (i>n-2) usage(); sampling_rate = atol(v[++i]); continue; } if (!strcmp(v[i], "-prb")) { if (i>n-2) usage(); prb = atoi(v[++i]); continue; } if (!strcmp(v[i], "-mu")) { if (i>n-2) usage(); mu = atoi(v[++i]); continue; } - if (!strcmp(v[i], "-skip")) { if (i>n-2) usage(); skip = atoi(v[++i]); continue; } + if (!strcmp(v[i], "-skip")) { if (i>n-2) usage(); skip = atoll(v[++i]); continue; } usage(); } @@ -222,14 +222,14 @@ int main(int n, char **v) int back_color = 0; int hpixel = 0; - if (skip) { - if (input_is_float) { - float intime[skip * 2]; - if (fread(intime, skip * 8, 1, stdin) != 1) abort(); - } else { - short intime[skip * 2]; - if (fread(intime, skip * 4, 1, stdin) != 1) abort(); - } + /* skip data */ + int sample_size = input_is_float ? 8 : 4; + uint64_t to_skip = skip; + while (to_skip) { + char intime[4096 * sample_size]; + int count = to_skip > 4096 ? 4096 : to_skip; + if (fread(intime, count * sample_size, 1, stdin) != 1) abort(); + to_skip -= count; } while (1) {