diff options
author | Vadim Yanitskiy <vyanitskiy@sysmocom.de> | 2023-06-16 06:35:18 +0700 |
---|---|---|
committer | Vadim Yanitskiy <vyanitskiy@sysmocom.de> | 2023-06-16 06:51:59 +0700 |
commit | 749f0a461cc78b0fbd17f3eeee36dace4ba9c8be (patch) | |
tree | ea6b0694ef96126791a48e0bef85c59d8619c826 | |
parent | df900478de4f3931539c9f2b0387f9800a785f9f (diff) |
layer23: fix handling of logging category mask (-d option)
In change 67943df4 I broke handling of the logging category mask in
the mobile app. Adding this option results in a segfault:
ERROR: osmo_log_info == NULL! You must call log_init() before
using logging in log_parse_category_mask()!
Assert failed osmo_log_info src/libosmocore/src/core/logging.c:329
As can be seen, the problem is that we are calling
log_parse_category_mask() before initializing the logging.
As possible solution, I could rearrange the code to parse command
line options after calling osmo_init_logging2(). This would fix
the segfault, but would not fully solve the problem.
If we call log_parse_category_mask() before parsing the config file,
then logging configuration in the config file overwrites the logging
configuration specified via the command line. But we want the
opposite: the command line setting should overwrite the config file
parameters. This is handy because there is no need to edit the
config file if you quickly need to test something.
So let's call log_parse_category_mask() after parsing the config file.
Change-Id: I1b2b7804bf99b71f96e9197f7824cfd20431e8a1
Fixes: 67943df4 "layer23: fix parsing of command line options"
-rw-r--r-- | src/host/layer23/src/common/main.c | 6 | ||||
-rw-r--r-- | src/host/layer23/src/mobile/main.c | 6 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/host/layer23/src/common/main.c b/src/host/layer23/src/common/main.c index a4b94415..919a2315 100644 --- a/src/host/layer23/src/common/main.c +++ b/src/host/layer23/src/common/main.c @@ -58,6 +58,7 @@ static char *sap_socket_path = "/tmp/osmocom_sap"; struct llist_head ms_list; static char *gsmtap_ip = NULL; static char *config_file = NULL; +static char *log_cat_mask = NULL; int (*l23_app_start)(void) = NULL; int (*l23_app_work)(void) = NULL; @@ -162,7 +163,7 @@ static void handle_options(int argc, char **argv) config_file = optarg; break; case 'd': - log_parse_category_mask(osmo_stderr_target, optarg); + log_cat_mask = optarg; break; default: if (l23_app_info.cfg_handle_opt != NULL) @@ -268,6 +269,9 @@ int main(int argc, char **argv) exit(1); } + if (log_cat_mask != NULL) + log_parse_category_mask(osmo_stderr_target, log_cat_mask); + if (l23_app_info.opt_supported & L23_OPT_TAP) { if (gsmtap_ip) { if (l23_cfg.gsmtap.remote_host != NULL) { diff --git a/src/host/layer23/src/mobile/main.c b/src/host/layer23/src/mobile/main.c index 71a16c11..8720ea76 100644 --- a/src/host/layer23/src/mobile/main.c +++ b/src/host/layer23/src/mobile/main.c @@ -54,6 +54,7 @@ void *l23_ctx = NULL; struct l23_global_config l23_cfg; struct llist_head ms_list; static const char *custom_cfg_file = NULL; +static const char *log_cat_mask = NULL; static char *config_file = NULL; char *config_dir = NULL; int daemonize = 0; @@ -118,7 +119,7 @@ static int handle_options(int argc, char **argv) custom_cfg_file = optarg; break; case 'd': - log_parse_category_mask(osmo_stderr_target, optarg); + log_cat_mask = optarg; break; case 'D': daemonize = 1; @@ -297,6 +298,9 @@ int main(int argc, char **argv) exit(1); } + if (log_cat_mask != NULL) + log_parse_category_mask(osmo_stderr_target, log_cat_mask); + if (l23_cfg.gsmtap.remote_host) { l23_cfg.gsmtap.inst = gsmtap_source_init2(l23_cfg.gsmtap.local_host, 0, l23_cfg.gsmtap.remote_host, GSMTAP_UDP_PORT, 1); |