From ff00101c9243d4ce1788a86586f674f5905ecd6b Mon Sep 17 00:00:00 2001 From: maweiye Date: Fri, 6 Jan 2023 18:00:27 +0800 Subject: [PATCH] fixed 839e18a from https://gitee.com/dhy308/third_party_musl/pulls/774 Replace SystemReadParam with CachedParameterGet Issue:I67DWL Test:build Signed-off-by: maweiye --- porting/linux/user/ldso/ld_log.c | 46 ++++--------------- porting/linux/user/src/hilog/hilog_adapter.c | 26 +++++++---- .../linux/user/src/internal/hilog_adapter.h | 5 ++ porting/linux/user/src/time/__tz.c | 10 ++-- 4 files changed, 37 insertions(+), 50 deletions(-) diff --git a/porting/linux/user/ldso/ld_log.c b/porting/linux/user/ldso/ld_log.c index 0505d9bd..bd1c5492 100644 --- a/porting/linux/user/ldso/ld_log.c +++ b/porting/linux/user/ldso/ld_log.c @@ -53,40 +53,26 @@ static char *get_app_name(char *buf, size_t length) return app; } -static bool get_ld_log_app_value(char *buffer, uint32_t *length) +static bool get_ld_log_value() { char buf[PROCESS_NAME_LEN]; char *path = get_app_name(buf, PROCESS_NAME_LEN); if (!path) { - buffer[0] = 0; return false; } char app_param_name[PROCESS_NAME_LEN] = "musl.log.ld.app."; strcat(app_param_name, path); - if (SystemReadParam(app_param_name, buffer, length) == 0) { - buffer[*length] = 0; - return true; + static CachedHandle app_param_handle = NULL; + static CachedHandle all_param_handle = NULL; + if (app_param_handle == NULL) { + app_param_handle = CachedParameterCreate(app_param_name, "false"); } - buffer[0] = 0; - return false; -} - -static bool get_ld_log_all_value(char *buffer, uint32_t *length) -{ - if (SystemReadParam("musl.log.ld.all", buffer, length) == 0) { - buffer[*length] = 0; - return true; + if (all_param_handle == NULL) { + all_param_handle = CachedParameterCreate("musl.log.ld.all", "false"); } - buffer[0] = 0; - return false; -} - -static inline void assign_ld_log_enable(char *param_value, const char *expect_value) -{ - ld_log_enable = (strcmp(param_value, expect_value) == 0); + return (get_bool_sysparam(app_param_handle) || get_bool_sysparam(all_param_handle)); } - #endif void ld_log_reset() @@ -96,21 +82,7 @@ void ld_log_reset() ld_log_enable = false; return; } - - char app_param_value[SYSPARAM_LENGTH]; - uint32_t app_param_value_len = SYSPARAM_LENGTH; - char all_param_value[SYSPARAM_LENGTH]; - uint32_t all_param_value_len = SYSPARAM_LENGTH; - - if (get_ld_log_app_value(app_param_value, &app_param_value_len)) { - assign_ld_log_enable(app_param_value, "true"); - } else { - if (get_ld_log_all_value(all_param_value, &all_param_value_len)) { - assign_ld_log_enable(all_param_value, "true"); - } else { - ld_log_enable = false; - } - } + ld_log_enable = get_ld_log_value(); #else ld_log_enable = is_musl_log_enable(); #endif diff --git a/porting/linux/user/src/hilog/hilog_adapter.c b/porting/linux/user/src/hilog/hilog_adapter.c index b4a28cba..8b63f03b 100644 --- a/porting/linux/user/src/hilog/hilog_adapter.c +++ b/porting/linux/user/src/hilog/hilog_adapter.c @@ -148,19 +148,27 @@ bool HiLogAdapterIsLoggable(unsigned int domain, const char *tag, LogLevel level return true; } -void musl_log_reset() +#ifdef OHOS_ENABLE_PARAMETER +bool get_bool_sysparam(CachedHandle cachedhandle) { -#if (defined(OHOS_ENABLE_PARAMETER)) - char param_value[SYSPARAM_LENGTH]; - uint32_t length = SYSPARAM_LENGTH; - if (SystemReadParam(param_name, param_value, &length) == 0) { - param_value[length] = 0; + char *param_value = CachedParameterGet(cachedhandle); + if (param_value != NULL) { if (strcmp(param_value, "true") == 0) { - musl_log_enable = true; - return; + return true; } } - musl_log_enable = false; + return false; +} +#endif + +void musl_log_reset() +{ +#if (defined(OHOS_ENABLE_PARAMETER)) + static CachedHandle musl_log_Handle = NULL; + if (musl_log_Handle == NULL) { + musl_log_Handle = CachedParameterCreate(param_name, "false"); + } + musl_log_enable = get_bool_sysparam(musl_log_Handle); #elif (defined(ENABLE_MUSL_LOG)) musl_log_enable = true; #endif diff --git a/porting/linux/user/src/internal/hilog_adapter.h b/porting/linux/user/src/internal/hilog_adapter.h index b0225117..142b1425 100644 --- a/porting/linux/user/src/internal/hilog_adapter.h +++ b/porting/linux/user/src/internal/hilog_adapter.h @@ -48,6 +48,11 @@ hidden int HiLogAdapterPrint(LogType type, LogLevel level, unsigned int domain, hidden bool HiLogAdapterIsLoggable(unsigned int domain, const char *tag, LogLevel level); +#ifdef OHOS_ENABLE_PARAMETER +#include "sys_param.h" +hidden bool get_bool_sysparam(CachedHandle cachedhandle); +#endif + hidden bool is_musl_log_enable(); hidden void musl_log_reset(); diff --git a/porting/linux/user/src/time/__tz.c b/porting/linux/user/src/time/__tz.c index 74f4dc4f..87e97c89 100755 --- a/porting/linux/user/src/time/__tz.c +++ b/porting/linux/user/src/time/__tz.c @@ -157,10 +157,12 @@ static void do_tzset() s = getenv("TZ"); if (!s) { #ifdef OHOS_ENABLE_PARAMETER - uint32_t tz_param_value_len = SYSPARAM_LENGTH; - char tz_param_value[SYSPARAM_LENGTH + 1] = {0}; - if (SystemReadParam("persist.time.timezone", tz_param_value, &tz_param_value_len) == 0) { - tz_param_value[tz_param_value_len] = 0; + static CachedHandle tz_param_handle = NULL; + if (tz_param_handle == NULL) { + tz_param_handle = CachedParameterCreate("persist.time.timezone", "/etc/localtime"); + } + const char *tz_param_value = CachedParameterGet(tz_param_handle); + if (tz_param_value != NULL){ s = tz_param_value; } else { s = "/etc/localtime"; -- GitLab