From 90752516277dd990e75f36fe5e930a77d1401144 Mon Sep 17 00:00:00 2001 From: faluco Date: Thu, 14 Oct 2021 11:16:32 +0200 Subject: [PATCH] Move the cleanup code from the signal handlers down to the new emergency handlers for the ue, epc and enb. --- lib/include/srsran/common/signal_handler.h | 11 +------- srsenb/src/main.cc | 17 ++++++++++-- srsepc/src/main.cc | 31 +++++++++++++++------- srsue/src/main.cc | 12 +++++++++ 4 files changed, 49 insertions(+), 22 deletions(-) diff --git a/lib/include/srsran/common/signal_handler.h b/lib/include/srsran/common/signal_handler.h index 29d4307fb..36e48ebb2 100644 --- a/lib/include/srsran/common/signal_handler.h +++ b/lib/include/srsran/common/signal_handler.h @@ -31,22 +31,13 @@ extern "C" { #define SRSRAN_TERM_TIMEOUT_S (5) // static vars required by signal handling -static srslog::sink* log_sink = nullptr; -static std::atomic running = {true}; - -void srsran_dft_exit(); +static std::atomic running = {true}; static void srsran_signal_handler(int signal) { switch (signal) { case SIGALRM: fprintf(stderr, "Couldn't stop after %ds. Forcing exit.\n", SRSRAN_TERM_TIMEOUT_S); - srslog::flush(); - //: TODO: refactor the sighandler, should not depend on log utilities - if (log_sink) { - log_sink->flush(); - } - srsran_dft_exit(); execute_emergency_cleanup_handlers(); raise(SIGKILL); default: diff --git a/srsenb/src/main.cc b/srsenb/src/main.cc index f95349ebf..d2c69a83b 100644 --- a/srsenb/src/main.cc +++ b/srsenb/src/main.cc @@ -45,8 +45,9 @@ namespace bpo = boost::program_options; /********************************************************************** * Program arguments processing ***********************************************************************/ -string config_file; -static bool stdout_ts_enable = false; +string config_file; +static bool stdout_ts_enable = false; +static srslog::sink* log_sink = nullptr; void parse_args(all_args_t* args, int argc, char* argv[]) { @@ -534,9 +535,21 @@ static size_t fixup_log_file_maxsize(int x) return (x < 0) ? 0 : size_t(x) * 1024u; } +extern "C" void srsran_dft_exit(); +static void emergency_cleanup_handler(void* data) +{ + srslog::flush(); + if (log_sink) { + log_sink->flush(); + } + srsran_dft_exit(); +} + int main(int argc, char* argv[]) { srsran_register_signal_handler(); + add_emergency_cleanup_handler(emergency_cleanup_handler, nullptr); + all_args_t args = {}; srsran::metrics_hub metricshub; metrics_stdout metrics_screen; diff --git a/srsepc/src/main.cc b/srsepc/src/main.cc index e2f33abaf..62e2fce09 100644 --- a/srsepc/src/main.cc +++ b/srsepc/src/main.cc @@ -55,6 +55,8 @@ typedef struct { log_args_t log_args; } all_args_t; +static srslog::sink* log_sink = nullptr; + /********************************************************************** * Program arguments processing ***********************************************************************/ @@ -261,18 +263,18 @@ void parse_args(all_args_t* args, int argc, char* argv[]) cout << "Using default mme.integrity_algo: EIA1" << endl; } - args->mme_args.s1ap_args.mme_bind_addr = mme_bind_addr; - args->mme_args.s1ap_args.mme_name = mme_name; - args->mme_args.s1ap_args.dns_addr = dns_addr; + args->mme_args.s1ap_args.mme_bind_addr = mme_bind_addr; + args->mme_args.s1ap_args.mme_name = mme_name; + args->mme_args.s1ap_args.dns_addr = dns_addr; args->mme_args.s1ap_args.full_net_name = full_net_name; args->mme_args.s1ap_args.short_net_name = short_net_name; - args->mme_args.s1ap_args.mme_apn = mme_apn; - args->mme_args.s1ap_args.paging_timer = paging_timer; - args->spgw_args.gtpu_bind_addr = spgw_bind_addr; - args->spgw_args.sgi_if_addr = sgi_if_addr; - args->spgw_args.sgi_if_name = sgi_if_name; - args->spgw_args.max_paging_queue = max_paging_queue; - args->hss_args.db_file = hss_db_file; + args->mme_args.s1ap_args.mme_apn = mme_apn; + args->mme_args.s1ap_args.paging_timer = paging_timer; + args->spgw_args.gtpu_bind_addr = spgw_bind_addr; + args->spgw_args.sgi_if_addr = sgi_if_addr; + args->spgw_args.sgi_if_name = sgi_if_name; + args->spgw_args.max_paging_queue = max_paging_queue; + args->hss_args.db_file = hss_db_file; // Apply all_level to any unset layers if (vm.count("log.all_level")) { @@ -353,9 +355,18 @@ std::string get_build_string() return ss.str(); } +static void emergency_cleanup_handler(void* data) +{ + srslog::flush(); + if (log_sink) { + log_sink->flush(); + } +} + int main(int argc, char* argv[]) { srsran_register_signal_handler(); + add_emergency_cleanup_handler(emergency_cleanup_handler, nullptr); // print build info cout << endl << get_build_string() << endl; diff --git a/srsue/src/main.cc b/srsue/src/main.cc index 05e43934b..7a9de3f76 100644 --- a/srsue/src/main.cc +++ b/srsue/src/main.cc @@ -47,6 +47,7 @@ namespace bpo = boost::program_options; static bool do_metrics = false; static metrics_stdout* metrics_screen = nullptr; +static srslog::sink* log_sink = nullptr; /********************************************************************** * Program arguments processing @@ -656,9 +657,20 @@ static size_t fixup_log_file_maxsize(int x) return (x < 0) ? 0 : size_t(x) * 1024u; } +extern "C" void srsran_dft_exit(); +static void emergency_cleanup_handler(void* data) +{ + srslog::flush(); + if (log_sink) { + log_sink->flush(); + } + srsran_dft_exit(); +} + int main(int argc, char* argv[]) { srsran_register_signal_handler(); + add_emergency_cleanup_handler(emergency_cleanup_handler, nullptr); srsran_debug_handle_crash(argc, argv); all_args_t args = {};