未验证 提交 9449c80a 编写于 作者: O openharmony_ci 提交者: Gitee

!916 解决litem下系统参数初始化问题

Merge pull request !916 from Mupceet/initlite
......@@ -121,10 +121,13 @@ if (defined(ohos_lite)) {
deps += [ "//third_party/mbedtls:mbedtls" ]
defines += [ "USE_MBEDTLS" ]
}
deps += [
"//base/startup/init_lite/services/param/liteos:param_client_lite",
"//base/startup/init_lite/services/utils:libinit_utils",
]
if (enable_ohos_startup_init_feature_begetctl_liteos) {
deps += [
"//base/startup/init_lite/services/log:init_log",
"//base/startup/init_lite/services/param/liteos:param_client_lite",
"//base/startup/init_lite/services/utils:libinit_utils",
]
}
}
}
......
......@@ -33,6 +33,9 @@ if (defined(ohos_lite)) {
if (ohos_kernel_type == "linux") {
defines += [ "INIT_DMESG" ]
}
if (ohos_kernel_type == "liteos_m") {
defines += [ "__LITEOS_M__" ]
}
include_dirs = [
"//base/hiviewdfx/hilog_lite/interfaces/native/kits",
"//third_party/bounds_checking_function/include",
......
......@@ -97,9 +97,13 @@ void LogToDmesg(InitLogLevel logLevel, const char *tag, const char *info)
static void PrintLog(InitLogLevel logLevel, unsigned int domain, const char *tag, const char *logInfo)
{
#ifdef OHOS_LITE
#ifdef __LITEOS_M__
printf("[%s]%s \n", tag, logInfo);
#else
static const LogLevel LOG_LEVEL[] = { LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL };
(void)HiLogPrint(INIT_LOG_INIT, LOG_LEVEL[logLevel], domain, tag, "%{public}s", logInfo);
#endif
#endif
#ifdef INIT_DMESG
LogToDmesg(logLevel, tag, logInfo);
#endif
......
......@@ -116,7 +116,7 @@ static int LoadParamLabels(const char *fileName)
char *buff = (char *)calloc(1, buffSize);
while (fp != NULL && buff != NULL && fgets(buff, buffSize, fp) != NULL) {
buff[buffSize - 1] = '\0';
int ret = SpliteString(buff, NULL, 0, LoadOneParam_, NULL);
int ret = SplitParamString(buff, NULL, 0, LoadOneParam_, NULL);
if (ret != 0) {
PARAM_LOGE("Failed to split string %s fileName %s", buff, fileName);
continue;
......
......@@ -56,7 +56,7 @@ static int LoadPersistParam()
uint32_t paramNum = 0;
while (fgets(buffer, buffSize, fp) != NULL) {
buffer[buffSize - 1] = '\0';
int ret = SpliteString(buffer, NULL, 0, LoadOnePersistParam_, NULL);
int ret = SplitParamString(buffer, NULL, 0, LoadOnePersistParam_, NULL);
PARAM_CHECK(ret == 0, continue, "Failed to set param %d %s", ret, buffer);
paramNum++;
}
......@@ -125,7 +125,7 @@ static void BatchSavePersistParamEnd(PERSIST_SAVE_HANDLE handle)
int RegisterPersistParamOps(PersistParamOps *ops)
{
ParamMutexCeate(&g_saveMutex);
ParamMutexCreate(&g_saveMutex);
PARAM_CHECK(ops != NULL, return -1, "Invalid ops");
ops->save = SavePersistParam;
ops->load = LoadPersistParam;
......
......@@ -320,7 +320,7 @@ INIT_LOCAL_API ParamSecurityLabel *GetParamSecurityLabel()
return &paramSpace->securityLabel;
}
int SpliteString(char *line, const char *exclude[], uint32_t count,
int SplitParamString(char *line, const char *exclude[], uint32_t count,
int (*result)(const uint32_t *context, const char *name, const char *value), const uint32_t *context)
{
// Skip spaces
......
......@@ -142,7 +142,7 @@ int ParamRWMutexRDLock(ParamRWMutex *lock);
int ParamRWMutexUnlock(ParamRWMutex *lock);
int ParamRWMutexDelete(ParamRWMutex *lock);
int ParamMutexCeate(ParamMutex *mutex);
int ParamMutexCreate(ParamMutex *mutex);
int ParamMutexPend(ParamMutex *mutex);
int ParamMutexPost(ParamMutex *mutex);
int ParamMutexDelete(ParamMutex *mutex);
......
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......@@ -50,6 +50,8 @@ int RegisterPersistParamOps(PersistParamOps *ops);
void TimerCallbackForSave(ParamTaskPtr timer, void *context);
#endif
void CheckAndSavePersistParam(void);
#ifdef __cplusplus
#if __cplusplus
}
......
......@@ -69,7 +69,7 @@ typedef struct cmdLineInfo {
#ifdef __LITEOS_M__
#ifndef DATA_PATH
#define DATA_PATH ""
#define DATA_PATH "/"
#endif
#elif defined __LITEOS_A__
#define DATA_PATH STARTUP_INIT_UT_PATH"/storage/data/system/param/"
......@@ -133,7 +133,7 @@ typedef struct cmdLineInfo {
#define SUBSTR_INFO_DAC 1
#endif
int SpliteString(char *line, const char *exclude[], uint32_t count,
int SplitParamString(char *line, const char *exclude[], uint32_t count,
int (*result)(const uint32_t *context, const char *name, const char *value), const uint32_t *context);
#ifdef __cplusplus
#if __cplusplus
......
......@@ -77,6 +77,7 @@ if (defined(ohos_lite)) {
"_GNU_SOURCE",
"__LINUX__",
"OHOS_LITE",
"PARAM_SUPPORT_REAL_CHECK",
"INCREMENTAL_VERSION=\"${ohos_version}\"",
"BUILD_TYPE=\"${ohos_build_type}\"",
"BUILD_USER=\"${ohos_build_user}\"",
......@@ -102,7 +103,10 @@ if (defined(ohos_lite)) {
sources += param_trigger_sources
include_dirs = param_include_dirs
public_configs = [ ":exported_header_files" ]
defines = [ "_GNU_SOURCE" ]
defines = [
"_GNU_SOURCE",
"PARAM_SUPPORT_REAL_CHECK",
]
if (defined(boot_kernel_extended_cmdline)) {
defines += [ "BOOT_EXTENDED_CMDLINE=\"${boot_kernel_extended_cmdline}\"" ]
......
......@@ -49,7 +49,7 @@ int ParamRWMutexDelete(ParamRWMutex *lock)
return 0;
}
int ParamMutexCeate(ParamMutex *mutex)
int ParamMutexCreate(ParamMutex *mutex)
{
return 0;
}
......
......@@ -13,6 +13,7 @@
import("//base/startup/init_lite/begetd.gni")
param_include_dirs = [
"//base/startup/init_lite/interfaces/innerkits/include/syspara",
"//base/startup/init_lite/services/param/include",
"//base/startup/init_lite/services/param/adapter",
"//base/startup/init_lite/services/include/param",
......@@ -116,25 +117,26 @@ static_library("param_client_lite") {
"WORKSPACE_AREA_NEED_MUTEX",
"PARAM_PERSIST_SAVE_MUTEX",
"PARAMWORKSPACE_NEED_MUTEX",
"PARAM_SUPPORT_CYCLE_CHECK",
]
} else if (ohos_kernel_type == "liteos_m") {
sources +=
[ "//base/startup/init_lite/services/param/manager/param_server.c" ]
sources += [
"//base/startup/init_lite/services/param/liteos/param_hal.c",
"//base/startup/init_lite/services/param/liteos/param_service.c",
"//base/startup/init_lite/services/param/manager/param_server.c",
]
if (enable_ohos_startup_init_lite_use_posix_file_api) {
sources += [
"//base/startup/init_lite/services/param/adapter/param_persistadp.c",
]
} else {
sources +=
[ "//base/startup/init_lite/services/param/liteos/param_hal.c" ]
defines += [ "PARAM_SUPPORT_POSIX" ]
}
defines += [
"__LITEOS_M__",
"WORKSPACE_AREA_NEED_MUTEX",
"PARAM_PERSIST_SAVE_MUTEX",
"PARAMWORKSPACE_NEED_MUTEX",
"DATA_PATH=\"${config_ohos_startup_init_lite_data_path}\"",
]
if (config_ohos_startup_init_lite_data_path != "") {
defines += [ "DATA_PATH=\"${config_ohos_startup_init_lite_data_path}\"" ]
}
if (enable_ohos_startup_init_feature_begetctl_liteos) {
deps = [ ":lite_ohos_param_to" ]
include_dirs += [ "$root_out_dir/gen/init_lite" ]
......
......@@ -14,12 +14,10 @@
*/
#include "init_param.h"
#include "param_manager.h"
#ifdef PARAM_LOAD_CFG_FROM_CODE
#include "param_cfg.h"
#endif
#define MIN_SLEEP (100 * 1000)
static int g_flags = 0;
__attribute__((constructor)) static void ClientInit(void);
__attribute__((destructor)) static void ClientDeinit(void);
......@@ -28,40 +26,26 @@ static int InitParamClient(void)
if (PARAM_TEST_FLAG(g_flags, WORKSPACE_FLAGS_INIT)) {
return 0;
}
#ifdef __LITEOS_M__
int ret = InitParamWorkSpace(0);
#else
EnableInitLog(INIT_INFO);
int ret = InitParamWorkSpace(1);
#endif
PARAM_LOGV("InitParamClient");
int ret = InitParamWorkSpace(1);
PARAM_CHECK(ret == 0, return -1, "Failed to init param workspace");
PARAM_SET_FLAG(g_flags, WORKSPACE_FLAGS_INIT);
// init persist to save
InitPersistParamWorkSpace();
#ifdef PARAM_LOAD_CFG_FROM_CODE
for (size_t i = 0; i < ARRAY_LENGTH(g_paramDefCfgNodes); i++) {
PARAM_LOGI("InitParamClient name %s = %s", g_paramDefCfgNodes[i].name, g_paramDefCfgNodes[i].value);
uint32_t dataIndex = 0;
ret = WriteParam(g_paramDefCfgNodes[i].name, g_paramDefCfgNodes[i].value, &dataIndex, 0);
PARAM_CHECK(ret == 0, continue, "Failed to set param %d name %s %s",
ret, g_paramDefCfgNodes[i].name, g_paramDefCfgNodes[i].value);
}
#endif
#ifdef __LITEOS_M__
LoadParamFromBuild();
// get persist param
LoadPersistParams();
#endif
return 0;
}
void ClientInit(void)
{
PARAM_LOGV("ClientInit");
#ifdef __LITEOS_M__
InitParamService();
#else
#ifndef STARTUP_INIT_TEST
(void)InitParamClient();
#endif
#endif
}
void ClientDeinit(void)
......@@ -75,7 +59,6 @@ void ClientDeinit(void)
int SystemSetParameter(const char *name, const char *value)
{
PARAM_CHECK(name != NULL && value != NULL, return -1, "Invalid name or value %s", name);
InitParamClient();
int ctrlService = 0;
int ret = CheckParameterSet(name, value, GetParamSecurityLabel(), &ctrlService);
PARAM_CHECK(ret == 0, return ret, "Forbid to set parameter %s", name);
......@@ -139,13 +122,11 @@ int WatchParamCheck(const char *keyprefix)
int SystemCheckParamExist(const char *name)
{
(void)InitParamClient();
return SysCheckParamExist(name);
}
int SystemFindParameter(const char *name, ParamHandle *handle)
{
(void)InitParamClient();
PARAM_CHECK(name != NULL && handle != NULL, return -1, "The name or handle is null");
int ret = ReadParamWithCheck(name, DAC_READ, handle);
if (ret != PARAM_CODE_NOT_FOUND && ret != 0 && ret != PARAM_CODE_NODE_EXIST) {
......
......@@ -28,6 +28,83 @@
// for linux, no mutex
static ParamMutex g_saveMutex = {};
#ifdef PARAM_SUPPORT_POSIX
#define MODE_READ O_RDONLY
#define MODE_APPEND (O_RDWR | O_CREAT | O_APPEND)
#define MODE_CREATE (O_RDWR | O_CREAT | O_TRUNC)
#else
#define MODE_READ O_RDONLY_FS
#define MODE_APPEND (O_RDWR_FS | O_CREAT_FS | O_APPEND_FS)
#define MODE_CREATE (O_RDWR_FS | O_CREAT_FS | O_TRUNC_FS)
#endif
static int ParamFileOpen(const char* path, int oflag, int mode)
{
#ifdef PARAM_SUPPORT_POSIX
return open(path, oflag, mode);
#else
return UtilsFileOpen(path, oflag, mode);
#endif
}
static int ParamFileClose(int fd)
{
#ifdef PARAM_SUPPORT_POSIX
return close(fd);
#else
return UtilsFileClose(fd);
#endif
}
static int ParamFileRead(int fd, char* buf, unsigned int len)
{
#ifdef PARAM_SUPPORT_POSIX
return read(fd, buf, len);
#else
return UtilsFileRead(fd, buf, len);
#endif
}
static int ParamFileWrite(int fd, const char* buf, unsigned int len)
{
#ifdef PARAM_SUPPORT_POSIX
return write(fd, buf, len);
#else
return UtilsFileWrite(fd, buf, len);
#endif
}
static int ParamFileDelete(const char* path)
{
#ifdef PARAM_SUPPORT_POSIX
return unlink(path);
#else
return UtilsFileDelete(path);
#endif
}
static int ParamFileStat(const char* path, unsigned int* fileSize)
{
#ifdef PARAM_SUPPORT_POSIX
int fd = open(path, O_RDONLY);
if (fd < 0) {
return -1;
}
*fileSize = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
return 0;
#else
return UtilsFileStat(path, fileSize);
#endif
}
static void ParamFileSync(int ft)
{
#ifdef PARAM_SUPPORT_POSIX
fsync(ft);
#else
#endif
}
static int LoadOnePersistParam_(const uint32_t *context, const char *name, const char *value)
{
......@@ -45,27 +122,27 @@ static int LoadPersistParam(void)
int fd = -1;
uint32_t paramNum = 0;
do {
fd = UtilsFileOpen(path, O_RDONLY_FS, 0);
fd = ParamFileOpen(path, MODE_READ, 0);
if (fd < 0) {
path = PARAM_PERSIST_SAVE_PATH;
fd = UtilsFileOpen(path, O_RDONLY_FS, 0);
fd = ParamFileOpen(path, MODE_READ, 0);
PARAM_LOGI("LoadPersistParam open file %s", path);
}
PARAM_CHECK(fd >= 0, break, "No valid persist parameter file %s", path);
// read file
uint32_t fileSize = 0;
int ret = UtilsFileStat(path, &fileSize);
int ret = ParamFileStat(path, &fileSize);
PARAM_CHECK(ret == 0, break, "Failed to get file state %s", path);
buffer = malloc(fileSize);
PARAM_CHECK(buffer != NULL, break, "Failed to get file");
ret = UtilsFileRead(fd, buffer, fileSize);
ret = ParamFileRead(fd, buffer, fileSize);
PARAM_CHECK(ret == 0, break, "Failed to get read file %s", path);
uint32_t currLen = 0;
while (currLen < fileSize) {
if (buffer[currLen] == '\n') { // split line
buffer[currLen] = '\0';
int ret = SpliteString(buffer, NULL, 0, LoadOnePersistParam_, NULL);
int ret = SplitParamString(buffer, NULL, 0, LoadOnePersistParam_, NULL);
PARAM_CHECK(ret == 0, continue, "Failed to set param %d %s", ret, buffer);
paramNum++;
}
......@@ -73,30 +150,30 @@ static int LoadPersistParam(void)
}
} while (0);
if (fd > 0) {
UtilsFileClose(fd);
ParamFileClose(fd);
}
if (buffer != NULL) {
free(buffer);
}
PARAM_LOGI("LoadPersistParam from file %s paramNum %d", path, paramNum);
PARAM_LOGI("LoadPersistParam paramNum %d", paramNum);
return 0;
}
static int PersistWrite(int fd, const char *name, const char *value)
{
int ret = UtilsFileWrite(fd, name, strlen(name));
int ret = ParamFileWrite(fd, name, strlen(name));
if (ret <= 0) {
PARAM_LOGE("Failed to save persist param %s", name);
}
ret = UtilsFileWrite(fd, "=", strlen("="));
ret = ParamFileWrite(fd, "=", strlen("="));
if (ret <= 0) {
PARAM_LOGE("Failed to save persist param %s", name);
}
ret = UtilsFileWrite(fd, value, strlen(value));
ret = ParamFileWrite(fd, value, strlen(value));
if (ret <= 0) {
PARAM_LOGE("Failed to save persist param %s", name);
}
ret = UtilsFileWrite(fd, "\n", strlen("\n"));
ret = ParamFileWrite(fd, "\n", strlen("\n"));
if (ret <= 0) {
PARAM_LOGE("Failed to save persist param %s", name);
}
......@@ -107,10 +184,14 @@ static int SavePersistParam(const char *name, const char *value)
{
ParamMutexPend(&g_saveMutex);
int ret = -1;
int fd = UtilsFileOpen(PARAM_PERSIST_SAVE_PATH, O_RDWR_FS | O_CREAT_FS | O_APPEND_FS, 0);
int fd = ParamFileOpen(PARAM_PERSIST_SAVE_PATH, MODE_APPEND, 0);
if (fd > 0) {
ret = PersistWrite(fd, name, value);
UtilsFileClose(fd);
ParamFileSync(fd);
ParamFileClose(fd);
}
if (ret != 0) {
PARAM_LOGE("SavePersistParam %s errno %d", name, errno);
}
ParamMutexPost(&g_saveMutex);
return ret;
......@@ -119,10 +200,10 @@ static int SavePersistParam(const char *name, const char *value)
static int BatchSavePersistParamBegin(PERSIST_SAVE_HANDLE *handle)
{
ParamMutexPend(&g_saveMutex);
int fd = UtilsFileOpen(PARAM_PERSIST_SAVE_TMP_PATH, O_RDWR_FS | O_CREAT_FS | O_TRUNC_FS, 0);
int fd = ParamFileOpen(PARAM_PERSIST_SAVE_PATH, MODE_CREATE, 0);
if (fd < 0) {
ParamMutexPost(&g_saveMutex);
PARAM_LOGE("Open file %s fail error %d", PARAM_PERSIST_SAVE_TMP_PATH, errno);
PARAM_LOGE("Open file %s fail error %d", PARAM_PERSIST_SAVE_PATH, errno);
return -1;
}
*handle = (PERSIST_SAVE_HANDLE)fd;
......@@ -142,17 +223,15 @@ static void BatchSavePersistParamEnd(PERSIST_SAVE_HANDLE handle)
{
int ret;
int fd = (int)handle;
UtilsFileClose(fd);
UtilsFileDelete(PARAM_PERSIST_SAVE_PATH);
ret = UtilsFileMove(PARAM_PERSIST_SAVE_TMP_PATH, PARAM_PERSIST_SAVE_PATH);
ParamFileSync(fd);
ParamFileClose(fd);
ParamMutexPost(&g_saveMutex);
PARAM_CHECK(ret == 0, return, "BatchSavePersistParamEnd %s fail error %d", PARAM_PERSIST_SAVE_TMP_PATH, errno);
PARAM_CHECK(ret == 0, return, "BatchSavePersistParamEnd fail error %d", errno);
}
int RegisterPersistParamOps(PersistParamOps *ops)
{
PARAM_LOGI("RegisterPersistParamOps");
ParamMutexCeate(&g_saveMutex);
ParamMutexCreate(&g_saveMutex);
PARAM_CHECK(ops != NULL, return -1, "Invalid ops");
ops->save = SavePersistParam;
ops->load = LoadPersistParam;
......
......@@ -179,7 +179,7 @@ int ParamRWMutexDelete(ParamRWMutex *lock)
return 0;
}
int ParamMutexCeate(ParamMutex *mutex)
int ParamMutexCreate(ParamMutex *mutex)
{
PARAM_CHECK(mutex != NULL, return -1, "Invalid mutex");
pthread_mutexattr_t mutexattr;
......@@ -233,8 +233,6 @@ void FreeSharedMem(const MemHandle *handle, void *mem, uint32_t dataSize)
void paramMutexEnvInit(void)
{
uint32_t ret = OsMuxInit();
PARAM_CHECK(ret == LOS_OK, return, "Failed to init mutex ret %d", ret);
return;
}
......@@ -278,7 +276,7 @@ int ParamRWMutexDelete(ParamRWMutex *lock)
return 0;
}
int ParamMutexCeate(ParamMutex *mutex)
int ParamMutexCreate(ParamMutex *mutex)
{
PARAM_CHECK(mutex != NULL, return -1, "Invalid lock");
uint32_t ret = LOS_MuxCreate(&mutex->mutex);
......
......@@ -12,15 +12,54 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <errno.h>
#include <unistd.h>
#include "init_param.h"
#include "init_utils.h"
#include "param_manager.h"
#ifdef PARAM_LOAD_CFG_FROM_CODE
#include "param_cfg.h"
#endif
#ifdef __LITEOS_M__
#include "ohos_init.h"
#include "cmsis_os2.h"
#include "parameter.h"
#endif
static const char *StringTrim(char *buffer, int size, const char *name)
{
char *tmp = (char *)name;
while (*tmp != '\0' && *tmp != '"') {
tmp++;
}
if (*tmp == '\0') {
return name;
}
// skip "
tmp++;
int i = 0;
while (*tmp != '\0' && i < size) {
buffer[i++] = *tmp;
tmp++;
}
if (i >= size) {
return name;
}
while (i > 0) {
if (buffer[i] == '"') {
buffer[i] = '\0';
return buffer;
}
i--;
}
return name;
}
void InitParamService(void)
{
PARAM_LOGI("InitParamService");
CheckAndCreateDir(PARAM_STORAGE_PATH"/");
PARAM_LOGI("InitParamService %s", DATA_PATH);
CheckAndCreateDir(PARAM_STORAGE_PATH "/");
CheckAndCreateDir(DATA_PATH);
// param space
int ret = InitParamWorkSpace(0);
......@@ -30,6 +69,19 @@ void InitParamService(void)
// from build
LoadParamFromBuild();
#ifdef PARAM_LOAD_CFG_FROM_CODE
char *buffer = calloc(1, PARAM_VALUE_LEN_MAX);
PARAM_CHECK(buffer != NULL, return, "Failed to malloc for buffer");
for (size_t i = 0; i < ARRAY_LENGTH(g_paramDefCfgNodes); i++) {
PARAM_LOGV("InitParamService name %s = %s", g_paramDefCfgNodes[i].name, g_paramDefCfgNodes[i].value);
uint32_t dataIndex = 0;
ret = WriteParam(g_paramDefCfgNodes[i].name,
StringTrim(buffer, PARAM_VALUE_LEN_MAX, g_paramDefCfgNodes[i].value), &dataIndex, 0);
PARAM_CHECK(ret == 0, continue, "Failed to set param %d name %s %s",
ret, g_paramDefCfgNodes[i].name, g_paramDefCfgNodes[i].value);
}
free(buffer);
#endif
}
int StartParamService(void)
......@@ -61,3 +113,42 @@ int SystemWriteParam(const char *name, const char *value)
}
return ret;
}
#ifdef __LITEOS_M__
#define OS_DELAY 1000 // * 30 // 30s
#define STACK_SIZE 1024
static void ParamServiceTask(int *arg)
{
char buffer[10] = {0};
(void)arg;
PARAM_LOGI("ParamServiceTask start");
while (1) {
CheckAndSavePersistParam();
osDelay(OS_DELAY);
}
}
void LiteParamService(void)
{
EnableInitLog(INIT_INFO);
PARAM_LOGI("LiteParamService");
InitParamService();
// get persist param
LoadPersistParams();
osThreadAttr_t attr;
attr.name = "ParamServiceTask";
attr.attr_bits = 0U;
attr.cb_mem = NULL;
attr.cb_size = 0U;
attr.stack_mem = NULL;
attr.stack_size = 0;
attr.priority = osPriorityBelowNormal;
if (osThreadNew((osThreadFunc_t)ParamServiceTask, NULL, &attr) == NULL) {
PARAM_LOGE("Failed to create ParamServiceTask! %d", errno);
}
}
CORE_INIT(LiteParamService);
#endif
\ No newline at end of file
......@@ -35,7 +35,7 @@ static int IsNeedToSave(const char *name)
return (strncmp(name, PARAM_PERSIST_PREFIX, strlen(PARAM_PERSIST_PREFIX)) == 0) ? 1 : 0;
#endif
}
#ifdef PARAM_SUPPORT_CYCLE_CHECK
static long long GetPersistCommitId(void)
{
ParamWorkSpace *paramSpace = GetParamWorkSpace();
......@@ -50,7 +50,6 @@ static long long GetPersistCommitId(void)
PARAMSPACE_AREA_RW_UNLOCK(space);
return globalCommitId;
}
#endif
static void UpdatePersistCommitId(void)
{
......@@ -145,27 +144,32 @@ INIT_LOCAL_API void ClosePersistParamWorkSpace(void)
g_persistWorkSpace.flags = 0;
}
void CheckAndSavePersistParam(void)
{
// check commit
long long commit = GetPersistCommitId();
PARAM_LOGV("CheckAndSavePersistParam commit %lld %lld", commit, g_persistWorkSpace.commitId);
if (g_persistWorkSpace.commitId == commit) {
return;
}
g_persistWorkSpace.commitId = commit;
(void)BatchSavePersistParam();
}
PARAM_STATIC void TimerCallbackForSave(const ParamTaskPtr timer, void *context)
{
UNUSED(context);
UNUSED(timer);
// for liteos,we must cycle check
#ifndef PARAM_SUPPORT_CYCLE_CHECK
PARAM_LOGV("TimerCallbackForSave ");
// for liteos-a,we must cycle check
#if (!defined(PARAM_SUPPORT_CYCLE_CHECK) || defined(PARAM_SUPPORT_REAL_CHECK))
ParamTimerClose(g_persistWorkSpace.saveTimer);
g_persistWorkSpace.saveTimer = NULL;
if (!PARAM_TEST_FLAG(g_persistWorkSpace.flags, WORKSPACE_FLAGS_UPDATE)) {
return;
}
#else
// check commit
long long commit = GetPersistCommitId();
PARAM_LOGV("TimerCallbackForSave commit %lld %lld", commit, g_persistWorkSpace.commitId);
if (g_persistWorkSpace.commitId == commit) {
return;
}
g_persistWorkSpace.commitId = commit;
#endif
(void)BatchSavePersistParam();
CheckAndSavePersistParam();
}
INIT_LOCAL_API int WritePersistParam(const char *name, const char *value)
......@@ -180,7 +184,11 @@ INIT_LOCAL_API int WritePersistParam(const char *name, const char *value)
}
// update commit for check
UpdatePersistCommitId();
// for liteos-m, start task to check and save parameter
// for linux, start timer after set persist parameter
// for liteos-a, start timer in init to check and save parameter
#ifdef PARAM_SUPPORT_REAL_CHECK
PARAM_LOGI("WritePersistParam start check ");
if (!PARAM_TEST_FLAG(g_persistWorkSpace.flags, WORKSPACE_FLAGS_LOADED)) {
PARAM_LOGE("Can not save persist param before load %s ", name);
return 0;
......@@ -200,7 +208,7 @@ INIT_LOCAL_API int WritePersistParam(const char *name, const char *value)
}
return BatchSavePersistParam();
}
#ifndef PARAM_SUPPORT_CYCLE_CHECK
PARAM_SET_FLAG(g_persistWorkSpace.flags, WORKSPACE_FLAGS_UPDATE);
if (g_persistWorkSpace.saveTimer == NULL) {
ParamTimerCreate(&g_persistWorkSpace.saveTimer, TimerCallbackForSave, NULL);
......@@ -228,7 +236,9 @@ int LoadPersistParams(void)
// save new persist param
ret = BatchSavePersistParam();
PARAM_CHECK(ret == 0, return ret, "Failed to load persist param");
// for liteos-a, start time to check in init
#ifdef PARAM_SUPPORT_CYCLE_CHECK
PARAM_LOGV("LoadPersistParams start check time ");
if (g_persistWorkSpace.saveTimer == NULL) {
ParamTimerCreate(&g_persistWorkSpace.saveTimer, TimerCallbackForSave, NULL);
ParamTimerStart(g_persistWorkSpace.saveTimer, PARAM_MUST_SAVE_PARAM_DIFF * MS_UNIT, MS_UNIT);
......
......@@ -174,7 +174,7 @@ static int LoadDefaultParam_(const char *fileName, uint32_t mode, const char *ex
}
while (fgets(buffer, buffSize, fp) != NULL) {
buffer[buffSize - 1] = '\0';
int ret = SpliteString(buffer, exclude, count, LoadOneParam_, &mode);
int ret = SplitParamString(buffer, exclude, count, LoadOneParam_, &mode);
PARAM_CHECK(ret == 0, continue, "Failed to set param '%s' error:%d ", buffer, ret);
paramNum++;
}
......@@ -215,23 +215,34 @@ INIT_LOCAL_API void LoadParamFromBuild(void)
{
PARAM_LOGI("load parameters from build ");
#ifdef INCREMENTAL_VERSION
WriteParam("const.product.incremental.version", INCREMENTAL_VERSION, NULL, LOAD_PARAM_NORMAL);
if (strlen(INCREMENTAL_VERSION) > 0) {
WriteParam("const.product.incremental.version", INCREMENTAL_VERSION, NULL, LOAD_PARAM_NORMAL);
}
#endif
#ifdef BUILD_TYPE
WriteParam("const.product.build.type", BUILD_TYPE, NULL, LOAD_PARAM_NORMAL);
if (strlen(BUILD_TYPE) > 0) {
WriteParam("const.product.build.type", BUILD_TYPE, NULL, LOAD_PARAM_NORMAL);
}
#endif
#ifdef BUILD_USER
WriteParam("const.product.build.user", BUILD_USER, NULL, LOAD_PARAM_NORMAL);
if (strlen(BUILD_USER) > 0) {
WriteParam("const.product.build.user", BUILD_USER, NULL, LOAD_PARAM_NORMAL);
}
#endif
#ifdef BUILD_TIME
PARAM_LOGI("const.product.build.date %s", BUILD_TIME);
WriteParam("const.product.build.date", BUILD_TIME, NULL, LOAD_PARAM_NORMAL);
if (strlen(BUILD_TIME) > 0) {
WriteParam("const.product.build.date", BUILD_TIME, NULL, LOAD_PARAM_NORMAL);
}
#endif
#ifdef BUILD_HOST
WriteParam("const.product.build.host", BUILD_HOST, NULL, LOAD_PARAM_NORMAL);
if (strlen(BUILD_HOST) > 0) {
WriteParam("const.product.build.host", BUILD_HOST, NULL, LOAD_PARAM_NORMAL);
}
#endif
#ifdef BUILD_ROOTHASH
WriteParam("const.ohos.buildroothash", BUILD_ROOTHASH, NULL, LOAD_PARAM_NORMAL);
if (strlen(BUILD_ROOTHASH) > 0) {
WriteParam("const.ohos.buildroothash", BUILD_ROOTHASH, NULL, LOAD_PARAM_NORMAL);
}
#endif
}
......@@ -27,7 +27,10 @@ if (defined(ohos_lite)) {
"//base/startup/init_lite/interfaces/innerkits/include",
"//third_party/bounds_checking_function/include",
]
defines = [ "_GNU_SOURCE" ]
defines = [
"_GNU_SOURCE",
"OHOS_LITE",
]
}
} else {
import("//build/ohos.gni")
......
......@@ -496,12 +496,16 @@ int ReadFileInDir(const char *dirPath, const char *includeExt,
// Check if in updater mode.
int InUpdaterMode(void)
{
#ifdef OHOS_LITE
return 0;
#else
const char * const updaterExecutabeFile = "/bin/updater";
if (access(updaterExecutabeFile, X_OK) == 0) {
return 1;
} else {
return 0;
}
#endif
}
int StringReplaceChr(char *strl, char oldChr, char newChr)
......
......@@ -157,17 +157,13 @@ if (defined(ohos_lite)) {
defines += [ "__LITEOS_M__" ]
sources += [
"//base/startup/init_lite/services/param/liteos/param_client.c",
"//base/startup/init_lite/services/param/liteos/param_hal.c",
"//base/startup/init_lite/services/param/liteos/param_litedac.c",
"//base/startup/init_lite/services/param/liteos/param_osadp.c",
"//base/startup/init_lite/services/param/liteos/param_service.c",
]
if (enable_ohos_startup_init_lite_use_posix_file_api) {
sources += [
"//base/startup/init_lite/services/param/adapter/param_persistadp.c",
]
} else {
sources +=
[ "//base/startup/init_lite/services/param/liteos/param_hal.c" ]
defines += [ "PARAM_SUPPORT_POSIX" ]
}
sources += [
"../param/dac_unittest.cpp",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册