pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-bts/+/41882?usp=email )
Change subject: Avoid accessing struct log_target members directly ......................................................................
Avoid accessing struct log_target members directly
Use newly available APIs instead.
Change-Id: Icd48874cf51d6af78305a30faeae48ba518e46b3 Depends: libosmocore.git Change-Id Ie48e7e635feb91509b9c034394df4fb16cb931a3 --- M TODO-RELEASE M src/common/logging.c M src/common/vty.c 3 files changed, 23 insertions(+), 16 deletions(-)
Approvals: fixeria: Looks good to me, approved Jenkins Builder: Verified osmith: Looks good to me, but someone else must approve
diff --git a/TODO-RELEASE b/TODO-RELEASE index 0ed7189..fb115da 100644 --- a/TODO-RELEASE +++ b/TODO-RELEASE @@ -7,3 +7,4 @@ # If any interfaces have been added since the last public release: c:r:a + 1. # If any interfaces have been removed or changed since the last public release: c:r:0. #library what description / commit summary line +libosmocore >1.12.0 log_get_context(), log_{get,set}_filter(_data)() diff --git a/src/common/logging.c b/src/common/logging.c index 15c126a..cbc4a19 100644 --- a/src/common/logging.c +++ b/src/common/logging.c @@ -136,12 +136,12 @@
static int osmo_bts_filter_fn(const struct log_context *ctx, struct log_target *tgt) { - uint8_t *sapi = ctx->ctx[LOG_CTX_L1_SAPI]; - uint16_t *sapi_mask = tgt->filter_data[LOG_FLT_L1_SAPI]; + uint8_t *sapi = log_get_context(ctx, LOG_CTX_L1_SAPI); + uint16_t *sapi_mask = log_get_filter_data(tgt, LOG_FLT_L1_SAPI);
- if ((tgt->filter_map & (1 << LOG_FLT_L1_SAPI)) != 0 - && sapi_mask && sapi - && (*sapi_mask & (1 << *sapi)) != 0) + if (log_get_filter(tgt, LOG_FLT_L1_SAPI) && + sapi_mask && sapi && + (*sapi_mask & (1 << *sapi)) != 0) return 1;
return 0; diff --git a/src/common/vty.c b/src/common/vty.c index d169342..62ebff2 100644 --- a/src/common/vty.c +++ b/src/common/vty.c @@ -2663,20 +2663,21 @@ { int sapi = get_string_value(l1sap_common_sapi_names, argv[0]); struct log_target *tgt = osmo_log_vty2tgt(vty); - uint16_t **sapi_mask; + uint16_t *sapi_mask;
OSMO_ASSERT(sapi >= 0); + OSMO_ASSERT(sapi <= 31); if (!tgt) return CMD_WARNING;
- sapi_mask = (uint16_t **)&tgt->filter_data[LOG_FLT_L1_SAPI]; + sapi_mask = log_get_filter_data(tgt, LOG_FLT_L1_SAPI);
- if (!*sapi_mask) - *sapi_mask = talloc(tgt, uint16_t); + if (!sapi_mask) + sapi_mask = talloc_zero(tgt, uint16_t);
- OSMO_ASSERT(sapi <= 31); - **sapi_mask |= (1 << sapi); - tgt->filter_map |= (1 << LOG_FLT_L1_SAPI); + *sapi_mask |= (1 << sapi); + log_set_filter_data(tgt, LOG_FLT_L1_SAPI, sapi_mask); + log_set_filter(tgt, LOG_FLT_L1_SAPI, true);
return CMD_SUCCESS; } @@ -2688,15 +2689,20 @@ uint16_t *sapi_mask;
OSMO_ASSERT(sapi >= 0); + OSMO_ASSERT(sapi <= 31); if (!tgt) return CMD_WARNING; - if (!tgt->filter_data[LOG_FLT_L1_SAPI]) + sapi_mask = (uint16_t *)log_get_filter_data(tgt, LOG_FLT_L1_SAPI); + if (!sapi_mask) return CMD_SUCCESS; - - OSMO_ASSERT(sapi <= 31); - sapi_mask = (uint16_t *)tgt->filter_data[LOG_FLT_L1_SAPI]; *sapi_mask &= ~(1 << sapi);
+ if (*sapi_mask == 0x0000) { + log_set_filter_data(tgt, LOG_FLT_L1_SAPI, NULL); + log_set_filter(tgt, LOG_FLT_L1_SAPI, false); + talloc_free(sapi_mask); + } + return CMD_SUCCESS; }