diff options
| author | Pau Espin Pedrol <pespin@sysmocom.de> | 2019-08-02 20:32:34 +0200 | 
|---|---|---|
| committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2019-08-02 20:35:15 +0200 | 
| commit | c21ba15b70504df175a611a75a1c4d3b52aa1f03 (patch) | |
| tree | c6b55e3c727448f5c7283ce632c27c37d445be71 | |
| parent | a37f58e98a28a8249178659ff3608203f5503772 (diff) | |
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
| -rw-r--r-- | src/vty/logging_vty.c | 24 | 
1 files changed, 13 insertions, 11 deletions
| 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; | 
