Delete move constructor and move assignment operator explictly for mac_pcap_base and s1ap_pcap classes.

Move emergency handlers header file into the support folder.

Refactored signal handling:
- Remove the dependency with the running static variable in the header file.
- Move implementations down to cc files.
- Allow specifying a new signal handler that will be used to stop the applications.
- Move signal handling files to support.
master
faluco 3 years ago committed by Andre Puschmann
parent 9075251627
commit dacf40f63e

@ -31,6 +31,8 @@ public:
mac_pcap_base(const mac_pcap_base& other) = delete; mac_pcap_base(const mac_pcap_base& other) = delete;
mac_pcap_base& operator=(const mac_pcap_base& other) = delete; mac_pcap_base& operator=(const mac_pcap_base& other) = delete;
mac_pcap_base(mac_pcap_base&& other) = delete;
mac_pcap_base& operator=(mac_pcap_base&& other) = delete;
~mac_pcap_base(); ~mac_pcap_base();
void enable(bool enable); void enable(bool enable);

@ -24,6 +24,8 @@ public:
s1ap_pcap(); s1ap_pcap();
s1ap_pcap(const s1ap_pcap& other) = delete; s1ap_pcap(const s1ap_pcap& other) = delete;
s1ap_pcap& operator=(const s1ap_pcap& other) = delete; s1ap_pcap& operator=(const s1ap_pcap& other) = delete;
s1ap_pcap(s1ap_pcap&& other) = delete;
s1ap_pcap& operator=(s1ap_pcap&& other) = delete;
void enable(); void enable();
void open(const char* filename_); void open(const char* filename_);

@ -0,0 +1,27 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2021 Software Radio Systems Limited
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the distribution.
*
*/
/**
* @file signal_handler.h
* @brief Common signal handling methods for all srsRAN applications.
*/
#ifndef SRSRAN_SIGNAL_HANDLER_H
#define SRSRAN_SIGNAL_HANDLER_H
using srsran_signal_hanlder = void (*)();
/// Registers the specified function to be called when the user interrupts the program execution (eg: via Ctrl+C).
/// Passing a null function pointer disables the current installed handler.
void srsran_register_signal_handler(srsran_signal_hanlder handler);
#endif // SRSRAN_SIGNAL_HANDLER_H

@ -15,4 +15,5 @@ add_subdirectory(rlc)
add_subdirectory(pdcp) add_subdirectory(pdcp)
add_subdirectory(gtpu) add_subdirectory(gtpu)
add_subdirectory(srslog) add_subdirectory(srslog)
add_subdirectory(support)
add_subdirectory(system) add_subdirectory(system)

