From 3e51d3e5bd6d3c2dff79e47c7ad22c073b0dba93 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 29 Oct 2017 10:57:27 +0100 Subject: Call osmo_init_logging() before static BTS constructor The BTS constructor uses functions of libosmocore that could in turn want to log something. This requires the logging to be initialized before. The only way to achieve this is to add an __attribute__((constructor)) function *before* the BTS constructor is being run. This solution might not be elegant, but I guess it's the only way to initialize a C library before calling C++ constructors of global static instance of a class. In case anyone comes up with a better / cleaner approach, we can always change later. This change requires libosmocore >= 0.10.1, as only that permits multiple calls to osmo_init_logging() which may now occur. Change-Id: I28dc4f0db229518348c92413959fed5ae85d753d --- src/bts.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/bts.cpp') diff --git a/src/bts.cpp b/src/bts.cpp index b7685698..e41b1fa9 100644 --- a/src/bts.cpp +++ b/src/bts.cpp @@ -36,6 +36,7 @@ extern "C" { #include #include #include + #include } #include @@ -48,6 +49,16 @@ extern "C" { extern void *tall_pcu_ctx; +extern "C" { + /* e must make sure to initialize logging before the BTS static + * constructors are executed below, as those call libosmocore APIs that + * require logging already to be initialized. */ + __attribute__((constructor)) static void early_init(void) + { + osmo_init_logging(&gprs_log_info); + } +} + static BTS s_bts; /** -- cgit v1.2.3