提交 30c3a96e 编写于 作者: M Mupceet

l1接口返回值适配

Signed-off-by: NMupceet <laiguizhong@huawei.com>
上级 093b3ac7
......@@ -50,11 +50,14 @@ INIT_LOCAL_API int GetParameter_(const char *key, const char *def, char *value,
}
uint32_t size = len;
int ret = SystemGetParameter(key, NULL, &size);
if (ret == PARAM_CODE_INVALID_NAME || ret == DAC_RESULT_FORBIDED || ret == PARAM_CODE_INVALID_PARAM) {
return EC_FAILURE;
}
if ((size > len) || (ret != 0)) {
return strcpy_s(value, len, def);
if (ret != 0) {
if (def == NULL || strlen(def) > len) {
return EC_INVALID;
}
ret = strcpy_s(value, len, def);
return (ret == 0) ? 0 : EC_FAILURE;
} else if (size > len) {
return EC_INVALID;
}
size = len;
return (SystemGetParameter(key, value, &size) == 0) ? EC_SUCCESS : EC_FAILURE;
......
......@@ -75,7 +75,7 @@ int GetParameter(const char *key, const char *def, char *value, uint32_t len)
return EC_INVALID;
}
int ret = GetParameter_(key, def, value, len);
return (ret != 0) ? EC_INVALID : strlen(value);
return (ret != 0) ? ret : strlen(value);
}
int GetIntParameter(const char *key, int def)
......@@ -99,6 +99,10 @@ int SetParameter(const char *key, const char *value)
return EC_INVALID;
}
int ret = SystemSetParameter(key, value);
if (ret == PARAM_CODE_INVALID_NAME || ret == DAC_RESULT_FORBIDED ||
ret == PARAM_CODE_INVALID_PARAM || ret == PARAM_CODE_INVALID_VALUE) {
return EC_INVALID;
}
return (ret == 0) ? EC_SUCCESS : EC_FAILURE;
}
......
......@@ -189,7 +189,8 @@ if (defined(ohos_lite)) {
deps = [
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/loopevent:loopevent",
"//base/startup/init_lite/services/param:parameter",
"//base/startup/init_lite/services/param/base:parameterbase",
"//base/startup/init_lite/services/param/linux:param_client",
"//base/startup/init_lite/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_static",
]
......
......@@ -409,5 +409,12 @@ INIT_LOCAL_API ParamTrieNode *FindTrieNode(WorkSpace *workSpace,
PARAMSPACE_AREA_RD_LOCK(workSpace);
node = FindTrieNode_(workSpace, key, keyLen, matchLabel);
PARAMSPACE_AREA_RW_UNLOCK(workSpace);
if (node != NULL && node->dataIndex != 0) {
ParamNode *entry = (ParamNode *)GetTrieNode(workSpace, node->dataIndex);
if (entry != NULL && entry->keyLength == keyLen) {
return node;
}
return NULL;
}
return node;
}
\ No newline at end of file
......@@ -115,7 +115,7 @@ HWTEST_F(SysparaUnitTest, parameterTest003, TestSize.Level0)
char key2[] = "rw.sys.version*%version";
char value2[] = "set value with illegal key";
int ret = SetParameter(key2, value2);
EXPECT_EQ(ret, EC_FAILURE);
EXPECT_EQ(ret, EC_INVALID);
}
/* key = 32 */
......@@ -134,7 +134,7 @@ HWTEST_F(SysparaUnitTest, parameterTest005, TestSize.Level0)
char value4[] = "rw.sys.version.version.version.version flash_offset = *(hi_u32 *)DT_SetGetU32(&g_Element[0], 0)a\
size = *(hi_u32 *)DT_SetGetU32(&g_Element[1], 0)a";
int ret = SetParameter(key4, value4);
EXPECT_EQ(ret, EC_FAILURE);
EXPECT_EQ(ret, EC_INVALID);
}
HWTEST_F(SysparaUnitTest, parameterTest006, TestSize.Level0)
......@@ -170,7 +170,7 @@ HWTEST_F(SysparaUnitTest, parameterTest009, TestSize.Level0)
char value5[] = "rw.sys.version.version.version.version \
flash_offset = *(hi_u32 *)DT_SetGetU32(&g_Element[0], 0)";
int ret = SetParameter(key5, value5);
EXPECT_EQ(ret, EC_FAILURE);
EXPECT_EQ(ret, EC_INVALID);
char valueGet[2] = {0};
char defValue3[] = "value of key > 32 ...";
ret = GetParameter(key5, defValue3, valueGet, 2);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册