@ -28,7 +28,6 @@ set(SOURCES arch_select.cc
rlc_pcap.cc rlc_pcap.cc
s1ap_pcap.cc s1ap_pcap.cc
security.cc security.cc
emergency_handlers.cc
standard_streams.cc standard_streams.cc
thread_pool.cc thread_pool.cc
threads.c threads.c
@ -48,7 +47,7 @@ add_dependencies(srsran_common gen_build_info)
add_executable(arch_select arch_select.cc) add_executable(arch_select arch_select.cc)
target_include_directories(srsran_common PUBLIC ${SEC_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR} ${BACKWARD_INCLUDE_DIRS}) target_include_directories(srsran_common PUBLIC ${SEC_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR} ${BACKWARD_INCLUDE_DIRS})
target_link_libraries(srsran_common srsran_phy srslog ${SEC_LIBRARIES} ${BACKWARD_LIBRARIES} ${SCTP_LIBRARIES}) target_link_libraries(srsran_common srsran_phy support srslog ${SEC_LIBRARIES} ${BACKWARD_LIBRARIES} ${SCTP_LIBRARIES})
target_compile_definitions(srsran_common PRIVATE ${BACKWARD_DEFINITIONS}) target_compile_definitions(srsran_common PRIVATE ${BACKWARD_DEFINITIONS})
INSTALL(TARGETS srsran_common DESTINATION ${LIBRARY_DIR}) INSTALL(TARGETS srsran_common DESTINATION ${LIBRARY_DIR})

@ -11,9 +11,9 @@
*/ */
#include "srsran/common/mac_pcap_base.h" #include "srsran/common/mac_pcap_base.h"
#include "srsran/common/emergency_handlers.h"
#include "srsran/config.h" #include "srsran/config.h"
#include "srsran/phy/common/phy_common.h" #include "srsran/phy/common/phy_common.h"
#include "srsran/support/emergency_handlers.h"
#include <stdint.h> #include <stdint.h>
namespace srsran { namespace srsran {

@ -11,9 +11,9 @@
*/ */
#include "srsran/common/s1ap_pcap.h" #include "srsran/common/s1ap_pcap.h"
#include "srsran/common/emergency_handlers.h"
#include "srsran/common/pcap.h" #include "srsran/common/pcap.h"
#include "srsran/srsran.h" #include "srsran/srsran.h"
#include "srsran/support/emergency_handlers.h"
#include <stdint.h> #include <stdint.h>
namespace srsran { namespace srsran {

@ -0,0 +1,12 @@
#
# Copyright 2013-2021 Software Radio Systems Limited
#
# By using this file, you agree to the terms and conditions set
# forth in the LICENSE file which can be found at the top level of
# the distribution.
#
set(SOURCES emergency_handlers.cc
signal_handler.cc)
add_library(support STATIC ${SOURCES})

@ -10,7 +10,7 @@
* *
*/ */
#include "srsran/common/emergency_handlers.h" #include "srsran/support/emergency_handlers.h"
#include "srsran/support/srsran_assert.h" #include "srsran/support/srsran_assert.h"
namespace { namespace {

@ -10,28 +10,17 @@
* *
*/ */
/** #include "srsran/support/signal_handler.h"
* @file signal_handler.h #include "srsran/support/emergency_handlers.h"
* @brief Common signal handling methods for all srsRAN applications. #include <atomic>
*/ #include <csignal>
#include <cstdio>
#ifndef SRSRAN_SIGNAL_HANDLER_H #include <unistd.h>
#define SRSRAN_SIGNAL_HANDLER_H
#include "srsran/common/emergency_handlers.h"
#include "srsran/srslog/sink.h"
#include "srsran/srslog/srslog.h"
#include <signal.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
#define SRSRAN_TERM_TIMEOUT_S (5) #define SRSRAN_TERM_TIMEOUT_S (5)
// static vars required by signal handling /// Handler called after the user interrupts the program.
static std::atomic<bool> running = {true}; static std::atomic<srsran_signal_hanlder> user_handler;
static void srsran_signal_handler(int signal) static void srsran_signal_handler(int signal)
{ {
@ -42,26 +31,24 @@ static void srsran_signal_handler(int signal)
raise(SIGKILL); raise(SIGKILL);
default: default:
// all other registered signals try to stop the app gracefully // all other registered signals try to stop the app gracefully
if (running) { // Call the user handler if present and remove it so that further signals are treated by the default handler.
running = false; if (auto handler = user_handler.exchange(nullptr)) {
fprintf(stdout, "Stopping ..\n"); handler();
alarm(SRSRAN_TERM_TIMEOUT_S);
} else { } else {
// already waiting for alarm to go off .. return;
} }
fprintf(stdout, "Stopping ..\n");
alarm(SRSRAN_TERM_TIMEOUT_S);
break; break;
} }
} }
void srsran_register_signal_handler() void srsran_register_signal_handler(srsran_signal_hanlder handler)
{ {
user_handler.store(handler);
signal(SIGINT, srsran_signal_handler); signal(SIGINT, srsran_signal_handler);
signal(SIGTERM, srsran_signal_handler); signal(SIGTERM, srsran_signal_handler);
signal(SIGHUP, srsran_signal_handler); signal(SIGHUP, srsran_signal_handler);
signal(SIGALRM, srsran_signal_handler); signal(SIGALRM, srsran_signal_handler);
} }
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // SRSRAN_SIGNAL_HANDLER_H

@ -27,7 +27,7 @@ target_link_libraries(enb_cfg_parser srsran_common ${LIBCONFIGPP_LIBRARIES})
add_executable(srsenb main.cc enb.cc metrics_stdout.cc metrics_csv.cc metrics_json.cc) add_executable(srsenb main.cc enb.cc metrics_stdout.cc metrics_csv.cc metrics_json.cc)
set(SRSENB_SOURCES srsenb_phy srsenb_stack srsenb_common srsenb_s1ap srsenb_upper srsenb_mac srsenb_rrc srslog system) set(SRSENB_SOURCES srsenb_phy srsenb_stack srsenb_common srsenb_s1ap srsenb_upper srsenb_mac srsenb_rrc srslog system)
set(SRSRAN_SOURCES srsran_common srsran_mac srsran_phy srsran_gtpu srsran_rlc srsran_pdcp srsran_radio rrc_asn1 s1ap_asn1 enb_cfg_parser srslog system) set(SRSRAN_SOURCES srsran_common srsran_mac srsran_phy srsran_gtpu srsran_rlc srsran_pdcp srsran_radio rrc_asn1 s1ap_asn1 enb_cfg_parser srslog support system)
set(SRSENB_SOURCES ${SRSENB_SOURCES} srsgnb_stack srsgnb_ngap srsgnb_upper srsgnb_mac srsgnb_rrc) set(SRSENB_SOURCES ${SRSENB_SOURCES} srsgnb_stack srsgnb_ngap srsgnb_upper srsgnb_mac srsgnb_rrc)
set(SRSRAN_SOURCES ${SRSRAN_SOURCES} rrc_nr_asn1 ngap_nr_asn1) set(SRSRAN_SOURCES ${SRSRAN_SOURCES} rrc_nr_asn1 ngap_nr_asn1)

@ -20,10 +20,11 @@
#include "srsran/common/common_helper.h" #include "srsran/common/common_helper.h"
#include "srsran/common/config_file.h" #include "srsran/common/config_file.h"
#include "srsran/common/crash_handler.h" #include "srsran/common/crash_handler.h"
#include "srsran/common/signal_handler.h"
#include "srsran/common/tsan_options.h" #include "srsran/common/tsan_options.h"
#include "srsran/srslog/event_trace.h" #include "srsran/srslog/event_trace.h"
#include "srsran/srslog/srslog.h" #include "srsran/srslog/srslog.h"
#include "srsran/support/emergency_handlers.h"
#include "srsran/support/signal_handler.h"
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <boost/program_options/parsers.hpp> #include <boost/program_options/parsers.hpp>
@ -45,9 +46,10 @@ namespace bpo = boost::program_options;
/********************************************************************** /**********************************************************************
* Program arguments processing * Program arguments processing
***********************************************************************/ ***********************************************************************/
string config_file; string config_file;
static bool stdout_ts_enable = false; static bool stdout_ts_enable = false;
static srslog::sink* log_sink = nullptr; static srslog::sink* log_sink = nullptr;
static std::atomic<bool> running = {true};
void parse_args(all_args_t* args, int argc, char* argv[]) void parse_args(all_args_t* args, int argc, char* argv[])
{ {
@ -545,9 +547,14 @@ static void emergency_cleanup_handler(void* data)
srsran_dft_exit(); srsran_dft_exit();
} }
static void signal_handler()
{
running = false;
}
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
srsran_register_signal_handler(); srsran_register_signal_handler(signal_handler);
add_emergency_cleanup_handler(emergency_cleanup_handler, nullptr); add_emergency_cleanup_handler(emergency_cleanup_handler, nullptr);
all_args_t args = {}; all_args_t args = {};

@ -31,6 +31,7 @@ target_link_libraries( srsepc srsepc_mme
srsran_asn1 srsran_asn1
srsran_common srsran_common
srslog srslog
support
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_THREAD_LIBS_INIT}
${Boost_LIBRARIES} ${Boost_LIBRARIES}
${SEC_LIBRARIES} ${SEC_LIBRARIES}

@ -18,9 +18,10 @@
#include "srsran/common/common_helper.h" #include "srsran/common/common_helper.h"
#include "srsran/common/config_file.h" #include "srsran/common/config_file.h"
#include "srsran/common/crash_handler.h" #include "srsran/common/crash_handler.h"
#include "srsran/common/signal_handler.h"
#include "srsran/srslog/srslog.h" #include "srsran/srslog/srslog.h"
#include "srsran/srsran.h" #include "srsran/srsran.h"
#include "srsran/support/emergency_handlers.h"
#include "srsran/support/signal_handler.h"
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <iostream> #include <iostream>
@ -55,7 +56,8 @@ typedef struct {
log_args_t log_args; log_args_t log_args;
} all_args_t; } all_args_t;
static srslog::sink* log_sink = nullptr; static srslog::sink* log_sink = nullptr;
static std::atomic<bool> running = {true};
/********************************************************************** /**********************************************************************
* Program arguments processing * Program arguments processing
@ -363,9 +365,14 @@ static void emergency_cleanup_handler(void* data)
} }
} }
static void signal_handler()
{
running = false;
}
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
srsran_register_signal_handler(); srsran_register_signal_handler(signal_handler);
add_emergency_cleanup_handler(emergency_cleanup_handler, nullptr); add_emergency_cleanup_handler(emergency_cleanup_handler, nullptr);
// print build info // print build info

@ -22,7 +22,7 @@ endif (RPATH)
add_executable(srsue main.cc ue.cc metrics_stdout.cc metrics_csv.cc metrics_json.cc) add_executable(srsue main.cc ue.cc metrics_stdout.cc metrics_csv.cc metrics_json.cc)
set(SRSUE_SOURCES srsue_phy srsue_stack srsue_upper srsue_mac srsue_rrc srslog system) set(SRSUE_SOURCES srsue_phy srsue_stack srsue_upper srsue_mac srsue_rrc srslog system)
set(SRSRAN_SOURCES srsran_common srsran_mac srsran_phy srsran_radio srsran_gtpu srsran_rlc srsran_pdcp rrc_asn1 srslog system) set(SRSRAN_SOURCES srsran_common srsran_mac srsran_phy srsran_radio srsran_gtpu srsran_rlc srsran_pdcp rrc_asn1 srslog support system)
set(SRSUE_SOURCES ${SRSUE_SOURCES} srsue_nr_stack srsue_rrc_nr srsue_mac_nr) set(SRSUE_SOURCES ${SRSUE_SOURCES} srsue_nr_stack srsue_rrc_nr srsue_mac_nr)
set(SRSRAN_SOURCES ${SRSRAN_SOURCES} rrc_nr_asn1 ngap_nr_asn1) set(SRSRAN_SOURCES ${SRSRAN_SOURCES} rrc_nr_asn1 ngap_nr_asn1)

@ -15,11 +15,12 @@
#include "srsran/common/crash_handler.h" #include "srsran/common/crash_handler.h"
#include "srsran/common/metrics_hub.h" #include "srsran/common/metrics_hub.h"
#include "srsran/common/multiqueue.h" #include "srsran/common/multiqueue.h"
#include "srsran/common/signal_handler.h"
#include "srsran/common/tsan_options.h" #include "srsran/common/tsan_options.h"
#include "srsran/srslog/event_trace.h" #include "srsran/srslog/event_trace.h"
#include "srsran/srslog/srslog.h" #include "srsran/srslog/srslog.h"
#include "srsran/srsran.h" #include "srsran/srsran.h"
#include "srsran/support/emergency_handlers.h"
#include "srsran/support/signal_handler.h"
#include "srsran/version.h" #include "srsran/version.h"
#include "srsue/hdr/metrics_csv.h" #include "srsue/hdr/metrics_csv.h"
#include "srsue/hdr/metrics_json.h" #include "srsue/hdr/metrics_json.h"
@ -27,6 +28,7 @@
#include "srsue/hdr/ue.h" #include "srsue/hdr/ue.h"
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <boost/program_options/parsers.hpp> #include <boost/program_options/parsers.hpp>
#include <csignal>
#include <iostream> #include <iostream>
#include <pthread.h> #include <pthread.h>
#include <stdio.h> #include <stdio.h>
@ -45,9 +47,10 @@ namespace bpo = boost::program_options;
* Local static variables * Local static variables
***********************************************************************/ ***********************************************************************/
static bool do_metrics = false; static bool do_metrics = false;
static metrics_stdout* metrics_screen = nullptr; static metrics_stdout* metrics_screen = nullptr;
static srslog::sink* log_sink = nullptr; static srslog::sink* log_sink = nullptr;
static std::atomic<bool> running = {true};
/********************************************************************** /**********************************************************************
* Program arguments processing * Program arguments processing
@ -667,9 +670,14 @@ static void emergency_cleanup_handler(void* data)
srsran_dft_exit(); srsran_dft_exit();
} }
static void signal_handler()
{
running = false;
}
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
srsran_register_signal_handler(); srsran_register_signal_handler(signal_handler);
add_emergency_cleanup_handler(emergency_cleanup_handler, nullptr); add_emergency_cleanup_handler(emergency_cleanup_handler, nullptr);
srsran_debug_handle_crash(argc, argv); srsran_debug_handle_crash(argc, argv);

Loading…
Cancel
Save