From 07f06f8c06f2f33ed0e5a49a6e610363ebd92c4d Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Fri, 24 Oct 2025 10:25:47 +0200 Subject: [PATCH] nrMAC_stats.log: handle file errors, add truncate to reset file truncate resets the file size to 0. Without this, e.g., when disconnecting a UE, the old UE remains at the end and is not overwritten, which is confusing. --- openair2/LAYER2/NR_MAC_gNB/main.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/openair2/LAYER2/NR_MAC_gNB/main.c b/openair2/LAYER2/NR_MAC_gNB/main.c index 2df930f3ff..4b8196fc1b 100644 --- a/openair2/LAYER2/NR_MAC_gNB/main.c +++ b/openair2/LAYER2/NR_MAC_gNB/main.c @@ -97,10 +97,16 @@ void *nrmac_stats_thread(void *arg) { p += print_meas_log(&gNB->nr_srs_ri_computation_timer, "UL-RI computation time", NULL, NULL, p, end - p); p += print_meas_log(&gNB->nr_srs_tpmi_computation_timer, "UL-TPMI computation time", NULL, NULL, p, end - p); NR_SCHED_UNLOCK(&gNB->sched_lock); - fwrite(output, p - output, 1, file); - fflush(file); + size_t len = p - output; + if (fwrite(output, len, 1, file) != 1 || fflush(file) != 0) { + LOG_E(NR_MAC, "error while writing nrMAC_stats.log: %d, %s\n", errno, strerror(errno)); + break; + } sleep(1); - fseek(file,0,SEEK_SET); + if (ftruncate(fileno(file), 0) != 0 || fseek(file, 0, SEEK_SET) != 0) { + LOG_E(NR_MAC, "error while writing nrMAC_stats.log: %d, %s\n", errno, strerror(errno)); + break; + } } fclose(file); return NULL;