未验证 提交 49c38808 编写于 作者: O openharmony_ci 提交者: Gitee

!774 Replace SystemReadParam with CachedParameterGet

Merge pull request !774 from maweiye/update-param
......@@ -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
......
......@@ -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
......
......@@ -50,6 +50,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();
......
......@@ -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";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册