From 2129ee3c9c6d5970e27caa5c994fa777c172df31 Mon Sep 17 00:00:00 2001 From: Laurent THOMAS Date: Fri, 1 Mar 2024 13:02:03 +0100 Subject: [PATCH] remove global visibility of log variables, remove circular .h dependancy --- common/utils/LOG/log.c | 52 ++++++++----------- common/utils/LOG/log.h | 5 +- common/utils/LOG/log_extern.h | 31 ----------- common/utils/LOG/log_if.h | 34 ------------ doc/Doxyfile | 1 - executables/nr-gnb.c | 2 +- executables/softmodem-common.c | 6 +-- openair1/PHY/defs_common.h | 2 +- openair1/SIMULATION/LTE_PHY/framegen.c | 2 +- openair1/SIMULATION/LTE_PHY/pucchsim.c | 2 +- openair2/E1AP/e1ap_setup.c | 1 - openair2/ENB_APP/NB_IoT_config.c | 1 - openair2/GNB_APP/gnb_config.c | 1 - .../PDCP_v10.1.0/pdcp_sequence_manager.c | 2 +- openair2/UTIL/CLI/cli_cmd.c | 1 - openair2/UTIL/OPT/opt.h | 2 +- radio/IRIS/iris_lib.cpp | 2 +- targets/TEST/AT_COMMANDS/oaisim.c | 3 +- targets/TEST/PDCP/test_pdcp.c | 2 +- targets/TEST/PDCP/with_rlc/test_pdcp_rlc.c | 3 +- 20 files changed, 36 insertions(+), 119 deletions(-) delete mode 100644 common/utils/LOG/log_extern.h delete mode 100644 common/utils/LOG/log_if.h diff --git a/common/utils/LOG/log.c b/common/utils/LOG/log.c index d2ef196e55..0d0bc144f7 100644 --- a/common/utils/LOG/log.c +++ b/common/utils/LOG/log.c @@ -46,7 +46,7 @@ #include #include #include -#include "common/utils/LOG/log_extern.h" +#include "common/utils/LOG/log.h" // main log variables @@ -58,18 +58,16 @@ void read_cpu_hardware (void) __attribute__ ((constructor)); void read_cpu_hardware (void) {} #endif -log_mem_cnt_t log_mem_d[2]; -int log_mem_flag = 0; +static log_mem_cnt_t log_mem_d[2]; +static int log_mem_flag = 0; volatile int log_mem_side=0; -pthread_mutex_t log_mem_lock; -pthread_cond_t log_mem_notify; -pthread_t log_mem_thread; -int log_mem_file_cnt=0; +static pthread_mutex_t log_mem_lock; +static pthread_cond_t log_mem_notify; +static pthread_t log_mem_thread; +static int log_mem_file_cnt=0; volatile int log_mem_write_flag=0; volatile int log_mem_write_side=0; -char __log_mem_filename[1024]={0}; -char * log_mem_filename = &__log_mem_filename[0]; -char logmem_filename[1024] = {0}; +static char * log_mem_filename; const mapping log_level_names[] = {{"error", OAILOG_ERR}, {"warn", OAILOG_WARNING}, @@ -935,28 +933,22 @@ static void log_output_memory(log_component_t *c, const char *file, const char * } } -int logInit_log_mem (void) +int logInit_log_mem (char * filename) { - if (log_mem_flag == 1) { - log_mem_d[0].buf_p = malloc(LOG_MEM_SIZE); - log_mem_d[0].buf_index = 0; - log_mem_d[0].enable_flag = 1; - log_mem_d[1].buf_p = malloc(LOG_MEM_SIZE); - log_mem_d[1].buf_index = 0; - log_mem_d[1].enable_flag = 1; - log_mem_side = 0; - if ((pthread_mutex_init(&log_mem_lock, NULL) != 0) || (pthread_cond_init(&log_mem_notify, NULL) != 0)) { - log_mem_d[1].enable_flag=0; - return -1; - } - pthread_create(&log_mem_thread, NULL, (void *(*)(void *))flush_mem_to_file, (void *)NULL); - } else { - log_mem_d[0].buf_p = NULL; - log_mem_d[1].buf_p = NULL; - log_mem_d[0].enable_flag = 0; - log_mem_d[1].enable_flag = 0; + log_mem_flag = 1; + log_mem_filename = filename; // in present code, the parameter is safe permanent pointer + log_mem_d[0].buf_p = malloc(LOG_MEM_SIZE); + log_mem_d[0].buf_index = 0; + log_mem_d[0].enable_flag = 1; + log_mem_d[1].buf_p = malloc(LOG_MEM_SIZE); + log_mem_d[1].buf_index = 0; + log_mem_d[1].enable_flag = 1; + log_mem_side = 0; + if ((pthread_mutex_init(&log_mem_lock, NULL) != 0) || (pthread_cond_init(&log_mem_notify, NULL) != 0)) { + log_mem_d[1].enable_flag=0; + return -1; } - + pthread_create(&log_mem_thread, NULL, (void *(*)(void *))flush_mem_to_file, (void *)NULL); printf("log init done\n"); return 0; diff --git a/common/utils/LOG/log.h b/common/utils/LOG/log.h index eb557ed28f..af4c0fe82f 100644 --- a/common/utils/LOG/log.h +++ b/common/utils/LOG/log.h @@ -272,8 +272,7 @@ extern "C" { } #endif #endif -/*--- INCLUDES ---------------------------------------------------------------*/ -# include "log_if.h" + /*----------------------------------------------------------------------------*/ int logInit (void); void logTerm (void); @@ -299,7 +298,7 @@ int register_log_component(char *name, char *fext, int compidx); #define LOG_MEM_SIZE 100*1024*1024 #define LOG_MEM_FILE "./logmem.log" void flush_mem_to_file(void); -int logInit_log_mem(void); +int logInit_log_mem(char*); void close_log_mem(void); typedef struct { diff --git a/common/utils/LOG/log_extern.h b/common/utils/LOG/log_extern.h deleted file mode 100644 index 4a253530e7..0000000000 --- a/common/utils/LOG/log_extern.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -#include "log.h" - -extern log_t *g_log; - -extern const mapping log_level_names[]; -extern const mapping log_options[]; -extern const mapping log_maskmap[]; -extern int log_mem_flag; -extern char * log_mem_filename; -extern char logmem_filename[1024]; diff --git a/common/utils/LOG/log_if.h b/common/utils/LOG/log_if.h deleted file mode 100644 index 531b9df62e..0000000000 --- a/common/utils/LOG/log_if.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file log_if.h -* \brief log interface -* \author Navid Nikaein -* \date 2009 - 2014 -* \version 0.3 -* \warning This component can be runned only in user-space -* @ingroup routing -*/ - -// LTS: kept this file for compatibility -// this file was probably a trial to separate internal functions and external ones -// but it has never been finished, most source code include directly log.h (not log_if.h) -#include "log.h" diff --git a/doc/Doxyfile b/doc/Doxyfile index c92e9fb336..53b59bb536 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -902,7 +902,6 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../common/utils/LOG/vcd_signal_dumper.h \ @CMAKE_CURRENT_SOURCE_DIR@/../common/utils/LOG/log.c \ @CMAKE_CURRENT_SOURCE_DIR@/../common/utils/LOG/log.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../common/utils/LOG/log_extern.h \ @CMAKE_CURRENT_SOURCE_DIR@/../common/utils/time_stat.h \ @CMAKE_CURRENT_SOURCE_DIR@/../common/utils/ocp_itti/all_msg.h \ @CMAKE_CURRENT_SOURCE_DIR@/../common/utils/ocp_itti/intertask_interface.h \ diff --git a/executables/nr-gnb.c b/executables/nr-gnb.c index 2a12126d7d..a67754e6f9 100644 --- a/executables/nr-gnb.c +++ b/executables/nr-gnb.c @@ -69,7 +69,7 @@ #include "common/ran_context.h" #include "RRC/LTE/rrc_extern.h" #include "PHY_INTERFACE/phy_interface.h" -#include "common/utils/LOG/log_extern.h" +#include "common/utils/LOG/log.h" #include "UTIL/OTG/otg_tx.h" #include "UTIL/OTG/otg_externs.h" #include "UTIL/MATH/oml.h" diff --git a/executables/softmodem-common.c b/executables/softmodem-common.c index b750092a39..c4b25d7f20 100644 --- a/executables/softmodem-common.c +++ b/executables/softmodem-common.c @@ -138,10 +138,8 @@ void get_common_options(configmodule_interface_t *cfg, uint32_t execmask) } if (logmem_filename != NULL && strlen(logmem_filename) > 0) { - log_mem_filename = &logmem_filename[0]; - log_mem_flag = 1; - printf("Enabling OPT for log save at memory %s\n",log_mem_filename); - logInit_log_mem(); + printf("Enabling OPT for log save at memory %s\n",logmem_filename); + logInit_log_mem(logmem_filename); } if (noS1) { diff --git a/openair1/PHY/defs_common.h b/openair1/PHY/defs_common.h index 7098bd8c6f..ff774d7789 100644 --- a/openair1/PHY/defs_common.h +++ b/openair1/PHY/defs_common.h @@ -953,7 +953,7 @@ typedef enum {no_relay=1,unicast_relay_type1,unicast_relay_type2, multicast_rela #define NB_BANDS_MAX 8 -#include "common/utils/LOG/log_extern.h" +#include "common/utils/LOG/log.h" extern pthread_cond_t sync_cond; extern pthread_mutex_t sync_mutex; extern int sync_var; diff --git a/openair1/SIMULATION/LTE_PHY/framegen.c b/openair1/SIMULATION/LTE_PHY/framegen.c index 74f76e56b9..521df12ca1 100644 --- a/openair1/SIMULATION/LTE_PHY/framegen.c +++ b/openair1/SIMULATION/LTE_PHY/framegen.c @@ -39,7 +39,7 @@ #include "LAYER2/MAC/defs.h" #include "PHY_INTERFACE/defs.h" #include "LAYER2/MAC/vars.h" -#include "UTIL/LOG/log_extern.h" +#include "UTIL/LOG/log.h" uint16_t n_rnti = 0x1235; int n_users = 1; diff --git a/openair1/SIMULATION/LTE_PHY/pucchsim.c b/openair1/SIMULATION/LTE_PHY/pucchsim.c index f88934d380..2ca891f023 100644 --- a/openair1/SIMULATION/LTE_PHY/pucchsim.c +++ b/openair1/SIMULATION/LTE_PHY/pucchsim.c @@ -31,7 +31,7 @@ #include "SCHED/vars.h" #include "LAYER2/MAC/vars.h" -#include "UTIL/LOG/log_extern.h" +#include "UTIL/LOG/log.h" #include "unitary_defs.h" diff --git a/openair2/E1AP/e1ap_setup.c b/openair2/E1AP/e1ap_setup.c index 70f90b9a56..31dbf6e407 100644 --- a/openair2/E1AP/e1ap_setup.c +++ b/openair2/E1AP/e1ap_setup.c @@ -24,7 +24,6 @@ #include #include "common/utils/LOG/log.h" #include "common/utils/nr/nr_common.h" -#include "common/utils/LOG/log_extern.h" #include "assertions.h" #include "common/utils/ocp_itti/intertask_interface.h" #include "openair2/GNB_APP/gnb_paramdef.h" diff --git a/openair2/ENB_APP/NB_IoT_config.c b/openair2/ENB_APP/NB_IoT_config.c index 0bd30d86b3..35e3ade4a4 100644 --- a/openair2/ENB_APP/NB_IoT_config.c +++ b/openair2/ENB_APP/NB_IoT_config.c @@ -31,7 +31,6 @@ #include #include "log.h" -#include "log_extern.h" #include "assertions.h" #include "intertask_interface.h" #include "s1ap_eNB.h" diff --git a/openair2/GNB_APP/gnb_config.c b/openair2/GNB_APP/gnb_config.c index 3b5d159d34..1046e24e11 100644 --- a/openair2/GNB_APP/gnb_config.c +++ b/openair2/GNB_APP/gnb_config.c @@ -32,7 +32,6 @@ #include "common/utils/LOG/log.h" #include "common/utils/nr/nr_common.h" -#include "common/utils/LOG/log_extern.h" #include "assertions.h" #include "oai_asn1.h" #include "executables/softmodem-common.h" diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_sequence_manager.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_sequence_manager.c index 31beb3a9e0..69d355533a 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_sequence_manager.c +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_sequence_manager.c @@ -27,7 +27,7 @@ */ #include "pdcp_sequence_manager.h" -#include "common/utils//LOG/log_if.h" +#include "common/utils//LOG/log.h" #include "pdcp_util.h" /* diff --git a/openair2/UTIL/CLI/cli_cmd.c b/openair2/UTIL/CLI/cli_cmd.c index 021c7c0b97..59f6bebfd2 100644 --- a/openair2/UTIL/CLI/cli_cmd.c +++ b/openair2/UTIL/CLI/cli_cmd.c @@ -32,7 +32,6 @@ #include "cli.h" #include "log.h" -#include "log_extern.h" extern cli_config *cli_cfg; diff --git a/openair2/UTIL/OPT/opt.h b/openair2/UTIL/OPT/opt.h index ce890a7933..e3b8059f23 100644 --- a/openair2/UTIL/OPT/opt.h +++ b/openair2/UTIL/OPT/opt.h @@ -48,7 +48,7 @@ This header file must be included */ #endif #ifndef project_include #define project_include - #include "common/utils/LOG/log_if.h" + #include "common/utils/LOG/log.h" #include "PHY/defs_RU.h" #endif diff --git a/radio/IRIS/iris_lib.cpp b/radio/IRIS/iris_lib.cpp index 47f4d2b4ef..44cea81b4e 100644 --- a/radio/IRIS/iris_lib.cpp +++ b/radio/IRIS/iris_lib.cpp @@ -19,7 +19,7 @@ #include #include #include -#include "common/utils/LOG/log_extern.h" +#include "common/utils/LOG/log.h" #include "common_lib.h" #include diff --git a/targets/TEST/AT_COMMANDS/oaisim.c b/targets/TEST/AT_COMMANDS/oaisim.c index bbbbe3da5f..fa6a348c97 100644 --- a/targets/TEST/AT_COMMANDS/oaisim.c +++ b/targets/TEST/AT_COMMANDS/oaisim.c @@ -32,8 +32,7 @@ #include "LAYER2/RLC/AM_v9.3.0/rlc_am.h" #include "LAYER2/MAC/defs.h" #include "LAYER2/MAC/vars.h" -#include "UTIL/LOG/log_if.h" -#include "UTIL/LOG/log_extern.h" +#include "UTIL/LOG/log.h" #include "RRC/LTE/vars.h" #include "PHY_INTERFACE/vars.h" #include "UTIL/AT_COMMANDS/parser.h" diff --git a/targets/TEST/PDCP/test_pdcp.c b/targets/TEST/PDCP/test_pdcp.c index fb8259bbde..1e634fa74d 100644 --- a/targets/TEST/PDCP/test_pdcp.c +++ b/targets/TEST/PDCP/test_pdcp.c @@ -27,7 +27,7 @@ #include "MAC_INTERFACE/vars.h" #include "LAYER2/MAC/vars.h" -#include "UTIL/LOG/log_if.h" +#include "UTIL/LOG/log.h" #include "test_util.h" #include "test_pdcp.h" diff --git a/targets/TEST/PDCP/with_rlc/test_pdcp_rlc.c b/targets/TEST/PDCP/with_rlc/test_pdcp_rlc.c index 7116f696dc..b60737dac8 100644 --- a/targets/TEST/PDCP/with_rlc/test_pdcp_rlc.c +++ b/targets/TEST/PDCP/with_rlc/test_pdcp_rlc.c @@ -32,8 +32,7 @@ #include "LAYER2/MAC/defs.h" #include "LAYER2/MAC/vars.h" -#include "UTIL/LOG/log_if.h" -#include "UTIL/LOG/log_extern.h" +#include "UTIL/LOG/log.h" #include "RRC/LTE/vars.h" #include "PHY_INTERFACE/vars.h" #include "LAYER2/PDCP_v10.1.0/pdcp.h"