From c21ba15b70504df175a611a75a1c4d3b52aa1f03 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Fri, 2 Aug 2019 20:32:34 +0200 Subject: Get rid of osmo_str_tolower() use inside libosmocore code There's no real good reason for using that function (static buffer) instead of osmo_str_tolower_buf(local buffer), so let's use the later. In any case, we get rid of TLS variables in those places, which is a performance improvement. It will also allow later shrinking of those buffers if we decide to define maximum logging category and level name length. Change-Id: I2e99de1142020e4d80ef0a094e4e751f7903f5f9 --- src/vty/logging_vty.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/vty/logging_vty.c b/src/vty/logging_vty.c index 9911c6f9..b785be4c 100644 --- a/src/vty/logging_vty.c +++ b/src/vty/logging_vty.c @@ -289,14 +289,15 @@ DEFUN(logging_prnt_file, static void add_category_strings(char **cmd_str_p, char **doc_str_p, const struct log_info *categories) { + char buf[128]; int i; for (i = 0; i < categories->num_cat; i++) { if (categories->cat[i].name == NULL) continue; /* skip the leading 'D' in each category name, hence '+ 1' */ + osmo_str_tolower_buf(buf, sizeof(buf), categories->cat[i].name + 1); osmo_talloc_asprintf(tall_log_ctx, *cmd_str_p, "%s%s", - i ? "|" : "", - osmo_str_tolower(categories->cat[i].name + 1)); + i ? "|" : "", buf); osmo_talloc_asprintf(tall_log_ctx, *doc_str_p, "%s\n", categories->cat[i].description); } @@ -868,6 +869,7 @@ DEFUN(cfg_no_log_alarms, cfg_no_log_alarms_cmd, static int config_write_log_single(struct vty *vty, struct log_target *tgt) { + char level_buf[128]; int i; switch (tgt->type) { @@ -923,26 +925,25 @@ static int config_write_log_single(struct vty *vty, struct log_target *tgt) if (tgt->loglevel) { const char *level_str = get_value_string_or_null(loglevel_strs, tgt->loglevel); - level_str = osmo_str_tolower(level_str); - if (!level_str) + if (!level_str) { vty_out(vty, "%% Invalid log level %u for 'force-all'%s", tgt->loglevel, VTY_NEWLINE); - else - vty_out(vty, " logging level force-all %s%s", level_str, VTY_NEWLINE); + } else { + osmo_str_tolower_buf(level_buf, sizeof(level_buf), level_str); + vty_out(vty, " logging level force-all %s%s", level_buf, VTY_NEWLINE); + } } for (i = 0; i < osmo_log_info->num_cat; i++) { const struct log_category *cat = &tgt->categories[i]; - const char *cat_name; + char cat_name[128]; const char *level_str; /* skip empty entries in the array */ if (!osmo_log_info->cat[i].name) continue; - /* Note: cat_name references the static buffer returned by osmo_str_tolower(), will - * become invalid after next osmo_str_tolower() invocation. */ - cat_name = osmo_str_tolower(osmo_log_info->cat[i].name+1); + osmo_str_tolower_buf(cat_name, sizeof(cat_name), osmo_log_info->cat[i].name + 1); level_str = get_value_string_or_null(loglevel_strs, cat->loglevel); if (!level_str) { @@ -951,8 +952,9 @@ static int config_write_log_single(struct vty *vty, struct log_target *tgt) continue; } + osmo_str_tolower_buf(level_buf, sizeof(level_buf), level_str); vty_out(vty, " logging level %s", cat_name); - vty_out(vty, " %s%s", osmo_str_tolower(level_str), VTY_NEWLINE); + vty_out(vty, " %s%s", level_buf, VTY_NEWLINE); } return 1; -- cgit v1.2.3