From f9224e1fc8998000ae483a6948ee692c608afa65 Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Mon, 14 Apr 2025 17:54:42 +0200 Subject: [PATCH] File-based stats: abort writing if we can't write There might be a number of reasons, such as read-only write system, erros, etc. Still gracefully continue instead of aborting the operation. --- executables/nr-gnb.c | 8 +++++--- openair2/LAYER2/NR_MAC_gNB/main.c | 5 ++++- openair2/RRC/NR/rrc_gNB.c | 15 +++++++++------ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/executables/nr-gnb.c b/executables/nr-gnb.c index 74a95c2794..9f20e6f409 100644 --- a/executables/nr-gnb.c +++ b/executables/nr-gnb.c @@ -267,9 +267,11 @@ void *nrL1_stats_thread(void *param) { char output[L1STATSSTRLEN]; memset(output,0,L1STATSSTRLEN); wait_sync("L1_stats_thread"); - FILE *fd; - fd=fopen("nrL1_stats.log","w"); - AssertFatal(fd!=NULL,"Cannot open nrL1_stats.log\n"); + FILE *fd=fopen("nrL1_stats.log","w"); + if (!fd) { + LOG_W(NR_PHY, "Cannot open nrL1_stats.log: %d, %s\n", errno, strerror(errno)); + return NULL; + } reset_meas(&gNB->phy_proc_tx); reset_meas(&gNB->dlsch_encoding_stats); diff --git a/openair2/LAYER2/NR_MAC_gNB/main.c b/openair2/LAYER2/NR_MAC_gNB/main.c index 099cb725e1..0e0442d77a 100644 --- a/openair2/LAYER2/NR_MAC_gNB/main.c +++ b/openair2/LAYER2/NR_MAC_gNB/main.c @@ -79,7 +79,10 @@ void *nrmac_stats_thread(void *arg) { char output[MACSTATSSTRLEN] = {0}; const char *end = output + MACSTATSSTRLEN; FILE *file = fopen("nrMAC_stats.log","w"); - AssertFatal(file!=NULL,"Cannot open nrMAC_stats.log, error %s\n",strerror(errno)); + if (!file) { + LOG_W(NR_MAC, "Cannot open nrMAC_stats.log: %d, %s\n", errno, strerror(errno)); + return NULL; + } while (oai_exit == 0) { char *p = output; diff --git a/openair2/RRC/NR/rrc_gNB.c b/openair2/RRC/NR/rrc_gNB.c index f3686cfc1e..824cd701fb 100644 --- a/openair2/RRC/NR/rrc_gNB.c +++ b/openair2/RRC/NR/rrc_gNB.c @@ -2481,13 +2481,13 @@ static const char *get_pdusession_status_text(pdu_session_status_t status) return "illegal"; } -static void write_rrc_stats(const gNB_RRC_INST *rrc) +static bool write_rrc_stats(const gNB_RRC_INST *rrc) { const char *filename = "nrRRC_stats.log"; FILE *f = fopen(filename, "w"); if (f == NULL) { - LOG_E(NR_RRC, "cannot open %s for writing\n", filename); - return; + LOG_W(NR_RRC, "cannot open %s for writing: %d, %s\n", filename, errno, strerror(errno)); + return false; } time_t now = time(NULL); @@ -2538,6 +2538,7 @@ static void write_rrc_stats(const gNB_RRC_INST *rrc) dump_du_info(rrc, f); fclose(f); + return true; } void *rrc_gnb_task(void *args_p) { @@ -2576,10 +2577,12 @@ void *rrc_gnb_task(void *args_p) { break; case TIMER_HAS_EXPIRED: - if (TIMER_HAS_EXPIRED(msg_p).timer_id == stats_timer_id) - write_rrc_stats(RC.nrrrc[0]); - else + if (TIMER_HAS_EXPIRED(msg_p).timer_id == stats_timer_id) { + if (!write_rrc_stats(RC.nrrrc[0])) + timer_remove(stats_timer_id); + } else { itti_send_msg_to_task(TASK_RRC_GNB, 0, TIMER_HAS_EXPIRED(msg_p).arg); /* see rrc_gNB_process_NGAP_PDUSESSION_SETUP_REQ() */ + } break; case F1AP_INITIAL_UL_RRC_MESSAGE: