mirror of
https://gitee.com/openharmony/startup_init
synced 2024-11-24 00:30:12 +00:00
系统参数归一,支持liteos
Signed-off-by: Mupceet <laiguizhong@huawei.com>
This commit is contained in:
parent
6c31bfdbd7
commit
13f6415f59
@ -12,11 +12,12 @@
|
||||
# limitations under the License.
|
||||
|
||||
declare_args() {
|
||||
param_feature_watcher = true
|
||||
param_feature_deviceinfo = true
|
||||
enable_ohos_startup_init_feature_watcher = true
|
||||
enable_ohos_startup_init_feature_deviceinfo = true
|
||||
param_test = true
|
||||
control_test = false
|
||||
param_begetctl_liteos_support = false
|
||||
# init begetctl support liteos
|
||||
enable_ohos_startup_init_feature_begetctl_liteos = false
|
||||
enable_ohos_startup_init_lite_use_thirdparty_mbedtls = true
|
||||
enable_ohos_startup_init_lite_use_posix_file_api = false
|
||||
config_ohos_startup_init_lite_data_path = ""
|
||||
|
@ -39,8 +39,7 @@
|
||||
"//base/startup/init_lite/services:startup_init",
|
||||
"//base/startup/init_lite/ueventd:startup_ueventd",
|
||||
"//base/startup/init_lite/watchdog:watchdog",
|
||||
"//base/startup/init_lite/services/begetctl:begetctl",
|
||||
"//base/startup/init_lite/services/begetctl:paramshell",
|
||||
"//base/startup/init_lite/services/begetctl:begetctl_cmd",
|
||||
"//base/startup/init_lite/services/modules:modules",
|
||||
"//base/startup/init_lite/interfaces/innerkits:libbegetutil",
|
||||
"//base/startup/init_lite/interfaces/kits/syscap:deviceinfo_ndk",
|
||||
|
@ -62,7 +62,7 @@ ohos_shared_library("deviceinfoservice") {
|
||||
}
|
||||
|
||||
group("device_info_group") {
|
||||
if (param_feature_deviceinfo) {
|
||||
if (enable_ohos_startup_init_feature_deviceinfo) {
|
||||
deps = [
|
||||
":device_info.cfg",
|
||||
":device_info_profile",
|
||||
|
@ -77,7 +77,6 @@ void DeviceInfoKits::DeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &rem
|
||||
|
||||
int32_t DeviceInfoKits::GetUdid(std::string& result)
|
||||
{
|
||||
printf("DeviceInfoKits::GetUdid \n");
|
||||
auto deviceService = GetService();
|
||||
DINFO_CHECK(deviceService != nullptr, return -1, "Failed to get watcher manager");
|
||||
return deviceService->GetUdid(result);
|
||||
|
@ -26,7 +26,6 @@ int32_t DeviceInfoProxy::GetUdid(std::string& result)
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option { MessageOption::TF_SYNC };
|
||||
printf("DeviceInfoProxy::GetUdid \n");
|
||||
data.WriteInterfaceToken(DeviceInfoProxy::GetDescriptor());
|
||||
int32_t ret = Remote()->SendRequest(COMMAND_GET_UDID, data, reply, option);
|
||||
DINFO_CHECK(ret == ERR_NONE, return ret, "getUdid failed, error code is %d", ret);
|
||||
|
@ -41,7 +41,9 @@ public:
|
||||
~DeviceInfoService() override {}
|
||||
virtual int32_t GetUdid(std::string& result) override;
|
||||
virtual int32_t GetSerialID(std::string& result) override;
|
||||
#ifndef STARTUP_INIT_TEST
|
||||
protected:
|
||||
#endif
|
||||
void OnStart() override;
|
||||
void OnStop() override;
|
||||
};
|
||||
|
51
interfaces/hals/hal_sys_param.h
Executable file
51
interfaces/hals/hal_sys_param.h
Executable file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef HAL_SYS_PARAM_H
|
||||
#define HAL_SYS_PARAM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
const char* HalGetDeviceType(void);
|
||||
const char* HalGetManufacture(void);
|
||||
const char* HalGetBrand(void);
|
||||
const char* HalGetMarketName(void);
|
||||
const char* HalGetProductSeries(void);
|
||||
const char* HalGetProductModel(void);
|
||||
const char* HalGetSoftwareModel(void);
|
||||
const char* HalGetHardwareModel(void);
|
||||
const char* HalGetHardwareProfile(void);
|
||||
const char* HalGetSerial(void);
|
||||
const char* HalGetBootloaderVersion(void);
|
||||
const char* HalGetAbiList(void);
|
||||
const char* HalGetDisplayVersion(void);
|
||||
const char* HalGetIncrementalVersion(void);
|
||||
const char* HalGetBuildType(void);
|
||||
const char* HalGetBuildUser(void);
|
||||
const char* HalGetBuildHost(void);
|
||||
const char* HalGetBuildTime(void);
|
||||
int HalGetFirstApiVersion(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif // HAL_SYS_PARAM_H
|
83
interfaces/hals/hal_token.h
Executable file
83
interfaces/hals/hal_token.h
Executable file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2020 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef HAL_TOKEN_H
|
||||
#define HAL_TOKEN_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define KIT_FRAMEWORK_UID_MAX 1000
|
||||
|
||||
/**
|
||||
* @brief Read token value from device.
|
||||
*
|
||||
* @param token the result token value, if read successfully.
|
||||
* @param len length of the token.
|
||||
* @returns 0 if success and get the update area token,
|
||||
* 1 if success and get the pre-made token,
|
||||
* -1 if failed,
|
||||
* -2 if no pre-made token.
|
||||
*/
|
||||
int HalReadToken(char *token, unsigned int len);
|
||||
|
||||
/**
|
||||
* @brief Write token value to device.
|
||||
*
|
||||
* @param token the token to write.
|
||||
* @param len length of the token.
|
||||
* @returns 0 if success, otherwise -1.
|
||||
*/
|
||||
int HalWriteToken(const char *token, unsigned int len);
|
||||
|
||||
/**
|
||||
* @brief Get AcKey value from device.
|
||||
*
|
||||
* @param acKey the result acKey, if get successfully.
|
||||
* @param len length of the acKey.
|
||||
* @returns 0 if success, otherwise -1.
|
||||
*/
|
||||
int HalGetAcKey(char *acKey, unsigned int len);
|
||||
|
||||
/**
|
||||
* @brief Get ProdId value from device.
|
||||
*
|
||||
* @param productId product IDs to be populated with.
|
||||
* @param len length of the productId.
|
||||
* @returns 0 if success, otherwise -1.
|
||||
*/
|
||||
int HalGetProdId(char *productId, unsigned int len);
|
||||
|
||||
/**
|
||||
* @brief Get ProdKey value from device.
|
||||
*
|
||||
* @param productKey The productKey value
|
||||
* @param len The productKey len.
|
||||
* @returns 0 if success, otherwise -1.
|
||||
*/
|
||||
int HalGetProdKey(char *productKey, unsigned int len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif // HAL_TOKEN_H
|
@ -11,7 +11,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import("//base/startup/init_lite/begetd.gni")
|
||||
if (!defined(ohos_lite) || ohos_kernel_type != "liteos_m") {
|
||||
if (!defined(ohos_lite) || enable_ohos_startup_init_feature_begetctl_liteos) {
|
||||
syspara_sources = [
|
||||
"syscap/init_syscap.c",
|
||||
"syspara/param_comm.c",
|
||||
@ -36,15 +36,20 @@ if (defined(ohos_lite)) {
|
||||
if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
|
||||
shared_library("libbegetutil") {
|
||||
sources = [ "//base/startup/init_lite/services/log/init_log.c" ]
|
||||
sources += syspara_sources
|
||||
|
||||
public_configs = [ ":exported_header_files" ]
|
||||
cflags = [ "-fPIC" ]
|
||||
defines = [
|
||||
"_GNU_SOURCE",
|
||||
"INIT_LOG_INIT=3",
|
||||
"OHOS_LITE",
|
||||
]
|
||||
if (enable_ohos_startup_init_feature_begetctl_liteos) {
|
||||
sources += syspara_sources
|
||||
defines += [ "LITEOS_SUPPORT" ]
|
||||
} else {
|
||||
sources += [ "syscap/init_syscap.c" ]
|
||||
}
|
||||
|
||||
public_configs = [ ":exported_header_files" ]
|
||||
cflags = [ "-fPIC" ]
|
||||
include_dirs = [
|
||||
"./include",
|
||||
"//base/hiviewdfx/hilog_lite/interfaces/native/kits",
|
||||
@ -56,21 +61,14 @@ if (defined(ohos_lite)) {
|
||||
"//base/startup/init_lite/interfaces/innerkits/include",
|
||||
]
|
||||
deps = [
|
||||
"$ohos_product_adapter_dir/utils/sys_param:hal_sysparam",
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
|
||||
"//base/startup/init_lite/services/utils:libinit_tools",
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
"//third_party/mbedtls:mbedtls",
|
||||
]
|
||||
|
||||
defines += [
|
||||
"INCREMENTAL_VERSION=\"${ohos_version}\"",
|
||||
"BUILD_TYPE=\"${ohos_build_type}\"",
|
||||
"BUILD_USER=\"${ohos_build_user}\"",
|
||||
"BUILD_TIME=\"${ohos_build_time}\"",
|
||||
"BUILD_HOST=\"${ohos_build_host}\"",
|
||||
"BUILD_ROOTHASH=\"${ohos_build_roothash}\"",
|
||||
"USE_MBEDTLS",
|
||||
]
|
||||
defines += [ "USE_MBEDTLS" ]
|
||||
deps += [ "//base/startup/init_lite/services/param:param_client" ]
|
||||
if (ohos_kernel_type == "liteos_a") {
|
||||
defines += [ "__LITEOS_A__" ]
|
||||
@ -83,7 +81,6 @@ if (defined(ohos_lite)) {
|
||||
if (ohos_kernel_type == "liteos_m") {
|
||||
static_library("libbegetutil") {
|
||||
sources = [ "//base/startup/init_lite/services/log/init_log.c" ]
|
||||
sources += [ "syscap/init_syscap.c" ]
|
||||
public_configs = [ ":exported_header_files" ]
|
||||
|
||||
defines = [
|
||||
@ -92,6 +89,7 @@ if (defined(ohos_lite)) {
|
||||
"OHOS_LITE",
|
||||
"__LITEOS_M__",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"./include",
|
||||
"//base/hiviewdfx/hilog_lite/interfaces/native/kits",
|
||||
@ -108,14 +106,14 @@ if (defined(ohos_lite)) {
|
||||
"//third_party/bounds_checking_function:libsec_static",
|
||||
]
|
||||
|
||||
defines += [
|
||||
"INCREMENTAL_VERSION=\"${ohos_version}\"",
|
||||
"BUILD_TYPE=\"${ohos_build_type}\"",
|
||||
"BUILD_USER=\"${ohos_build_user}\"",
|
||||
"BUILD_TIME=\"${ohos_build_time}\"",
|
||||
"BUILD_HOST=\"${ohos_build_host}\"",
|
||||
"BUILD_ROOTHASH=\"${ohos_build_roothash}\"",
|
||||
]
|
||||
if (enable_ohos_startup_init_feature_begetctl_liteos) {
|
||||
deps += [ "$ohos_product_adapter_dir/utils/sys_param:hal_sysparam" ]
|
||||
defines += [ "LITEOS_SUPPORT" ]
|
||||
sources += syspara_sources
|
||||
} else {
|
||||
sources += [ "syscap/init_syscap.c" ]
|
||||
}
|
||||
|
||||
if (enable_ohos_startup_init_lite_use_thirdparty_mbedtls) {
|
||||
deps += [ "//third_party/mbedtls:mbedtls" ]
|
||||
defines += [ "USE_MBEDTLS" ]
|
||||
@ -168,7 +166,6 @@ if (defined(ohos_lite)) {
|
||||
"INIT_AGENT",
|
||||
"INIT_FILE",
|
||||
"_GNU_SOURCE",
|
||||
"INIT_FILE",
|
||||
]
|
||||
if (target_cpu == "arm64") {
|
||||
defines += [ "SUPPORT_64BIT" ]
|
||||
@ -232,7 +229,7 @@ if (defined(ohos_lite)) {
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
]
|
||||
|
||||
if (param_feature_watcher) {
|
||||
if (enable_ohos_startup_init_feature_watcher) {
|
||||
sources += [
|
||||
"//base/startup/init_lite/services/param/watcher/agent/watcher.cpp",
|
||||
"//base/startup/init_lite/services/param/watcher/agent/watcher_manager_kits.cpp",
|
||||
@ -253,7 +250,7 @@ if (defined(ohos_lite)) {
|
||||
defines += [ "NO_PARAM_WATCHER" ]
|
||||
}
|
||||
|
||||
if (param_feature_deviceinfo) {
|
||||
if (enable_ohos_startup_init_feature_deviceinfo) {
|
||||
sources += [
|
||||
"//base/startup/init_lite/device_info/device_info_kits.cpp",
|
||||
"//base/startup/init_lite/device_info/device_info_proxy.cpp",
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
#ifndef STARTUP_SYSPARAM_PARAMETER_API_H
|
||||
#define STARTUP_SYSPARAM_PARAMETER_API_H
|
||||
|
||||
#include <stdint.h>
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
@ -49,7 +49,7 @@ static const char EMPTY_STR[] = { "" };
|
||||
* @since 1
|
||||
* @version 1
|
||||
*/
|
||||
int GetParameter(const char *key, const char *def, char *value, unsigned int len);
|
||||
int GetParameter(const char *key, const char *def, char *value, uint32_t len);
|
||||
|
||||
/**
|
||||
* @brief Sets or updates a system parameter.
|
||||
@ -148,10 +148,10 @@ int AclGetDevUdid(char *udid, int size);
|
||||
* @since 1
|
||||
* @version 1
|
||||
*/
|
||||
unsigned int FindParameter(const char *key);
|
||||
unsigned int GetParameterCommitId(unsigned int handle);
|
||||
int GetParameterName(unsigned int handle, char *key, unsigned int len);
|
||||
int GetParameterValue(unsigned int handle, char *value, unsigned int len);
|
||||
uint32_t FindParameter(const char *key);
|
||||
uint32_t GetParameterCommitId(uint32_t handle);
|
||||
int GetParameterName(uint32_t handle, char *key, uint32_t len);
|
||||
int GetParameterValue(uint32_t handle, char *value, uint32_t len);
|
||||
long long GetSystemCommitId(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
static const char *g_emptyStr = "";
|
||||
|
||||
int IsValidValue(const char *value, unsigned int len)
|
||||
INIT_LOCAL_API int IsValidParamValue(const char *value, uint32_t len)
|
||||
{
|
||||
if ((value == NULL) || (strlen(value) + 1 > len)) {
|
||||
return 0;
|
||||
@ -39,7 +39,7 @@ int IsValidValue(const char *value, unsigned int len)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int HalGetParameter(const char *key, const char *def, char *value, uint32_t len)
|
||||
INIT_LOCAL_API int GetParameter_(const char *key, const char *def, char *value, uint32_t len)
|
||||
{
|
||||
if ((key == NULL) || (value == NULL)) {
|
||||
return EC_INVALID;
|
||||
@ -53,7 +53,7 @@ int HalGetParameter(const char *key, const char *def, char *value, uint32_t len)
|
||||
return (SystemGetParameter(key, value, &size) == 0) ? EC_SUCCESS : EC_FAILURE;
|
||||
}
|
||||
|
||||
const char *GetProperty(const char *key, const char **paramHolder)
|
||||
INIT_LOCAL_API const char *GetProperty(const char *key, const char **paramHolder)
|
||||
{
|
||||
if (paramHolder == NULL) {
|
||||
return NULL;
|
||||
@ -78,7 +78,7 @@ const char *GetProperty(const char *key, const char **paramHolder)
|
||||
return *paramHolder;
|
||||
}
|
||||
|
||||
int StringToLL(const char *str, long long int *out)
|
||||
INIT_LOCAL_API int StringToLL(const char *str, long long int *out)
|
||||
{
|
||||
const char* s = str;
|
||||
while (isspace(*s)) {
|
||||
@ -101,7 +101,7 @@ int StringToLL(const char *str, long long int *out)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int StringToULL(const char *str, unsigned long long int *out)
|
||||
INIT_LOCAL_API int StringToULL(const char *str, unsigned long long int *out)
|
||||
{
|
||||
const char* s = str;
|
||||
while (isspace(*s)) {
|
||||
@ -128,13 +128,13 @@ int StringToULL(const char *str, unsigned long long int *out)
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *GetProductModel_(void)
|
||||
INIT_LOCAL_API const char *GetProductModel_(void)
|
||||
{
|
||||
static const char *productModel = NULL;
|
||||
return GetProperty("const.product.model", &productModel);
|
||||
}
|
||||
|
||||
const char *GetManufacture_(void)
|
||||
INIT_LOCAL_API const char *GetManufacture_(void)
|
||||
{
|
||||
static const char *productManufacture = NULL;
|
||||
return GetProperty("const.product.manufacturer", &productManufacture);
|
||||
@ -193,14 +193,22 @@ static int GetSha256Value(const char *input, char *udid, int udidSize)
|
||||
}
|
||||
#endif
|
||||
|
||||
const char *GetSerial_(void)
|
||||
INIT_LOCAL_API const char *GetSerial_(void)
|
||||
{
|
||||
const char *serialNumberss = NULL;
|
||||
GetProperty("ohos.boot.sn", &serialNumberss);
|
||||
return serialNumberss;
|
||||
#ifdef LITEOS_SUPPORT
|
||||
return HalGetSerial();
|
||||
#else
|
||||
static char ohos_serial[PARAM_VALUE_LEN_MAX] = {0};
|
||||
uint32_t len = PARAM_VALUE_LEN_MAX;
|
||||
int ret = SystemGetParameter("ohos.boot.sn", ohos_serial, &len);
|
||||
if (ret != 0) {
|
||||
return NULL;
|
||||
}
|
||||
return ohos_serial;
|
||||
#endif
|
||||
}
|
||||
|
||||
int GetDevUdid_(char *udid, int size)
|
||||
INIT_LOCAL_API int GetDevUdid_(char *udid, int size)
|
||||
{
|
||||
if (size < UDID_LEN || udid == NULL) {
|
||||
return EC_FAILURE;
|
||||
@ -213,12 +221,10 @@ int GetDevUdid_(char *udid, int size)
|
||||
}
|
||||
int tmpSize = strlen(manufacture) + strlen(model) + strlen(sn) + 1;
|
||||
if (tmpSize <= 0 || tmpSize > DEV_BUF_MAX_LENGTH) {
|
||||
free((void *)sn);
|
||||
return -1;
|
||||
}
|
||||
char *tmp = (char *)malloc(tmpSize);
|
||||
if (tmp == NULL) {
|
||||
free((void *)sn);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -226,12 +232,16 @@ int GetDevUdid_(char *udid, int size)
|
||||
if ((strcat_s(tmp, tmpSize, manufacture) != 0) || (strcat_s(tmp, tmpSize, model) != 0) ||
|
||||
(strcat_s(tmp, tmpSize, sn) != 0)) {
|
||||
free(tmp);
|
||||
free((void *)sn);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = GetSha256Value(tmp, udid, size);
|
||||
free(tmp);
|
||||
free((void *)sn);
|
||||
return ret;
|
||||
}
|
||||
|
||||
INIT_LOCAL_API const char *GetFullName_(void)
|
||||
{
|
||||
static const char *fillname = NULL;
|
||||
return GetProperty("const.ohos.fullname", &fillname);
|
||||
}
|
@ -15,6 +15,9 @@
|
||||
|
||||
#ifndef INIT_PARAM_COMM_H
|
||||
#define INIT_PARAM_COMM_H
|
||||
#include <stdint.h>
|
||||
#include "beget_ext.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
@ -29,18 +32,19 @@ extern "C" {
|
||||
#define DECIMAL 10
|
||||
#define HEX 16
|
||||
|
||||
const char *GetProperty(const char *key, const char **paramHolder);
|
||||
INIT_LOCAL_API const char *GetProperty(const char *key, const char **paramHolder);
|
||||
|
||||
int StringToULL(const char *str, unsigned long long int *out);
|
||||
int StringToLL(const char *str, long long int *out);
|
||||
int HalGetParameter(const char *key, const char *def, char *value, unsigned int len);
|
||||
INIT_LOCAL_API int StringToULL(const char *str, unsigned long long int *out);
|
||||
INIT_LOCAL_API int StringToLL(const char *str, long long int *out);
|
||||
INIT_LOCAL_API int GetParameter_(const char *key, const char *def, char *value, uint32_t len);
|
||||
|
||||
const char *GetProductModel_(void);
|
||||
const char *GetManufacture_(void);
|
||||
const char *GetSerial_(void);
|
||||
int GetDevUdid_(char *udid, int size);
|
||||
int IsValidValue(const char *value, unsigned int len);
|
||||
INIT_LOCAL_API const char *GetProductModel_(void);
|
||||
INIT_LOCAL_API const char *GetManufacture_(void);
|
||||
INIT_LOCAL_API const char *GetSerial_(void);
|
||||
INIT_LOCAL_API int GetDevUdid_(char *udid, int size);
|
||||
INIT_LOCAL_API int IsValidParamValue(const char *value, uint32_t len);
|
||||
|
||||
INIT_LOCAL_API const char *GetFullName_(void);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <vector>
|
||||
#include <climits>
|
||||
|
||||
#include "beget_ext.h"
|
||||
#include "param_comm.h"
|
||||
#include "init_param.h"
|
||||
#include "sysparam_errno.h"
|
||||
@ -73,7 +74,7 @@ std::string GetParameter(const std::string& key, const std::string& def)
|
||||
return std::string(value.data());
|
||||
}
|
||||
}
|
||||
if (IsValidValue(def.c_str(), MAX_VALUE_LEN) == 1) {
|
||||
if (IsValidParamValue(def.c_str(), MAX_VALUE_LEN) == 1) {
|
||||
return std::string(def);
|
||||
}
|
||||
return "";
|
||||
@ -109,7 +110,7 @@ int GetStringParameter(const std::string key, std::string &value, const std::str
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
}
|
||||
if (IsValidValue(def.c_str(), MAX_VALUE_LEN) == 1) {
|
||||
if (IsValidParamValue(def.c_str(), MAX_VALUE_LEN) == 1) {
|
||||
value = std::string(def);
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ int GetParameter(const char *key, const char *def, char *value, uint32_t len)
|
||||
if ((key == NULL) || (value == NULL)) {
|
||||
return EC_INVALID;
|
||||
}
|
||||
int ret = HalGetParameter(key, def, value, len);
|
||||
int ret = GetParameter_(key, def, value, len);
|
||||
return (ret != 0) ? EC_INVALID : strlen(value);
|
||||
}
|
||||
|
||||
@ -193,13 +193,13 @@ const char *GetIncrementalVersion(void)
|
||||
return GetProperty("const.product.incremental.version", &incrementalVersion);
|
||||
}
|
||||
|
||||
const char *HalGetOsReleaseType(void)
|
||||
const char *GetOsReleaseType(void)
|
||||
{
|
||||
static const char *osReleaseType = NULL;
|
||||
return GetProperty("const.ohos.releasetype", &osReleaseType);
|
||||
}
|
||||
|
||||
const char *HalGetSdkApiVersion(void)
|
||||
static const char *GetSdkApiVersion_(void)
|
||||
{
|
||||
static const char *sdkApiVersion = NULL;
|
||||
return GetProperty("const.ohos.apiversion", &sdkApiVersion);
|
||||
@ -231,13 +231,7 @@ const char *GetBuildTime(void)
|
||||
|
||||
const char *GetSerial(void)
|
||||
{
|
||||
static char ohos_serial[PARAM_VALUE_LEN_MAX] = {0};
|
||||
uint32_t len = PARAM_VALUE_LEN_MAX;
|
||||
int ret = SystemGetParameter("ohos.boot.sn", ohos_serial, &len);
|
||||
if (ret != 0) {
|
||||
return NULL;
|
||||
}
|
||||
return ohos_serial;
|
||||
return GetSerial_();
|
||||
}
|
||||
|
||||
int GetDevUdid(char *udid, int size)
|
||||
@ -245,27 +239,17 @@ int GetDevUdid(char *udid, int size)
|
||||
return GetDevUdid_(udid, size);
|
||||
}
|
||||
|
||||
static const char *GetOSName(void)
|
||||
{
|
||||
static const char *osName = NULL;
|
||||
return GetProperty("const.ohos.name", &osName);
|
||||
}
|
||||
|
||||
static const char *BuildOSFullName(void)
|
||||
{
|
||||
const char release[] = "Release";
|
||||
char value[OS_FULL_NAME_LEN] = {0};
|
||||
const char *releaseType = GetOsReleaseType();
|
||||
int length;
|
||||
if ((releaseType == NULL) || (strncmp(releaseType, release, sizeof(release) - 1) == 0)) {
|
||||
length = sprintf_s(value, OS_FULL_NAME_LEN, "%s-%d.%d.%d.%d",
|
||||
GetOSName(), GetMajorVersion(), GetSeniorVersion(), GetFeatureVersion(), GetBuildVersion());
|
||||
} else {
|
||||
length = sprintf_s(value, OS_FULL_NAME_LEN, "%s-%d.%d.%d.%d(%s)",
|
||||
GetOSName(), GetMajorVersion(), GetSeniorVersion(), GetFeatureVersion(), GetBuildVersion(), releaseType);
|
||||
}
|
||||
if (length < 0) {
|
||||
return EMPTY_STR;
|
||||
const char *fillname = GetFullName_();
|
||||
if ((releaseType != NULL) && (strncmp(releaseType, release, sizeof(release) - 1) != 0)) {
|
||||
int length = sprintf_s(value, OS_FULL_NAME_LEN, "%s(%s)", fillname, releaseType);
|
||||
if (length < 0) {
|
||||
return EMPTY_STR;
|
||||
}
|
||||
}
|
||||
const char *osFullName = strdup(value);
|
||||
return osFullName;
|
||||
@ -284,24 +268,14 @@ const char *GetOSFullName(void)
|
||||
return osFullName;
|
||||
}
|
||||
|
||||
static int GetSdkApiLevel(void)
|
||||
{
|
||||
static const char *sdkApiLevel = NULL;
|
||||
GetProperty("const.ohos.sdkapilevel", &sdkApiLevel);
|
||||
if (sdkApiLevel == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return atoi(sdkApiLevel);
|
||||
}
|
||||
|
||||
static const char *BuildVersionId(void)
|
||||
{
|
||||
char value[VERSION_ID_MAX_LEN] = {0};
|
||||
|
||||
int len = sprintf_s(value, VERSION_ID_MAX_LEN, "%s/%s/%s/%s/%s/%s/%s/%d/%s/%s",
|
||||
int len = sprintf_s(value, VERSION_ID_MAX_LEN, "%s/%s/%s/%s/%s/%s/%s/%s/%s/%s",
|
||||
GetDeviceType(), GetManufacture(), GetBrand(), GetProductSeries(),
|
||||
GetOSFullName(), GetProductModel(), GetSoftwareModel(),
|
||||
GetSdkApiLevel(), GetIncrementalVersion(), GetBuildType());
|
||||
GetSdkApiVersion_(), GetIncrementalVersion(), GetBuildType());
|
||||
if (len <= 0) {
|
||||
return EMPTY_STR;
|
||||
}
|
||||
@ -322,12 +296,6 @@ const char *GetVersionId(void)
|
||||
return ohosVersionId;
|
||||
}
|
||||
|
||||
const char *GetOsReleaseType(void)
|
||||
{
|
||||
static const char *osReleaseType = NULL;
|
||||
return GetProperty("const.ohos.releasetype", &osReleaseType);
|
||||
}
|
||||
|
||||
int GetSdkApiVersion(void)
|
||||
{
|
||||
static const char *sdkApiVersion = NULL;
|
||||
|
@ -14,6 +14,15 @@
|
||||
*/
|
||||
#include "sysversion.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "beget_ext.h"
|
||||
#include "param_comm.h"
|
||||
#include "parameter.h"
|
||||
#include "securec.h"
|
||||
|
||||
/* *
|
||||
* Major(M) version number.
|
||||
*/
|
||||
@ -34,6 +43,26 @@ static int g_featureVersion = 0;
|
||||
*/
|
||||
static int g_buildVersion = 0;
|
||||
|
||||
static void GetVersions(void)
|
||||
{
|
||||
static int versionInited = 0;
|
||||
if (versionInited) {
|
||||
return;
|
||||
}
|
||||
const char *fullName = GetFullName_();
|
||||
const char *tmp = strstr(fullName, "-");
|
||||
if (tmp == NULL) {
|
||||
return;
|
||||
}
|
||||
tmp++; // skip "-"
|
||||
int ret = sscanf_s(tmp, "%d.%d.%d.%d", &g_majorVersion, &g_seniorVersion, &g_featureVersion, &g_buildVersion);
|
||||
BEGET_LOGV("fullName %s %d.%d.%d.%d ret %d",
|
||||
fullName, g_majorVersion, g_seniorVersion, g_featureVersion, g_buildVersion, ret);
|
||||
if (ret == 4) { // 4 parameters
|
||||
versionInited = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* *
|
||||
* Obtains the major (M) version number, which increases with any updates to the overall architecture.
|
||||
* <p>The M version number monotonically increases from 1 to 99.
|
||||
@ -43,6 +72,7 @@ static int g_buildVersion = 0;
|
||||
*/
|
||||
int GetMajorVersion(void)
|
||||
{
|
||||
GetVersions();
|
||||
return g_majorVersion;
|
||||
}
|
||||
|
||||
@ -56,6 +86,7 @@ int GetMajorVersion(void)
|
||||
*/
|
||||
int GetSeniorVersion(void)
|
||||
{
|
||||
GetVersions();
|
||||
return g_seniorVersion;
|
||||
}
|
||||
|
||||
@ -68,6 +99,7 @@ int GetSeniorVersion(void)
|
||||
*/
|
||||
int GetFeatureVersion(void)
|
||||
{
|
||||
GetVersions();
|
||||
return g_featureVersion;
|
||||
}
|
||||
|
||||
@ -80,5 +112,6 @@ int GetFeatureVersion(void)
|
||||
*/
|
||||
int GetBuildVersion(void)
|
||||
{
|
||||
GetVersions();
|
||||
return g_buildVersion;
|
||||
}
|
@ -12,6 +12,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
import("//base/startup/init_lite/begetd.gni")
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
import("//build/lite/ndk/ndk.gni")
|
||||
|
||||
@ -49,24 +50,29 @@ if (ohos_kernel_type == "liteos_m") {
|
||||
}
|
||||
}
|
||||
|
||||
lite_component("token") {
|
||||
lite_component("inittoken") {
|
||||
features = []
|
||||
if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
|
||||
features += [ ":token_shared" ]
|
||||
}
|
||||
if (ohos_kernel_type == "liteos_m") {
|
||||
features += [ ":token_static" ]
|
||||
if (enable_ohos_startup_init_feature_begetctl_liteos) {
|
||||
if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
|
||||
features += [ ":token_shared" ]
|
||||
}
|
||||
if (ohos_kernel_type == "liteos_m") {
|
||||
features += [ ":token_static" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ndk_lib("token_notes1") {
|
||||
if (ohos_kernel_type != "liteos_m") {
|
||||
lib_extension = ".so"
|
||||
}
|
||||
ndk_lib("inittoken_notes") {
|
||||
deps = []
|
||||
if (ohos_kernel_type != "liteos_m") {
|
||||
deps +=
|
||||
[ "//base/startup/init_lite/interfaces/innerkits/token:token_shared" ]
|
||||
head_files = []
|
||||
if (enable_ohos_startup_init_feature_begetctl_liteos) {
|
||||
if (ohos_kernel_type != "liteos_m") {
|
||||
lib_extension = ".so"
|
||||
}
|
||||
if (ohos_kernel_type != "liteos_m") {
|
||||
deps +=
|
||||
[ "//base/startup/init_lite/interfaces/innerkits/token:token_shared" ]
|
||||
}
|
||||
head_files += [ "//base/startup/init_lite/interfaces/include/token" ]
|
||||
}
|
||||
head_files = [ "//base/startup/init_lite/interfaces/include/token" ]
|
||||
}
|
||||
|
@ -34,10 +34,10 @@ def GetParamFromCfg(cfgName):
|
||||
dict = {}
|
||||
with open(cfgName) as afile:
|
||||
data = afile.readline()
|
||||
while data:
|
||||
while data:
|
||||
name, value = DecodeCfgLine(data)
|
||||
if len(name) != 0 and len(value) != 0:
|
||||
dict[name] = value
|
||||
dict[name] = value
|
||||
print("sample file name={%s %s}"%(name, value))
|
||||
data = afile.readline()
|
||||
return dict
|
||||
@ -46,29 +46,29 @@ def DecodeCodeLine(data):
|
||||
data.replace('\n', '').replace('\r', '')
|
||||
data = data.strip()
|
||||
if (not data.startswith("PARAM_MAP")):
|
||||
return "", ""
|
||||
dataLen = len(data)
|
||||
return "", ""
|
||||
dataLen = len(data)
|
||||
data = data[len("PARAM_MAP") + 1 : dataLen - 1]
|
||||
data = data.strip()
|
||||
strs = data.split(',')
|
||||
if len(strs) <= 1:
|
||||
return "", ""
|
||||
return strs[0].strip(), strs[1].strip()
|
||||
return strs[0].strip(), data[len(strs[0]) + 1: ].strip()
|
||||
|
||||
def GetParamFromCCode(codeName):
|
||||
dict = {}
|
||||
with open(codeName) as afile:
|
||||
with open(codeName, "r+") as afile:
|
||||
data = afile.readline()
|
||||
while data:
|
||||
while data:
|
||||
name, value = DecodeCodeLine(data)
|
||||
if len(name) != 0 and len(value) != 0:
|
||||
dict[name] = value
|
||||
dict[name] = value
|
||||
data = afile.readline()
|
||||
return dict
|
||||
|
||||
def WriteMapToCode(codeName, dict):
|
||||
try:
|
||||
f = open(codeName, 'w+')
|
||||
f = open(codeName, 'w')
|
||||
# write file header
|
||||
f.write('#ifndef PARAM_LITE_DEF_CFG_' + os.linesep)
|
||||
f.write('#define PARAM_LITE_DEF_CFG_' + os.linesep)
|
||||
@ -89,8 +89,12 @@ def WriteMapToCode(codeName, dict):
|
||||
# write data
|
||||
f.write('static Node g_paramDefCfgNodes[] = {' + os.linesep)
|
||||
for name, value in dict.items():
|
||||
str = " PARAM_MAP({0}, {1})".format(name, value)
|
||||
f.write(str + os.linesep)
|
||||
if (value.startswith("\"")):
|
||||
str = " PARAM_MAP({0}, {1})".format(name, value)
|
||||
f.write(str + os.linesep)
|
||||
else:
|
||||
str = " PARAM_MAP({0}, \"{1}\")".format(name, value)
|
||||
f.write(str + os.linesep)
|
||||
f.write('};' + os.linesep + os.linesep)
|
||||
|
||||
#end
|
||||
@ -103,7 +107,7 @@ def WriteMapToCode(codeName, dict):
|
||||
except IOError:
|
||||
print("Error: open or write file %s fail"%{codeName})
|
||||
else:
|
||||
f.close()
|
||||
f.close()
|
||||
return 0
|
||||
|
||||
def AddToCodeDict(codeDict, cfgDict, high = True):
|
||||
@ -115,7 +119,7 @@ def AddToCodeDict(codeDict, cfgDict, high = True):
|
||||
elif not hasKey:
|
||||
codeDict[name] = value
|
||||
return codeDict
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='A common change param.para file to h.')
|
||||
@ -142,12 +146,14 @@ def main():
|
||||
assert os.path.exists(source)
|
||||
|
||||
srcDict = GetParamFromCfg(source)
|
||||
dst = out_dir + "param_cfg.h"
|
||||
dst = out_dir + "param_cfg.h"
|
||||
|
||||
if os.path.exists(dst):
|
||||
dstDict = GetParamFromCCode(dst)
|
||||
else:
|
||||
dstDict = {}
|
||||
dstDict = AddToCodeDict(dstDict, srcDict, True)
|
||||
|
||||
dstDict = AddToCodeDict(dstDict, srcDict, args.priority == "1")
|
||||
WriteMapToCode(dst, dstDict)
|
||||
return 0
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import("//base/startup/init_lite/begetd.gni")
|
||||
|
||||
init_common_sources = [
|
||||
"init/init_capability.c",
|
||||
@ -32,6 +33,9 @@ if (defined(ohos_lite)) {
|
||||
"OHOS_LITE",
|
||||
"__MUSL__",
|
||||
]
|
||||
if (enable_ohos_startup_init_feature_begetctl_liteos) {
|
||||
defines += [ "LITEOS_SUPPORT" ]
|
||||
}
|
||||
sources = [
|
||||
"init/adapter/init_adapter.c",
|
||||
"init/lite/init.c",
|
||||
@ -94,20 +98,20 @@ if (defined(ohos_lite)) {
|
||||
}
|
||||
}
|
||||
|
||||
if (ohos_build_type == "debug") {
|
||||
group("unittest") {
|
||||
group("init_lite") {
|
||||
if (ohos_kernel_type != "liteos_m") {
|
||||
deps = [
|
||||
":lite_init",
|
||||
"etc:etc_files",
|
||||
]
|
||||
}
|
||||
}
|
||||
group("unittest") {
|
||||
if (ohos_build_type == "debug" && ohos_kernel_type != "liteos_m") {
|
||||
deps = [ "//base/startup/init_lite/test/unittest/lite:init_test" ]
|
||||
}
|
||||
}
|
||||
|
||||
group("init_lite") {
|
||||
deps = [
|
||||
":lite_init",
|
||||
"etc:etc_files",
|
||||
]
|
||||
}
|
||||
} else {
|
||||
import("//base/startup/init_lite/begetd.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/ohos/native_stub/native_stub.gni")
|
||||
|
||||
@ -241,7 +245,7 @@ if (defined(ohos_lite)) {
|
||||
"//base/startup/init_lite/services/param:param_client",
|
||||
"//base/startup/init_lite/services/param:param_init",
|
||||
]
|
||||
if (param_feature_watcher) {
|
||||
if (enable_ohos_startup_init_feature_watcher) {
|
||||
deps += [
|
||||
"//base/startup/init_lite/services/param/watcher:param_watcher",
|
||||
"//base/startup/init_lite/services/param/watcher:param_watcher.rc",
|
||||
|
@ -23,7 +23,11 @@ if (defined(ohos_lite)) {
|
||||
defines = [
|
||||
"_GNU_SOURCE", #syscall function need this macro definition
|
||||
"__MUSL__",
|
||||
"OHOS_LITE",
|
||||
]
|
||||
if (param_test) {
|
||||
sources += [ "//base/startup/init_lite/test/moduletest/syspara.cpp" ]
|
||||
}
|
||||
include_dirs = [
|
||||
".",
|
||||
"shell",
|
||||
@ -46,7 +50,8 @@ if (defined(ohos_lite)) {
|
||||
]
|
||||
}
|
||||
group("begetctl_cmd") {
|
||||
if (param_begetctl_liteos_support) {
|
||||
if (enable_ohos_startup_init_feature_begetctl_liteos &&
|
||||
ohos_kernel_type != "liteos_m") {
|
||||
deps = [ ":begetctl" ]
|
||||
}
|
||||
}
|
||||
@ -86,21 +91,16 @@ if (defined(ohos_lite)) {
|
||||
deps = [
|
||||
"//base/startup/init_lite/interfaces/innerkits:libbegetutil",
|
||||
"//base/startup/init_lite/interfaces/innerkits/sandbox:libsandbox",
|
||||
"//base/startup/init_lite/services/log:agent_log",
|
||||
"//base/startup/init_lite/services/param:param_client",
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
]
|
||||
external_deps = [ "utils_base:utils" ]
|
||||
|
||||
if (param_test) {
|
||||
sources +=
|
||||
[ "//base/startup/init_lite/test/moduletest/param_test_cmds.c" ]
|
||||
deps += [
|
||||
"//base/startup/init_lite/interfaces/innerkits:libbeget_proxy",
|
||||
"//base/startup/init_lite/services/loopevent:loopevent",
|
||||
"//base/startup/init_lite/services/utils:libinit_tools",
|
||||
"//base/startup/init_lite/services/utils:libinit_utils",
|
||||
sources += [
|
||||
"//base/startup/init_lite/test/moduletest/param_test_cmds.c",
|
||||
"//base/startup/init_lite/test/moduletest/syspara.cpp",
|
||||
]
|
||||
deps += [ "//base/startup/init_lite/interfaces/innerkits:libbeget_proxy" ]
|
||||
defines += [
|
||||
"OHOS_SERVICE_DUMP",
|
||||
"INIT_TEST",
|
||||
@ -126,7 +126,6 @@ if (defined(ohos_lite)) {
|
||||
"start_service",
|
||||
"stop_service",
|
||||
"service",
|
||||
"param",
|
||||
"sandbox",
|
||||
]
|
||||
|
||||
@ -158,8 +157,6 @@ if (defined(ohos_lite)) {
|
||||
]
|
||||
deps = [
|
||||
"//base/startup/init_lite/interfaces/innerkits:libbegetutil",
|
||||
"//base/startup/init_lite/services/log:agent_log",
|
||||
"//base/startup/init_lite/services/param:param_client",
|
||||
"//third_party/bounds_checking_function:libsec_static",
|
||||
]
|
||||
|
||||
@ -170,8 +167,10 @@ if (defined(ohos_lite)) {
|
||||
}
|
||||
|
||||
if (param_test) {
|
||||
sources +=
|
||||
[ "//base/startup/init_lite/test/moduletest/param_test_cmds.c" ]
|
||||
sources += [
|
||||
"//base/startup/init_lite/test/moduletest/param_test_cmds.c",
|
||||
"//base/startup/init_lite/test/moduletest/syspara.cpp",
|
||||
]
|
||||
deps += [
|
||||
"//base/startup/init_lite/interfaces/innerkits:libbeget_proxy",
|
||||
"//base/startup/init_lite/services/loopevent:loopevent",
|
||||
@ -189,4 +188,59 @@ if (defined(ohos_lite)) {
|
||||
|
||||
part_name = "init"
|
||||
}
|
||||
|
||||
ohos_executable("param") {
|
||||
sources = [
|
||||
"main.c",
|
||||
"param_cmd.c",
|
||||
"shell/shell_bas.c",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"INIT_AGENT",
|
||||
"INIT_FILE",
|
||||
"_GNU_SOURCE",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
".",
|
||||
"shell",
|
||||
"//base/startup/init_lite/services/include",
|
||||
"//base/startup/init_lite/services/log",
|
||||
"//base/startup/init_lite/interfaces/innerkits/include",
|
||||
"//base/startup/init_lite/services/include/param/",
|
||||
"//base/startup/init_lite/services/loopevent/include",
|
||||
"//base/startup/init_lite/services/param/include",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
deps = [
|
||||
"//base/startup/init_lite/services/log:agent_log",
|
||||
"//base/startup/init_lite/services/loopevent:loopevent",
|
||||
"//base/startup/init_lite/services/param:param_client",
|
||||
"//base/startup/init_lite/services/utils:libinit_tools",
|
||||
"//base/startup/init_lite/services/utils:libinit_utils",
|
||||
"//third_party/bounds_checking_function:libsec_static",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hilog_native:libhilog_base",
|
||||
"utils_base:utils",
|
||||
]
|
||||
if (build_selinux) {
|
||||
deps += [ "//third_party/selinux:libselinux" ]
|
||||
external_deps += [ "selinux:libparaperm_checker" ]
|
||||
defines += [ "PARAM_SUPPORT_SELINUX" ]
|
||||
}
|
||||
install_images = [ "system" ]
|
||||
install_enable = true
|
||||
part_name = "init"
|
||||
}
|
||||
|
||||
group("begetctl_cmd") {
|
||||
deps = [
|
||||
":begetctl",
|
||||
":param",
|
||||
":paramshell",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ static int main_cmd(BShellHandle shell, int argc, char* argv[])
|
||||
strcmp(argv[1], "suspend") != 0 &&
|
||||
strcmp(argv[1], "flashd") != 0 &&
|
||||
#ifdef INIT_TEST
|
||||
strcmp(argv[1], "charing") != 0 &&
|
||||
strcmp(argv[1], "charge") != 0 &&
|
||||
#endif
|
||||
#ifdef PRODUCT_RK
|
||||
strcmp(argv[1], "loader") != 0 &&
|
||||
@ -70,7 +70,7 @@ MODULE_CONSTRUCTOR(void)
|
||||
{"reboot", main_cmd, "reboot and boot into flashd", "reboot flashd", ""},
|
||||
{"reboot", main_cmd, "reboot and boot into flashd", "reboot flashd[:options]", ""},
|
||||
#ifdef INIT_TEST
|
||||
{"reboot", main_cmd, "reboot and boot into charing", "reboot charing", ""},
|
||||
{"reboot", main_cmd, "reboot and boot into charge", "reboot charge", ""},
|
||||
#endif
|
||||
#ifdef PRODUCT_RK
|
||||
{"reboot", main_cmd, "reboot loader", "reboot loader", ""}
|
||||
|
@ -111,7 +111,7 @@ int SetParamShellPrompt(BShellHandle shell, const char *param)
|
||||
return -1;
|
||||
}
|
||||
// check parameter
|
||||
int ret = SysCheckParamExist(realParameter);
|
||||
int ret = SystemCheckParamExist(realParameter);
|
||||
if (ret == PARAM_CODE_NOT_FOUND) {
|
||||
BShellEnvOutput(shell, "Error: parameter \'%s\' not found\r\n", realParameter);
|
||||
return -1;
|
||||
@ -228,7 +228,7 @@ static int32_t BShellParamCmdLs(BShellHandle shell, int32_t argc, char *argv[])
|
||||
BShellEnvOutput(shell, "Error: Forbid to list parameters\r\n");
|
||||
}
|
||||
} else {
|
||||
ret = SysCheckParamExist(prefix);
|
||||
ret = SystemCheckParamExist(prefix);
|
||||
if (ret == 0) {
|
||||
ParamHandle handle;
|
||||
ret = SystemFindParameter(prefix, &handle);
|
||||
@ -398,7 +398,7 @@ static int32_t BShellParamCmdShell(BShellHandle shell, int32_t argc, char *argv[
|
||||
BSH_LOGV("BShellParamCmdShell %d %s", argc, argv[1]);
|
||||
int ret = 0;
|
||||
if (argc > 1) {
|
||||
ret = SysCheckParamExist(argv[1]);
|
||||
ret = SystemCheckParamExist(argv[1]);
|
||||
if (ret != 0) {
|
||||
BShellEnvOutput(shell, "Error: parameter \'%s\' not found\r\n", argv[1]);
|
||||
return -1;
|
||||
|
@ -22,8 +22,9 @@ if (defined(ohos_lite)) {
|
||||
outputs = [ "$root_out_dir/system/etc/param/ohos.para.dac" ]
|
||||
}
|
||||
copy("ohos.const") {
|
||||
sources =
|
||||
[ "//base/startup/init_lite/services/etc/param/ohos_const/ohos.para" ]
|
||||
sources = [
|
||||
"//base/startup/init_lite/services/etc_lite/param/ohos_const/ohos.para",
|
||||
]
|
||||
outputs = [ "$root_out_dir/system/etc/param/ohos_const/ohos.para" ]
|
||||
}
|
||||
|
||||
|
21
services/etc/device.charge.group.cfg
Executable file
21
services/etc/device.charge.group.cfg
Executable file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"jobs": [
|
||||
"param:sys.usb.config=hdc && param:sys.usb.configfs=1",
|
||||
"param:sys.usb.ffs.ready=1 && param:sys.usb.config=hdc && param:sys.usb.configfs=1",
|
||||
"boot && param:persist.sys.usb.config=*",
|
||||
"param:sys.usb.config=none && param:sys.usb.configfs=0",
|
||||
"boot && param:const.debuggable=1",
|
||||
"param:sys.usb.config=none && param:sys.usb.configfs=1",
|
||||
"load_persist_props_action"
|
||||
],
|
||||
"services": [
|
||||
"ueventd",
|
||||
"console",
|
||||
"watchdog_service",
|
||||
"hdf_devmgr",
|
||||
"samgr",
|
||||
"param_watcher"
|
||||
],
|
||||
"groups": [
|
||||
]
|
||||
}
|
@ -56,4 +56,3 @@ const.product.build.date=default
|
||||
const.product.hardwareprofile=default
|
||||
const.ohos.buildroothash=default
|
||||
const.ohos.sdkapilevel=8
|
||||
const.ohos.name=OpenHarmony
|
||||
|
@ -10,7 +10,7 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
const.ohos.version.security_patch=2022-03-30
|
||||
const.ohos.releasetype=Canary1
|
||||
const.ohos.apiversion=8
|
||||
const.ohos.apiversion=8
|
||||
const.ohos.fullname=OpenHarmony-2.2.0.0
|
17
services/etc_lite/param/ohos_const/ohos.para
Executable file
17
services/etc_lite/param/ohos_const/ohos.para
Executable file
@ -0,0 +1,17 @@
|
||||
# Copyright (c) 2021 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
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
const.ohos.releasetype=Beta
|
||||
const.ohos.apiversion=6
|
||||
const.ohos.version.security_patch=2021-09-01
|
||||
const.ohos.fullname=OpenHarmony-1.0.1.0
|
@ -17,6 +17,7 @@
|
||||
#define INIT_UTILS_H
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -69,7 +70,7 @@ int StringReplaceChr(char *strl, char oldChr, char newChr);
|
||||
|
||||
int GetMapValue(const char *name, const InitArgInfo *infos, int argNum, int defValue);
|
||||
const InitArgInfo *GetServieStatusMap(int *size);
|
||||
unsigned int GetRandom(void);
|
||||
uint32_t GetRandom(void);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ typedef enum {
|
||||
PARAM_CODE_NOT_FOUND,
|
||||
PARAM_CODE_READ_ONLY,
|
||||
PARAM_CODE_FAIL_CONNECT,
|
||||
PARAM_CODE_NODE_EXIST,
|
||||
PARAM_CODE_NODE_EXIST, // 9
|
||||
PARAM_CODE_MAX
|
||||
} PARAM_CODE;
|
||||
|
||||
@ -89,7 +89,7 @@ void StopParamService(void);
|
||||
* 加载默认的参数值
|
||||
*
|
||||
*/
|
||||
int LoadDefaultParams(const char *fileName, unsigned int mode);
|
||||
int LoadDefaultParams(const char *fileName, uint32_t mode);
|
||||
|
||||
/**
|
||||
* Init 接口
|
||||
@ -110,7 +110,7 @@ int SystemWriteParam(const char *name, const char *value);
|
||||
* 查询参数。
|
||||
*
|
||||
*/
|
||||
int SystemReadParam(const char *name, char *value, unsigned int *len);
|
||||
int SystemReadParam(const char *name, char *value, uint32_t *len);
|
||||
|
||||
#ifdef PARAM_SUPPORT_TRIGGER
|
||||
/**
|
||||
@ -217,7 +217,7 @@ int SystemWaitParameter(const char *name, const char *value, int32_t timeout);
|
||||
typedef void (*ParameterChangePtr)(const char *key, const char *value, void *context);
|
||||
int SystemWatchParameter(const char *keyprefix, ParameterChangePtr change, void *context);
|
||||
|
||||
int SysCheckParamExist(const char *name);
|
||||
int SystemCheckParamExist(const char *name);
|
||||
long long GetSystemCommitId(void);
|
||||
|
||||
void SystemDumpParameters(int verbose);
|
||||
|
@ -36,7 +36,7 @@ extern "C" {
|
||||
|
||||
typedef enum {
|
||||
GROUP_BOOT,
|
||||
GROUP_CHARING,
|
||||
GROUP_CHARGE,
|
||||
GROUP_UNKNOW
|
||||
} InitGroupType;
|
||||
|
||||
|
@ -35,7 +35,7 @@ static int GetBootGroupMode(void)
|
||||
{
|
||||
static const char *groupModes[] = {
|
||||
"device.boot.group",
|
||||
"device.charing.group"
|
||||
"device.charge.group"
|
||||
};
|
||||
for (size_t i = 0; i < ARRAY_LENGTH(groupModes); i++) {
|
||||
if (strcmp(g_initWorkspace.groupModeStr, groupModes[i]) == 0) {
|
||||
@ -190,8 +190,8 @@ void InitServiceSpace(void)
|
||||
g_initWorkspace.groupModeStr, sizeof(g_initWorkspace.groupModeStr));
|
||||
if (ret != 0) {
|
||||
INIT_LOGE("%s", "Failed to get boot group");
|
||||
if (GetBootModeFromMisc() == GROUP_CHARING) {
|
||||
strcpy_s(g_initWorkspace.groupModeStr, sizeof(g_initWorkspace.groupModeStr), "device.charing.group");
|
||||
if (GetBootModeFromMisc() == GROUP_CHARGE) {
|
||||
strcpy_s(g_initWorkspace.groupModeStr, sizeof(g_initWorkspace.groupModeStr), "device.charge.group");
|
||||
}
|
||||
}
|
||||
free(data);
|
||||
|
@ -32,7 +32,7 @@
|
||||
"//base/startup/init_lite/interfaces/innerkits:libbegetutil",
|
||||
"//base/startup/init_lite/services:init_lite",
|
||||
"//base/startup/init_lite/services/begetctl:begetctl_cmd",
|
||||
"//base/startup/init_lite/watchdog:watchdog",
|
||||
"//base/startup/init_lite/watchdog:init_watchdog",
|
||||
"//base/startup/init_lite/ueventd:ueventd"
|
||||
],
|
||||
"inner_kits": [
|
||||
@ -52,7 +52,7 @@
|
||||
}
|
||||
],
|
||||
"test": [
|
||||
"//base/startup/init_lite/test/unittest/lite:init_test"
|
||||
"//base/startup/init_lite/services:unittest"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ void SystemPrepare(void)
|
||||
void SystemConfig(void)
|
||||
{
|
||||
InitServiceSpace();
|
||||
#ifdef LITEOS_SUPPORT_PARAM
|
||||
#ifdef LITEOS_SUPPORT
|
||||
InitParamService();
|
||||
// parse parameters
|
||||
LoadDefaultParams("/system/etc/param/ohos_const", LOAD_PARAM_NORMAL);
|
||||
|
@ -94,8 +94,8 @@ int GetBootModeFromMisc(void)
|
||||
struct RBMiscUpdateMessage msg;
|
||||
ret = RBMiscReadUpdaterMessage(miscFile, &msg);
|
||||
INIT_ERROR_CHECK(ret == 0, return -1, "Failed to get misc info");
|
||||
if (memcmp(msg.command, "boot_charing", strlen("boot_charing")) == 0) {
|
||||
return GROUP_CHARING;
|
||||
if (memcmp(msg.command, "boot_charge", strlen("boot_charge")) == 0) {
|
||||
return GROUP_CHARGE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -214,11 +214,11 @@ static int DoSuspendCmd(const char *cmd, const char *opt)
|
||||
}
|
||||
|
||||
#ifdef INIT_TEST
|
||||
static int DoCharingCmd()
|
||||
static int DoChargeCmd()
|
||||
{
|
||||
// by job to stop service and unmount
|
||||
DoJobNow("reboot");
|
||||
int ret = CheckAndRebootToUpdater(NULL, "charing", "charing:", "boot_charing");
|
||||
int ret = CheckAndRebootToUpdater(NULL, "charge", "charge:", "boot_charge");
|
||||
if (ret == 0) {
|
||||
#ifndef STARTUP_INIT_TEST
|
||||
return reboot(RB_AUTOBOOT);
|
||||
@ -242,7 +242,7 @@ struct {
|
||||
#endif
|
||||
{ "suspend", DoSuspendCmd },
|
||||
#ifdef INIT_TEST
|
||||
{ "charing", DoCharingCmd }
|
||||
{ "charge", DoChargeCmd }
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -105,7 +105,7 @@ void InitLog(InitLogLevel logLevel, unsigned int domain, const char *tag, const
|
||||
}
|
||||
va_list vargs;
|
||||
va_start(vargs, fmt);
|
||||
char tmpFmt[MAX_LOG_SIZE];
|
||||
char tmpFmt[MAX_LOG_SIZE] = {0};
|
||||
if (vsnprintf_s(tmpFmt, MAX_LOG_SIZE, MAX_LOG_SIZE - 1, fmt, vargs) == -1) {
|
||||
va_end(vargs);
|
||||
return;
|
||||
|
@ -13,7 +13,6 @@
|
||||
import("//base/startup/init_lite/begetd.gni")
|
||||
|
||||
param_comm_sources = [
|
||||
"adapter/param_dac.c",
|
||||
"manager/param_manager.c",
|
||||
"manager/param_trie.c",
|
||||
"manager/param_utils.c",
|
||||
@ -36,33 +35,6 @@ if (!defined(ohos_lite) || ohos_kernel_type == "linux") {
|
||||
]
|
||||
}
|
||||
|
||||
action("lite_const_param_to") {
|
||||
script = "//base/startup/init_lite/scripts/param_cfg_to_code.py"
|
||||
args = [
|
||||
"--source",
|
||||
rebase_path(
|
||||
"//base/startup/init_lite/services/etc/param/ohos_const/ohos.para"),
|
||||
"--dest_dir",
|
||||
rebase_path("$root_out_dir/gen/init_lite/"),
|
||||
"--priority",
|
||||
"0",
|
||||
]
|
||||
outputs = [ "$target_gen_dir/${target_name}_param_cfg_to_code.log" ]
|
||||
}
|
||||
|
||||
action("lite_ohos_param_to") {
|
||||
script = "//base/startup/init_lite/scripts/param_cfg_to_code.py"
|
||||
args = [
|
||||
"--source",
|
||||
rebase_path("//base/startup/init_lite/services/etc/param/ohos.para"),
|
||||
"--dest_dir",
|
||||
rebase_path("$root_out_dir/gen/init_lite/"),
|
||||
"--priority",
|
||||
"0",
|
||||
]
|
||||
outputs = [ "$target_gen_dir/${target_name}_param_cfg_to_code.log" ]
|
||||
}
|
||||
|
||||
param_include_dirs = [
|
||||
"include",
|
||||
"adapter",
|
||||
@ -77,9 +49,62 @@ param_include_dirs = [
|
||||
"//third_party/libuv/include",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"//third_party/cJSON",
|
||||
"//utils/native/lite/include",
|
||||
]
|
||||
|
||||
if (enable_ohos_startup_init_feature_begetctl_liteos) {
|
||||
action("lite_const_param_to") {
|
||||
script = "//base/startup/init_lite/scripts/param_cfg_to_code.py"
|
||||
args = [
|
||||
"--source",
|
||||
rebase_path(
|
||||
"//base/startup/init_lite/services/etc_lite/param/ohos_const/ohos.para"),
|
||||
"--dest_dir",
|
||||
rebase_path("$root_out_dir/gen/init_lite/"),
|
||||
"--priority",
|
||||
"0",
|
||||
]
|
||||
outputs = [ "$target_gen_dir/${target_name}_param_cfg_to_code.log" ]
|
||||
}
|
||||
|
||||
action("lite_ohos_param_to") {
|
||||
script = "//base/startup/init_lite/scripts/param_cfg_to_code.py"
|
||||
args = [
|
||||
"--source",
|
||||
rebase_path("//base/startup/init_lite/services/etc/param/ohos.para"),
|
||||
"--dest_dir",
|
||||
rebase_path("$root_out_dir/gen/init_lite/"),
|
||||
"--priority",
|
||||
"0",
|
||||
]
|
||||
outputs = [ "$target_gen_dir/${target_name}_param_cfg_to_code.log" ]
|
||||
}
|
||||
|
||||
action("vendor_param_to") {
|
||||
script = "//base/startup/init_lite/scripts/param_cfg_to_code.py"
|
||||
args = [
|
||||
"--source",
|
||||
rebase_path("$ohos_product_adapter_dir/utils/sys_param/vendor.para"),
|
||||
"--dest_dir",
|
||||
rebase_path("$root_out_dir/gen/init_lite/"),
|
||||
"--priority",
|
||||
"1",
|
||||
]
|
||||
outputs = [ "$target_gen_dir/${target_name}_param_cfg_to_code.log" ]
|
||||
}
|
||||
}
|
||||
|
||||
if (defined(ohos_lite)) {
|
||||
param_build_defines = [
|
||||
"_GNU_SOURCE",
|
||||
"INCREMENTAL_VERSION=\"${ohos_version}\"",
|
||||
"BUILD_TYPE=\"${ohos_build_type}\"",
|
||||
"BUILD_USER=\"${ohos_build_user}\"",
|
||||
"BUILD_TIME=\"${ohos_build_time}\"",
|
||||
"BUILD_HOST=\"${ohos_build_host}\"",
|
||||
"BUILD_ROOTHASH=\"${ohos_build_roothash}\"",
|
||||
]
|
||||
|
||||
static_library("param_init") {
|
||||
defines = []
|
||||
deps = []
|
||||
@ -88,10 +113,11 @@ if (defined(ohos_lite)) {
|
||||
if (defined(boot_kernel_extended_cmdline)) {
|
||||
defines += [ "BOOT_EXTENDED_CMDLINE=\"${boot_kernel_extended_cmdline}\"" ]
|
||||
}
|
||||
defines += [ "_GNU_SOURCE" ]
|
||||
defines += param_build_defines
|
||||
if (ohos_kernel_type == "linux") {
|
||||
sources += param_service_sources
|
||||
sources += param_trigger_sources
|
||||
sources += [ "adapter/param_dac.c" ]
|
||||
defines += [ "__LINUX__" ]
|
||||
} else if (ohos_kernel_type == "liteos_a") {
|
||||
sources += [
|
||||
@ -107,24 +133,21 @@ if (defined(ohos_lite)) {
|
||||
"__LITEOS_A__",
|
||||
"PARAM_SUPPORT_CYCLE_CHECK",
|
||||
]
|
||||
deps += [
|
||||
":lite_const_param_to",
|
||||
":lite_ohos_param_to",
|
||||
]
|
||||
include_dirs += [ "$root_out_dir/gen/init_lite" ]
|
||||
}
|
||||
}
|
||||
|
||||
static_library("param_client") {
|
||||
sources = param_comm_sources
|
||||
include_dirs = param_include_dirs
|
||||
defines = [ "_GNU_SOURCE" ]
|
||||
defines = param_build_defines
|
||||
|
||||
if (ohos_kernel_type == "linux") {
|
||||
sources += [
|
||||
"linux/param_message.c",
|
||||
"linux/param_osadp.c",
|
||||
"linux/param_request.c",
|
||||
]
|
||||
sources += [ "adapter/param_dac.c" ]
|
||||
defines += [ "__LINUX__" ]
|
||||
} else if (ohos_kernel_type == "liteos_a") {
|
||||
sources += [
|
||||
@ -141,11 +164,15 @@ if (defined(ohos_lite)) {
|
||||
]
|
||||
} else if (ohos_kernel_type == "liteos_m") {
|
||||
sources += [
|
||||
"adapter/param_persistadp.c",
|
||||
"liteos/param_client.c",
|
||||
"liteos/param_osadp.c",
|
||||
"manager/param_persist.c",
|
||||
]
|
||||
if (enable_ohos_startup_init_lite_use_posix_file_api) {
|
||||
sources += [ "adapter/param_persistadp.c" ]
|
||||
} else {
|
||||
sources += [ "liteos/param_hal.c" ]
|
||||
}
|
||||
defines += [
|
||||
"__LITEOS_M__",
|
||||
"WORKSPACE_AREA_NEED_MUTEX",
|
||||
@ -153,11 +180,15 @@ if (defined(ohos_lite)) {
|
||||
"PARAMWORKSPACE_NEED_MUTEX",
|
||||
"DATA_PATH=\"${config_ohos_startup_init_lite_data_path}\"",
|
||||
]
|
||||
deps = [
|
||||
":lite_const_param_to",
|
||||
":lite_ohos_param_to",
|
||||
]
|
||||
include_dirs += [ "$root_out_dir/gen/init_lite" ]
|
||||
if (enable_ohos_startup_init_feature_begetctl_liteos) {
|
||||
deps = [
|
||||
":lite_const_param_to",
|
||||
":lite_ohos_param_to",
|
||||
":vendor_param_to",
|
||||
]
|
||||
include_dirs += [ "$root_out_dir/gen/init_lite" ]
|
||||
defines += [ "PARAM_LOAD_CFG_FROM_CODE" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -167,8 +198,8 @@ if (defined(ohos_lite)) {
|
||||
sources = param_comm_sources
|
||||
sources += param_service_sources
|
||||
sources += param_trigger_sources
|
||||
sources += [ "adapter/param_dac.c" ]
|
||||
include_dirs = param_include_dirs
|
||||
|
||||
defines = [ "_GNU_SOURCE" ]
|
||||
|
||||
if (defined(boot_kernel_extended_cmdline)) {
|
||||
@ -196,6 +227,7 @@ if (defined(ohos_lite)) {
|
||||
|
||||
ohos_static_library("param_client") {
|
||||
sources = param_comm_sources
|
||||
sources += [ "adapter/param_dac.c" ]
|
||||
sources += [
|
||||
"linux/param_message.c",
|
||||
"linux/param_osadp.c",
|
||||
|
@ -81,16 +81,10 @@ static int InitLocalSecurityLabel(ParamSecurityLabel *security, int isInit)
|
||||
UNUSED(isInit);
|
||||
PARAM_CHECK(security != NULL, return -1, "Invalid security");
|
||||
security->cred.pid = getpid();
|
||||
#if defined __LITEOS_A__ || defined __LITEOS_M__
|
||||
security->cred.uid = getuid();
|
||||
security->cred.gid = 0;
|
||||
security->flags[PARAM_SECURITY_DAC] |= LABEL_CHECK_IN_ALL_PROCESS;
|
||||
#else
|
||||
security->cred.uid = geteuid();
|
||||
security->cred.gid = getegid();
|
||||
// support check write permission in client
|
||||
security->flags[PARAM_SECURITY_DAC] |= LABEL_CHECK_IN_ALL_PROCESS;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -166,7 +160,7 @@ static int CheckUserInGroup(WorkSpace *space, gid_t groupId, uid_t uid)
|
||||
int ret = sprintf_s(buffer, sizeof(buffer) - 1, "%s.%d.%d", GROUP_FORMAT, groupId, uid);
|
||||
PARAM_CHECK(ret >= 0, return -1, "Failed to format name for %s.%d.%d", GROUP_FORMAT, groupId, uid);
|
||||
(void)FindTrieNode(space, buffer, strlen(buffer), &labelIndex);
|
||||
ParamSecruityNode *node = (ParamSecruityNode *)GetTrieNode(space, labelIndex);
|
||||
ParamSecurityNode *node = (ParamSecurityNode *)GetTrieNode(space, labelIndex);
|
||||
PARAM_CHECK(node != NULL, return DAC_RESULT_FORBIDED, "Can not get security label %d", labelIndex);
|
||||
PARAM_LOGV("CheckUserInGroup %s groupid %d uid %d", buffer, groupId, uid);
|
||||
if (node->gid == groupId && node->uid == uid) {
|
||||
@ -180,21 +174,13 @@ static int CheckUserInGroup(WorkSpace *space, gid_t groupId, uid_t uid)
|
||||
|
||||
static int DacCheckParamPermission(const ParamSecurityLabel *srcLabel, const char *name, uint32_t mode)
|
||||
{
|
||||
#if defined(__LITEOS_A__)
|
||||
uid_t uid = getuid();
|
||||
return uid <= SYS_UID_INDEX ? DAC_RESULT_PERMISSION : DAC_RESULT_FORBIDED;
|
||||
#endif
|
||||
#if defined(__LITEOS_M__)
|
||||
return DAC_RESULT_PERMISSION;
|
||||
#endif
|
||||
|
||||
int ret = DAC_RESULT_FORBIDED;
|
||||
uint32_t labelIndex = 0;
|
||||
// get dac label
|
||||
WorkSpace *space = GetWorkSpace(WORKSPACE_NAME_DAC);
|
||||
PARAM_CHECK(space != NULL, return DAC_RESULT_FORBIDED, "Failed to get dac space %s", name);
|
||||
(void)FindTrieNode(space, name, strlen(name), &labelIndex);
|
||||
ParamSecruityNode *node = (ParamSecruityNode *)GetTrieNode(space, labelIndex);
|
||||
ParamSecurityNode *node = (ParamSecurityNode *)GetTrieNode(space, labelIndex);
|
||||
PARAM_CHECK(node != NULL, return DAC_RESULT_FORBIDED, "Can not get security label %d", labelIndex);
|
||||
/**
|
||||
* DAC group
|
||||
@ -252,8 +238,6 @@ void LoadGroupUser(void)
|
||||
#ifndef __MUSL__
|
||||
return;
|
||||
#endif
|
||||
|
||||
#if !(defined __LITEOS_A__ || defined __LITEOS_M__)
|
||||
PARAM_LOGV("LoadGroupUser ");
|
||||
uid_t uid = 0;
|
||||
struct group *data = NULL;
|
||||
@ -277,5 +261,4 @@ void LoadGroupUser(void)
|
||||
}
|
||||
PARAM_LOGV("LoadGroupUser getgrent fail errnor %d ", errno);
|
||||
endgrent();
|
||||
#endif
|
||||
}
|
@ -23,11 +23,6 @@
|
||||
#include "param_persist.h"
|
||||
#include "param_utils.h"
|
||||
|
||||
typedef struct {
|
||||
void *context;
|
||||
PersistParamGetPtr persistParamGet;
|
||||
} PersistAdpContext;
|
||||
|
||||
// for linux, no mutex
|
||||
static ParamMutex g_saveMutex = {};
|
||||
|
||||
|
@ -46,7 +46,7 @@ static int InitLocalSecurityLabel(ParamSecurityLabel *security, int isInit)
|
||||
const char *libname = (InUpdaterMode() == 1) ? CHECKER_UPDATER_LIB_NAME : CHECKER_LIB_NAME;
|
||||
g_selinuxSpace.selinuxHandle = dlopen(libname, RTLD_LAZY);
|
||||
PARAM_CHECK(g_selinuxSpace.selinuxHandle != NULL,
|
||||
return -1, "Failed to dlsym selinuxHandle, %s", dlerror());
|
||||
return 0, "Failed to dlsym selinuxHandle, %s", dlerror());
|
||||
}
|
||||
void *handle = g_selinuxSpace.selinuxHandle;
|
||||
if (g_selinuxSpace.setSelinuxLogCallback == NULL) {
|
||||
@ -130,8 +130,7 @@ static int CheckFilePermission(const ParamSecurityLabel *localLabel, const char
|
||||
static int SelinuxReadParamCheck(const char *name)
|
||||
{
|
||||
int ret = DAC_RESULT_FORBIDED;
|
||||
PARAM_CHECK(g_selinuxSpace.getParamLabel != NULL, return ret, "Invalid getParamLabel");
|
||||
const char *label = g_selinuxSpace.getParamLabel(name);
|
||||
const char *label = GetSelinuxContent(name);
|
||||
if (label == NULL) { // open file with readonly
|
||||
ret = AddWorkSpace(WORKSPACE_NAME_DEF_SELINUX, 1, PARAM_WORKSPACE_MAX);
|
||||
} else {
|
||||
@ -167,6 +166,11 @@ static int SelinuxCheckParamPermission(const ParamSecurityLabel *srcLabel, const
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int UpdaterCheckParamPermission(const ParamSecurityLabel *srcLabel, const char *name, uint32_t mode)
|
||||
{
|
||||
return DAC_RESULT_PERMISSION;
|
||||
}
|
||||
|
||||
int RegisterSecuritySelinuxOps(ParamSecurityOps *ops, int isInit)
|
||||
{
|
||||
PARAM_CHECK(ops != NULL, return -1, "Invalid param");
|
||||
@ -174,7 +178,11 @@ int RegisterSecuritySelinuxOps(ParamSecurityOps *ops, int isInit)
|
||||
ops->securityGetLabel = NULL;
|
||||
ops->securityInitLabel = InitLocalSecurityLabel;
|
||||
ops->securityCheckFilePermission = CheckFilePermission;
|
||||
ops->securityCheckParamPermission = SelinuxCheckParamPermission;
|
||||
if (InUpdaterMode() == 1) {
|
||||
ops->securityCheckParamPermission = UpdaterCheckParamPermission;
|
||||
} else {
|
||||
ops->securityCheckParamPermission = SelinuxCheckParamPermission;
|
||||
}
|
||||
ops->securityFreeLabel = FreeLocalSecurityLabel;
|
||||
if (isInit) {
|
||||
ops->securityGetLabel = SelinuxGetParamSecurityLabel;
|
||||
@ -184,8 +192,12 @@ int RegisterSecuritySelinuxOps(ParamSecurityOps *ops, int isInit)
|
||||
|
||||
const char *GetSelinuxContent(const char *name)
|
||||
{
|
||||
PARAM_CHECK(g_selinuxSpace.getParamLabel != NULL, return NULL, "Invalid getParamLabel");
|
||||
return g_selinuxSpace.getParamLabel(name);
|
||||
if (g_selinuxSpace.getParamLabel != NULL) {
|
||||
return g_selinuxSpace.getParamLabel(name);
|
||||
} else {
|
||||
PARAM_LOGE("Can not init selinux");
|
||||
return WORKSPACE_NAME_DEF_SELINUX;
|
||||
}
|
||||
}
|
||||
|
||||
void OpenPermissionWorkSpace(void)
|
||||
|
@ -81,7 +81,7 @@ int InitParamWorkSpace(int onlyRead);
|
||||
void CloseParamWorkSpace(void);
|
||||
WorkSpace *GetWorkSpace(const char *name);
|
||||
int AddWorkSpace(const char *name, int onlyRead, uint32_t spacesize);
|
||||
WorkSpace *GetFristWorkSpace(void);
|
||||
WorkSpace *GetFirstWorkSpace(void);
|
||||
WorkSpace *GetNextWorkSpace(WorkSpace *curr);
|
||||
|
||||
ParamTrieNode *GetTrieNodeByHandle(ParamHandle handle);
|
||||
@ -112,6 +112,7 @@ typedef struct {
|
||||
|
||||
const char *GetSelinuxContent(const char *name);
|
||||
|
||||
void LoadParamFromBuild(void);
|
||||
int LoadParamFromCmdLine(void);
|
||||
void LoadSelinuxLabel(void);
|
||||
|
||||
@ -120,6 +121,7 @@ void ClosePersistParamWorkSpace(void);
|
||||
int WritePersistParam(const char *name, const char *value);
|
||||
long long GetPersistCommitId(void);
|
||||
void UpdatePersistCommitId(void);
|
||||
int SysCheckParamExist(const char *name);
|
||||
|
||||
#ifdef STARTUP_INIT_TEST
|
||||
ParamService *GetParamService();
|
||||
|
@ -20,11 +20,8 @@
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include "param_utils.h"
|
||||
#include "securec.h"
|
||||
#if !(defined __LITEOS_A__ || defined __LITEOS_M__)
|
||||
#include <sys/syscall.h>
|
||||
#include "loop_event.h"
|
||||
#else
|
||||
#include <time.h>
|
||||
@ -32,12 +29,16 @@
|
||||
|
||||
#ifndef __LITEOS_M__
|
||||
#include <pthread.h>
|
||||
#include <stdatomic.h>
|
||||
#endif
|
||||
|
||||
#if defined FUTEX_WAIT || defined FUTEX_WAKE
|
||||
#include <linux/futex.h>
|
||||
#endif
|
||||
|
||||
#include "param_utils.h"
|
||||
#include "securec.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
@ -135,6 +136,7 @@ typedef struct {
|
||||
} ParamMutex;
|
||||
#endif
|
||||
|
||||
void paramMutexEnvInit(void);
|
||||
int ParamRWMutexCreate(ParamRWMutex *lock);
|
||||
int ParamRWMutexWRLock(ParamRWMutex *lock);
|
||||
int ParamRWMutexRDLock(ParamRWMutex *lock);
|
||||
@ -176,9 +178,25 @@ typedef struct {
|
||||
void *GetSharedMem(const char *fileName, MemHandle *handle, uint32_t spaceSize, int readOnly);
|
||||
void FreeSharedMem(const MemHandle *handle, void *mem, uint32_t dataSize);
|
||||
|
||||
// for atomic
|
||||
#ifdef __LITEOS_M__
|
||||
#define ATOMIC_UINT32 uint32_t
|
||||
#define ATOMIC_LLONG long long
|
||||
#define ATOMIC_INIT(commitId, value) *(commitId) = (value)
|
||||
#define ATOMIC_LOAD_EXPLICIT(commitId, order) *(commitId)
|
||||
#define ATOMIC_STORE_EXPLICIT(commitId, value, order) *(commitId) = (value)
|
||||
#else
|
||||
#define ATOMIC_UINT32 atomic_uint
|
||||
#define ATOMIC_LLONG atomic_llong
|
||||
#define ATOMIC_INIT(commitId, value) atomic_init((commitId), (value))
|
||||
#define ATOMIC_LOAD_EXPLICIT(commitId, order) atomic_load_explicit((commitId), (order))
|
||||
#define ATOMIC_STORE_EXPLICIT(commitId, value, order) atomic_store_explicit((commitId), (value), (order))
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
uint32_t Difftime(time_t curr, time_t base);
|
||||
#endif // BASE_STARTUP_PARAM_MESSAGE_H
|
@ -27,8 +27,12 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int (*PersistParamGetPtr)(const char *name, const char *value, void *context);
|
||||
|
||||
typedef void *PERSIST_SAVE_HANDLE;
|
||||
typedef struct {
|
||||
void *context;
|
||||
PersistParamGetPtr persistParamGet;
|
||||
} PersistAdpContext;
|
||||
|
||||
typedef struct {
|
||||
int (*load)();
|
||||
int (*save)(const char *name, const char *value);
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#ifndef BASE_STARTUP_PARAM_TRIE_H
|
||||
#define BASE_STARTUP_PARAM_TRIE_H
|
||||
#include <stdatomic.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "init_hashmap.h"
|
||||
@ -53,7 +52,7 @@ typedef struct {
|
||||
#define PARAM_FLAGS_COMMITID 0x0000ffff
|
||||
|
||||
typedef struct {
|
||||
atomic_uint commitId;
|
||||
ATOMIC_UINT32 commitId;
|
||||
uint16_t keyLength;
|
||||
uint16_t valueLength;
|
||||
char data[0];
|
||||
@ -65,11 +64,11 @@ typedef struct {
|
||||
uint16_t mode;
|
||||
uint16_t length;
|
||||
char data[0];
|
||||
} ParamSecruityNode;
|
||||
} ParamSecurityNode;
|
||||
|
||||
typedef struct {
|
||||
atomic_llong commitId;
|
||||
atomic_llong commitPersistId;
|
||||
ATOMIC_LLONG commitId;
|
||||
ATOMIC_LLONG commitPersistId;
|
||||
uint32_t trieNodeCount;
|
||||
uint32_t paramNodeCount;
|
||||
uint32_t securityNodeCount;
|
||||
|
@ -66,9 +66,10 @@ typedef struct cmdLineInfo {
|
||||
#define PARAM_STATIC static
|
||||
#endif
|
||||
|
||||
#ifdef __LITEOS_M__
|
||||
#ifndef DATA_PATH
|
||||
#if defined __LITEOS_M__
|
||||
#define DATA_PATH ""
|
||||
#endif
|
||||
#elif defined __LITEOS_A__
|
||||
#define DATA_PATH STARTUP_INIT_UT_PATH"/storage/data/system/param/"
|
||||
#elif defined __LINUX__
|
||||
@ -76,7 +77,6 @@ typedef struct cmdLineInfo {
|
||||
#else
|
||||
#define DATA_PATH STARTUP_INIT_UT_PATH"/data/parameters/"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define CLIENT_PIPE_NAME "/dev/unix/socket/paramservice"
|
||||
#define PIPE_NAME STARTUP_INIT_UT_PATH "/dev/unix/socket/paramservice"
|
||||
|
@ -22,6 +22,10 @@
|
||||
#include "param_message.h"
|
||||
#include "param_utils.h"
|
||||
|
||||
void paramMutexEnvInit(void)
|
||||
{
|
||||
}
|
||||
|
||||
int ParamRWMutexCreate(ParamRWMutex *lock)
|
||||
{
|
||||
return 0;
|
||||
@ -84,4 +88,9 @@ void FreeSharedMem(const MemHandle *handle, void *mem, uint32_t dataSize)
|
||||
{
|
||||
PARAM_CHECK(mem != NULL && handle != NULL, return, "Invalid mem or handle");
|
||||
munmap((char *)mem, dataSize);
|
||||
}
|
||||
|
||||
uint32_t Difftime(time_t curr, time_t base)
|
||||
{
|
||||
return (uint32_t)difftime(curr, base);
|
||||
}
|
@ -29,16 +29,11 @@
|
||||
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define INIT_PROCESS_PID 1
|
||||
|
||||
static const uint32_t RECV_BUFFER_MAX = 5 * 1024;
|
||||
|
||||
static atomic_uint g_requestId = ATOMIC_VAR_INIT(1);
|
||||
static ClientWorkSpace g_clientSpace = {};
|
||||
|
||||
__attribute__((constructor)) static void ClientInit(void);
|
||||
#ifndef STARTUP_INIT_TEST
|
||||
__attribute__((constructor(100))) static void ClientInit(void);
|
||||
__attribute__((destructor)) static void ClientDeinit(void);
|
||||
#endif
|
||||
|
||||
static int InitParamClient(void)
|
||||
{
|
||||
@ -69,9 +64,14 @@ void ClientInit(void)
|
||||
|
||||
void ClientDeinit(void)
|
||||
{
|
||||
#ifndef STARTUP_INIT_TEST
|
||||
if (PARAM_TEST_FLAG(g_clientSpace.flags, WORKSPACE_FLAGS_INIT)) {
|
||||
CloseParamWorkSpace();
|
||||
}
|
||||
#endif
|
||||
if (g_clientSpace.clientFd != INVALID_SOCKET) {
|
||||
close(g_clientSpace.clientFd);
|
||||
}
|
||||
PARAM_SET_FLAG(g_clientSpace.flags, 0);
|
||||
pthread_mutex_destroy(&g_clientSpace.mutex);
|
||||
}
|
||||
@ -120,35 +120,36 @@ static int ReadMessage(int fd, char *buffer, int timeout)
|
||||
continue;
|
||||
}
|
||||
} while (1);
|
||||
PARAM_LOGE("ReadMessage errno %d diff %u timeout %d ret %d", errno, diff, timeout, ret);
|
||||
if (ret != 0) {
|
||||
PARAM_LOGE("ReadMessage fd: %d errno %d diff %u timeout %d ret %d", errno, diff, timeout, ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int StartRequest(int *fd, ParamMessage *request, int timeout)
|
||||
static int GetClientSocket(int timeout)
|
||||
{
|
||||
int ret = 0;
|
||||
struct timeval time;
|
||||
#ifndef STARTUP_INIT_TEST
|
||||
time.tv_sec = timeout;
|
||||
#else
|
||||
time.tv_sec = 1;
|
||||
#endif
|
||||
time.tv_usec = 0;
|
||||
int clientFd = *fd;
|
||||
if (clientFd == INVALID_SOCKET) {
|
||||
clientFd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
PARAM_CHECK(clientFd >= 0, return PARAM_CODE_FAIL_CONNECT, "Failed to create socket");
|
||||
ret = ConntectServer(clientFd, CLIENT_PIPE_NAME);
|
||||
PARAM_CHECK(ret == 0, close(clientFd);
|
||||
return PARAM_CODE_FAIL_CONNECT, "Failed to connect server");
|
||||
int clientFd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
PARAM_CHECK(clientFd >= 0, return -1, "Failed to create socket");
|
||||
int ret = ConntectServer(clientFd, CLIENT_PIPE_NAME);
|
||||
if (ret == 0) {
|
||||
setsockopt(clientFd, SOL_SOCKET, SO_SNDTIMEO, (char *)&time, sizeof(struct timeval));
|
||||
setsockopt(clientFd, SOL_SOCKET, SO_RCVTIMEO, (char *)&time, sizeof(struct timeval));
|
||||
*fd = clientFd;
|
||||
} else {
|
||||
close(clientFd);
|
||||
clientFd = INVALID_SOCKET;
|
||||
}
|
||||
return clientFd;
|
||||
}
|
||||
|
||||
static int StartRequest(int clientFd, ParamMessage *request, int timeout)
|
||||
{
|
||||
int ret = 0;
|
||||
ssize_t sendLen = send(clientFd, (char *)request, request->msgSize, 0);
|
||||
PARAM_CHECK(sendLen >= 0, return PARAM_CODE_FAIL_CONNECT, "Failed to send message");
|
||||
PARAM_LOGV("sendMessage sendLen %zd", sendLen);
|
||||
PARAM_LOGV("sendMessage sendLen fd %d %zd", clientFd, sendLen);
|
||||
ret = ReadMessage(clientFd, (char *)request, timeout);
|
||||
if (ret == 0) {
|
||||
ret = ProcessRecvMsg(request);
|
||||
@ -176,9 +177,16 @@ int SystemSetParameter(const char *name, const char *value)
|
||||
request->msgSize = offset + sizeof(ParamMessage);
|
||||
request->id.msgId = atomic_fetch_add(&g_requestId, 1);
|
||||
|
||||
PARAM_LOGV("SystemSetParameter name %s", name);
|
||||
int fd = INVALID_SOCKET;
|
||||
pthread_mutex_lock(&g_clientSpace.mutex);
|
||||
ret = StartRequest(&g_clientSpace.clientFd, request, DEFAULT_PARAM_SET_TIMEOUT);
|
||||
if (g_clientSpace.clientFd == INVALID_SOCKET) {
|
||||
g_clientSpace.clientFd = GetClientSocket(DEFAULT_PARAM_SET_TIMEOUT);
|
||||
}
|
||||
fd = g_clientSpace.clientFd;
|
||||
pthread_mutex_unlock(&g_clientSpace.mutex);
|
||||
PARAM_CHECK(fd > 0, return -1, "Failed to connect server for set %s", name);
|
||||
ret = StartRequest(fd, request, DEFAULT_PARAM_SET_TIMEOUT);
|
||||
free(request);
|
||||
return ret;
|
||||
}
|
||||
@ -222,16 +230,35 @@ int SystemWaitParameter(const char *name, const char *value, int32_t timeout)
|
||||
|
||||
request->msgSize = offset + sizeof(ParamMessage);
|
||||
request->id.waitId = atomic_fetch_add(&g_requestId, 1);
|
||||
int fd = INVALID_SOCKET;
|
||||
ret = StartRequest(&fd, request, timeout);
|
||||
if (fd != INVALID_SOCKET) {
|
||||
close(fd);
|
||||
}
|
||||
#ifdef STARTUP_INIT_TEST
|
||||
timeout = 1;
|
||||
#endif
|
||||
int fd = GetClientSocket(timeout);
|
||||
PARAM_CHECK(fd > 0, return -1, "Failed to connect server for wait %s", name);
|
||||
ret = StartRequest(fd, request, timeout);
|
||||
close(fd);
|
||||
free(request);
|
||||
PARAM_LOGI("SystemWaitParameter %s value %s result %d ", name, value, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
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) {
|
||||
PARAM_CHECK(ret == 0, return ret, "Forbid to access parameter %s", name);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int WatchParamCheck(const char *keyprefix)
|
||||
{
|
||||
(void)InitParamClient();
|
||||
|
@ -62,23 +62,23 @@ static void CheckAndSendTrigger(uint32_t dataIndex, const char *name, const char
|
||||
ParamNode *entry = (ParamNode *)GetTrieNode(GetWorkSpace(name), dataIndex);
|
||||
PARAM_CHECK(entry != NULL, return, "Failed to get data %s ", name);
|
||||
uint32_t trigger = 1;
|
||||
if ((atomic_load_explicit(&entry->commitId, memory_order_relaxed) & PARAM_FLAGS_TRIGGED) != PARAM_FLAGS_TRIGGED) {
|
||||
if ((ATOMIC_LOAD_EXPLICIT(&entry->commitId, memory_order_relaxed) & PARAM_FLAGS_TRIGGED) != PARAM_FLAGS_TRIGGED) {
|
||||
trigger = (CheckAndMarkTrigger(TRIGGER_PARAM, name) != 0) ? 1 : 0;
|
||||
}
|
||||
if (trigger) {
|
||||
atomic_store_explicit(&entry->commitId,
|
||||
atomic_load_explicit(&entry->commitId, memory_order_relaxed) | PARAM_FLAGS_TRIGGED, memory_order_release);
|
||||
ATOMIC_STORE_EXPLICIT(&entry->commitId,
|
||||
ATOMIC_LOAD_EXPLICIT(&entry->commitId, memory_order_relaxed) | PARAM_FLAGS_TRIGGED, memory_order_release);
|
||||
// notify event to process trigger
|
||||
PostParamTrigger(EVENT_TRIGGER_PARAM, name, value);
|
||||
}
|
||||
|
||||
int wait = 1;
|
||||
if ((atomic_load_explicit(&entry->commitId, memory_order_relaxed) & PARAM_FLAGS_WAITED) != PARAM_FLAGS_WAITED) {
|
||||
if ((ATOMIC_LOAD_EXPLICIT(&entry->commitId, memory_order_relaxed) & PARAM_FLAGS_WAITED) != PARAM_FLAGS_WAITED) {
|
||||
wait = (CheckAndMarkTrigger(TRIGGER_PARAM_WAIT, name) != 0) ? 1 : 0;
|
||||
}
|
||||
if (wait) {
|
||||
atomic_store_explicit(&entry->commitId,
|
||||
atomic_load_explicit(&entry->commitId, memory_order_relaxed) | PARAM_FLAGS_WAITED, memory_order_release);
|
||||
ATOMIC_STORE_EXPLICIT(&entry->commitId,
|
||||
ATOMIC_LOAD_EXPLICIT(&entry->commitId, memory_order_relaxed) | PARAM_FLAGS_WAITED, memory_order_release);
|
||||
PostParamTrigger(EVENT_TRIGGER_PARAM_WAIT, name, value);
|
||||
}
|
||||
PostParamTrigger(EVENT_TRIGGER_PARAM_WATCH, name, value);
|
||||
@ -228,7 +228,11 @@ static int HandleParamWaitAdd(const ParamTaskPtr worker, const ParamMessage *msg
|
||||
{
|
||||
PARAM_CHECK(msg != NULL, return -1, "Invalid message");
|
||||
uint32_t offset = 0;
|
||||
#ifndef STARTUP_INIT_TEST
|
||||
uint32_t timeout = DEFAULT_PARAM_WAIT_TIMEOUT;
|
||||
#else
|
||||
uint32_t timeout = 0;
|
||||
#endif
|
||||
ParamMsgContent *valueContent = GetNextContent(msg, &offset);
|
||||
PARAM_CHECK(valueContent != NULL, return -1, "Invalid msg");
|
||||
PARAM_CHECK(valueContent->contentSize <= PARAM_CONST_VALUE_LEN_MAX, return -1, "Invalid msg");
|
||||
@ -376,6 +380,8 @@ void InitParamService(void)
|
||||
LoadSelinuxLabel();
|
||||
// from cmdline
|
||||
LoadParamFromCmdLine();
|
||||
// from build
|
||||
LoadParamFromBuild();
|
||||
}
|
||||
|
||||
int StartParamService(void)
|
||||
|
@ -25,15 +25,15 @@ __attribute__((destructor)) static void ClientDeinit(void);
|
||||
|
||||
static int InitParamClient(void)
|
||||
{
|
||||
if (getpid() == 1) {
|
||||
PARAM_LOGI("Init process, do not init client");
|
||||
return 0;
|
||||
}
|
||||
if (PARAM_TEST_FLAG(g_clientSpace.flags, WORKSPACE_FLAGS_INIT)) {
|
||||
return 0;
|
||||
}
|
||||
PARAM_LOGV("InitParamClient");
|
||||
#ifdef __LITEOS_M__
|
||||
int ret = InitParamWorkSpace(0);
|
||||
#else
|
||||
int ret = InitParamWorkSpace(1);
|
||||
#endif
|
||||
PARAM_LOGV("InitParamClient");
|
||||
PARAM_CHECK(ret == 0, return -1, "Failed to init param workspace");
|
||||
PARAM_SET_FLAG(g_clientSpace.flags, WORKSPACE_FLAGS_INIT);
|
||||
// init persist to save
|
||||
@ -48,6 +48,7 @@ static int InitParamClient(void)
|
||||
}
|
||||
#endif
|
||||
#ifdef __LITEOS_M__
|
||||
LoadParamFromBuild();
|
||||
// get persist param
|
||||
LoadPersistParams();
|
||||
#endif
|
||||
@ -133,4 +134,21 @@ int SystemWaitParameter(const char *name, const char *value, int32_t timeout)
|
||||
int WatchParamCheck(const char *keyprefix)
|
||||
{
|
||||
return PARAM_CODE_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
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) {
|
||||
PARAM_CHECK(ret == 0, return ret, "Forbid to access parameter %s", name);
|
||||
}
|
||||
return ret;
|
||||
}
|
163
services/param/liteos/param_hal.c
Executable file
163
services/param/liteos/param_hal.c
Executable file
@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "init_utils.h"
|
||||
#include "param_manager.h"
|
||||
#include "param_persist.h"
|
||||
#include "param_utils.h"
|
||||
#include "securec.h"
|
||||
#include "utils_file.h"
|
||||
|
||||
// for linux, no mutex
|
||||
static ParamMutex g_saveMutex = {};
|
||||
|
||||
static int LoadOnePersistParam_(const uint32_t *context, const char *name, const char *value)
|
||||
{
|
||||
uint32_t dataIndex = 0;
|
||||
int ret = WriteParam(name, value, &dataIndex, 0);
|
||||
PARAM_CHECK(ret == 0, return ret, "Failed to write param %d name:%s %s", ret, name, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int LoadPersistParam(void)
|
||||
{
|
||||
const char *path = PARAM_PERSIST_SAVE_TMP_PATH;
|
||||
CheckAndCreateDir(path);
|
||||
char *buffer = NULL;
|
||||
int fd = -1;
|
||||
uint32_t paramNum = 0;
|
||||
do {
|
||||
fd = UtilsFileOpen(path, O_RDONLY_FS, 0);
|
||||
if (fd < 0) {
|
||||
path = PARAM_PERSIST_SAVE_PATH;
|
||||
fd = UtilsFileOpen(path, O_RDONLY_FS, 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);
|
||||
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);
|
||||
PARAM_CHECK(ret == 0, break, "Failed to get read file %s", path);
|
||||
|
||||
uint32_t currLen = 0;
|
||||
while (currLen < fileSize) {
|
||||
if (buffer[currLen] == '\n') { // splite line
|
||||
buffer[currLen] = '\0';
|
||||
int ret = SpliteString(buffer, NULL, 0, LoadOnePersistParam_, NULL);
|
||||
PARAM_CHECK(ret == 0, continue, "Failed to set param %d %s", ret, buffer);
|
||||
paramNum++;
|
||||
}
|
||||
currLen++;
|
||||
}
|
||||
} while (0);
|
||||
if (fd > 0) {
|
||||
UtilsFileClose(fd);
|
||||
}
|
||||
if (buffer != NULL) {
|
||||
free(buffer);
|
||||
}
|
||||
PARAM_LOGI("LoadPersistParam from file %s paramNum %d", path, paramNum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int PersistWrite(int fd, const char *name, const char *value)
|
||||
{
|
||||
int ret = UtilsFileWrite(fd, name, strlen(name));
|
||||
if (ret <= 0) {
|
||||
PARAM_LOGE("Failed to save persist param %s", name);
|
||||
}
|
||||
ret = UtilsFileWrite(fd, "=", strlen("="));
|
||||
if (ret <= 0) {
|
||||
PARAM_LOGE("Failed to save persist param %s", name);
|
||||
}
|
||||
ret = UtilsFileWrite(fd, value, strlen(value));
|
||||
if (ret <= 0) {
|
||||
PARAM_LOGE("Failed to save persist param %s", name);
|
||||
}
|
||||
ret = UtilsFileWrite(fd, "\n", strlen("\n"));
|
||||
if (ret <= 0) {
|
||||
PARAM_LOGE("Failed to save persist param %s", name);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
if (fd > 0) {
|
||||
ret = PersistWrite(fd, name, value);
|
||||
UtilsFileClose(fd);
|
||||
}
|
||||
ParamMutexPost(&g_saveMutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
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);
|
||||
if (fd < 0) {
|
||||
ParamMutexPost(&g_saveMutex);
|
||||
PARAM_LOGE("Open file %s fail error %d", PARAM_PERSIST_SAVE_TMP_PATH, errno);
|
||||
return -1;
|
||||
}
|
||||
*handle = (PERSIST_SAVE_HANDLE)fd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int BatchSavePersistParam(PERSIST_SAVE_HANDLE handle, const char *name, const char *value)
|
||||
{
|
||||
int fd = (int)handle;
|
||||
int ret = PersistWrite(fd, name, value);
|
||||
PARAM_CHECK(ret == 0, return -1, "Failed to write param %s", name);
|
||||
PARAM_LOGV("BatchSavePersistParam %s=%s", name, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
ParamMutexPost(&g_saveMutex);
|
||||
PARAM_CHECK(ret == 0, return, "BatchSavePersistParamEnd %s fail error %d", PARAM_PERSIST_SAVE_TMP_PATH, errno);
|
||||
}
|
||||
|
||||
int RegisterPersistParamOps(PersistParamOps *ops)
|
||||
{
|
||||
PARAM_LOGI("RegisterPersistParamOps");
|
||||
ParamMutexCeate(&g_saveMutex);
|
||||
PARAM_CHECK(ops != NULL, return -1, "Invalid ops");
|
||||
ops->save = SavePersistParam;
|
||||
ops->load = LoadPersistParam;
|
||||
ops->batchSaveBegin = BatchSavePersistParamBegin;
|
||||
ops->batchSave = BatchSavePersistParam;
|
||||
ops->batchSaveEnd = BatchSavePersistParamEnd;
|
||||
return 0;
|
||||
}
|
@ -17,9 +17,13 @@
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
#ifdef __LITEOS_A__
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/shm.h>
|
||||
#else
|
||||
#include "los_task.h"
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
@ -27,6 +31,8 @@
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "param_security.h"
|
||||
|
||||
#define NSEC_PER_MSEC 1000000LL
|
||||
#define MSEC_PER_SEC 1000LL
|
||||
|
||||
@ -86,12 +92,9 @@ int ParamTimerStart(const ParamTaskPtr timer, uint64_t timeout, uint64_t repeat)
|
||||
{
|
||||
PARAM_CHECK(timer != NULL, return -1, "Invalid timer");
|
||||
ParamTimer *paramTimer = (ParamTimer *)timer;
|
||||
PARAM_LOGE("ParamTimerStart timeout %llu ", timeout);
|
||||
PARAM_LOGV("ParamTimerStart timeout %llu ", timeout);
|
||||
int32_t ret = StartTimer(paramTimer, timeout, repeat);
|
||||
if (ret < 0) {
|
||||
PARAM_LOGE("Failed to start timer");
|
||||
return -1;
|
||||
}
|
||||
PARAM_CHECK(ret >= 0, return -1, "Failed to start timer");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -132,6 +135,11 @@ void FreeSharedMem(const MemHandle *handle, void *mem, uint32_t dataSize)
|
||||
shmctl(handle->shmid, IPC_RMID, NULL);
|
||||
}
|
||||
|
||||
void paramMutexEnvInit(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int ParamRWMutexCreate(ParamRWMutex *lock)
|
||||
{
|
||||
PARAM_CHECK(lock != NULL, return -1, "Invalid lock");
|
||||
@ -221,6 +229,13 @@ void FreeSharedMem(const MemHandle *handle, void *mem, uint32_t dataSize)
|
||||
free(mem);
|
||||
}
|
||||
|
||||
void paramMutexEnvInit(void)
|
||||
{
|
||||
uint32_t ret = OsMuxInit();
|
||||
PARAM_CHECK(ret == LOS_OK, return, "Failed to init mutex ret %d", ret);
|
||||
return;
|
||||
}
|
||||
|
||||
int ParamRWMutexCreate(ParamRWMutex *lock)
|
||||
{
|
||||
PARAM_CHECK(lock != NULL, return -1, "Invalid lock");
|
||||
@ -232,32 +247,32 @@ int ParamRWMutexCreate(ParamRWMutex *lock)
|
||||
int ParamRWMutexWRLock(ParamRWMutex *lock)
|
||||
{
|
||||
PARAM_CHECK(lock != NULL, return -1, "Invalid lock");
|
||||
uint32_t ret = LOS_MuxPend(&lock->mutex, LOS_WAIT_FOREVER);
|
||||
PARAM_CHECK(ret == LOS_OK, return -1, "Failed to mutex lock ret %d", ret);
|
||||
uint32_t ret = LOS_MuxPend(lock->mutex, LOS_WAIT_FOREVER);
|
||||
PARAM_CHECK(ret == LOS_OK, return -1, "Failed to mutex lock ret %d %d", ret, lock->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ParamRWMutexRDLock(ParamRWMutex *lock)
|
||||
{
|
||||
PARAM_CHECK(lock != NULL, return -1, "Invalid lock");
|
||||
uint32_t ret = LOS_MuxPend(&lock->mutex, LOS_WAIT_FOREVER);
|
||||
PARAM_CHECK(ret == LOS_OK, return -1, "Failed to mutex lock ret %d", ret);
|
||||
uint32_t ret = LOS_MuxPend(lock->mutex, LOS_WAIT_FOREVER);
|
||||
PARAM_CHECK(ret == LOS_OK, return -1, "Failed to mutex lock ret %d %d", ret, lock->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ParamRWMutexUnlock(ParamRWMutex *lock)
|
||||
{
|
||||
PARAM_CHECK(lock != NULL, return -1, "Invalid lock");
|
||||
uint32_t ret = LOS_MuxPost(&lock->mutex);
|
||||
PARAM_CHECK(ret == LOS_OK, return -1, "Failed to mutex lock ret %d", ret);
|
||||
uint32_t ret = LOS_MuxPost(lock->mutex);
|
||||
PARAM_CHECK(ret == LOS_OK, return -1, "Failed to mutex lock ret %d %d", ret, lock->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ParamRWMutexDelete(ParamRWMutex *lock)
|
||||
{
|
||||
PARAM_CHECK(lock != NULL, return -1, "Invalid lock");
|
||||
uint32_t ret = LOS_MuxDelete(&lock->mutex);
|
||||
PARAM_CHECK(ret == LOS_OK, return -1, "Failed to mutex lock ret %d", ret);
|
||||
uint32_t ret = LOS_MuxDelete(lock->mutex);
|
||||
PARAM_CHECK(ret == LOS_OK, return -1, "Failed to mutex lock ret %d %d", ret, lock->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -272,24 +287,102 @@ int ParamMutexCeate(ParamMutex *mutex)
|
||||
int ParamMutexPend(ParamMutex *mutex)
|
||||
{
|
||||
PARAM_CHECK(mutex != NULL, return -1, "Invalid lock");
|
||||
uint32_t ret = LOS_MuxPend(&mutex->mutex, LOS_WAIT_FOREVER);
|
||||
PARAM_CHECK(ret == LOS_OK, return -1, "Failed to mutex lock ret %d", ret);
|
||||
uint32_t ret = LOS_MuxPend(mutex->mutex, LOS_WAIT_FOREVER);
|
||||
PARAM_CHECK(ret == LOS_OK, return -1, "Failed to mutex lock ret %d %d", ret, mutex->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ParamMutexPost(ParamMutex *mutex)
|
||||
{
|
||||
PARAM_CHECK(mutex != NULL, return -1, "Invalid lock");
|
||||
uint32_t ret = LOS_MuxPost(&mutex->mutex);
|
||||
PARAM_CHECK(ret == LOS_OK, return -1, "Failed to mutex lock ret %d", ret);
|
||||
uint32_t ret = LOS_MuxPost(mutex->mutex);
|
||||
PARAM_CHECK(ret == LOS_OK, return -1, "Failed to mutex lockret %d %d", ret, mutex->mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ParamMutexDelete(ParamMutex *mutex)
|
||||
{
|
||||
PARAM_CHECK(mutex != NULL, return -1, "Invalid mutex");
|
||||
uint32_t ret = LOS_MuxDelete(&mutex->mutex);
|
||||
PARAM_CHECK(ret == LOS_OK, return -1, "Failed to delete mutex lock ret %d", ret);
|
||||
uint32_t ret = LOS_MuxDelete(mutex->mutex);
|
||||
PARAM_CHECK(ret == LOS_OK, return -1, "Failed to delete mutex lock ret %d %d", ret, mutex->mutex);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef STARTUP_INIT_TEST
|
||||
static int InitLocalSecurityLabel(ParamSecurityLabel *security, int isInit)
|
||||
{
|
||||
UNUSED(isInit);
|
||||
PARAM_CHECK(security != NULL, return -1, "Invalid security");
|
||||
#if defined __LITEOS_A__
|
||||
security->cred.pid = getpid();
|
||||
security->cred.uid = getuid();
|
||||
security->cred.gid = 0;
|
||||
#else
|
||||
security->cred.pid = 0;
|
||||
security->cred.uid = 0;
|
||||
security->cred.gid = 0;
|
||||
#endif
|
||||
security->flags[PARAM_SECURITY_DAC] |= LABEL_CHECK_IN_ALL_PROCESS;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int FreeLocalSecurityLabel(ParamSecurityLabel *srcLabel)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DacGetParamSecurityLabel(const char *path)
|
||||
{
|
||||
UNUSED(path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int CheckFilePermission(const ParamSecurityLabel *localLabel, const char *fileName, int flags)
|
||||
{
|
||||
UNUSED(flags);
|
||||
PARAM_CHECK(localLabel != NULL && fileName != NULL, return -1, "Invalid param");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int DacCheckParamPermission(const ParamSecurityLabel *srcLabel, const char *name, uint32_t mode)
|
||||
{
|
||||
#if defined(__LITEOS_A__)
|
||||
uid_t uid = getuid();
|
||||
return uid <= SYS_UID_INDEX ? DAC_RESULT_PERMISSION : DAC_RESULT_FORBIDED;
|
||||
#endif
|
||||
#if defined(__LITEOS_M__)
|
||||
return DAC_RESULT_PERMISSION;
|
||||
#endif
|
||||
return DAC_RESULT_PERMISSION;
|
||||
}
|
||||
|
||||
int RegisterSecurityDacOps(ParamSecurityOps *ops, int isInit)
|
||||
{
|
||||
PARAM_CHECK(ops != NULL, return -1, "Invalid param");
|
||||
PARAM_LOGV("RegisterSecurityDacOps %d", isInit);
|
||||
int ret = strcpy_s(ops->name, sizeof(ops->name), "dac");
|
||||
ops->securityGetLabel = NULL;
|
||||
ops->securityInitLabel = InitLocalSecurityLabel;
|
||||
ops->securityCheckFilePermission = CheckFilePermission;
|
||||
ops->securityCheckParamPermission = DacCheckParamPermission;
|
||||
ops->securityFreeLabel = FreeLocalSecurityLabel;
|
||||
if (isInit) {
|
||||
ops->securityGetLabel = DacGetParamSecurityLabel;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void LoadGroupUser(void)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t Difftime(time_t curr, time_t base)
|
||||
{
|
||||
#ifndef __LITEOS_M__
|
||||
return (uint32_t)difftime(curr, base);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
@ -25,8 +25,9 @@ void InitParamService(void)
|
||||
PARAM_CHECK(ret == 0, return, "Init parameter workspace fail");
|
||||
ret = InitPersistParamWorkSpace();
|
||||
PARAM_CHECK(ret == 0, return, "Init persist parameter workspace fail");
|
||||
// read cmd to param
|
||||
LoadParamFromCmdLine();
|
||||
|
||||
// from build
|
||||
LoadParamFromBuild();
|
||||
}
|
||||
|
||||
int StartParamService(void)
|
||||
|
@ -69,7 +69,6 @@ static ParamHandle GetParamHandle(const WorkSpace *workSpace, uint32_t index, co
|
||||
uint32_t hashCode = (uint32_t)GenerateKeyHasCode(workSpace->fileName, strlen(workSpace->fileName));
|
||||
uint32_t handle = (hashCode % HASH_BUTT) << 24; // 24 left shift
|
||||
handle = handle | (index + workSpace->area->startIndex);
|
||||
PARAM_LOGV("GetParamHandle handle 0x%x index %u, name %s space %p", handle, index, name, workSpace);
|
||||
return handle;
|
||||
}
|
||||
|
||||
@ -121,10 +120,7 @@ int InitParamWorkSpace(int onlyRead)
|
||||
if (PARAM_TEST_FLAG(g_paramWorkSpace.flags, WORKSPACE_FLAGS_INIT)) {
|
||||
return 0;
|
||||
}
|
||||
g_paramWorkSpace.securityLabel.cred.pid = getpid();
|
||||
g_paramWorkSpace.securityLabel.cred.uid = geteuid();
|
||||
g_paramWorkSpace.securityLabel.cred.gid = getegid();
|
||||
|
||||
paramMutexEnvInit();
|
||||
HashInfo info = {
|
||||
WorkSpaceNodeCompare,
|
||||
WorkSpaceKeyCompare,
|
||||
@ -186,10 +182,10 @@ void CloseParamWorkSpace(void)
|
||||
|
||||
static uint32_t ReadCommitId(ParamNode *entry)
|
||||
{
|
||||
uint32_t commitId = atomic_load_explicit(&entry->commitId, memory_order_acquire);
|
||||
uint32_t commitId = ATOMIC_LOAD_EXPLICIT(&entry->commitId, memory_order_acquire);
|
||||
while (commitId & PARAM_FLAGS_MODIFY) {
|
||||
futex_wait(&entry->commitId, commitId);
|
||||
commitId = atomic_load_explicit(&entry->commitId, memory_order_acquire);
|
||||
commitId = ATOMIC_LOAD_EXPLICIT(&entry->commitId, memory_order_acquire);
|
||||
}
|
||||
return commitId & PARAM_FLAGS_COMMITID;
|
||||
}
|
||||
@ -336,13 +332,13 @@ static int AddParam(WorkSpace *workSpace, const char *name, const char *value, u
|
||||
uint32_t offset = AddParamNode(workSpace, name, strlen(name), value, strlen(value));
|
||||
PARAM_CHECK(offset > 0, return PARAM_CODE_REACHED_MAX, "Failed to allocate name %s", name);
|
||||
SaveIndex(&node->dataIndex, offset);
|
||||
long long globalCommitId = atomic_load_explicit(&workSpace->area->commitId, memory_order_relaxed);
|
||||
atomic_store_explicit(&workSpace->area->commitId, ++globalCommitId, memory_order_release);
|
||||
long long globalCommitId = ATOMIC_LOAD_EXPLICIT(&workSpace->area->commitId, memory_order_relaxed);
|
||||
ATOMIC_STORE_EXPLICIT(&workSpace->area->commitId, ++globalCommitId, memory_order_release);
|
||||
#ifdef PARAM_SUPPORT_SELINUX
|
||||
WorkSpace *space = GetWorkSpace(WORKSPACE_NAME_DAC);
|
||||
if (space != workSpace) { // dac commit is global commit
|
||||
globalCommitId = atomic_load_explicit(&space->area->commitId, memory_order_relaxed);
|
||||
atomic_store_explicit(&space->area->commitId, ++globalCommitId, memory_order_release);
|
||||
globalCommitId = ATOMIC_LOAD_EXPLICIT(&space->area->commitId, memory_order_relaxed);
|
||||
ATOMIC_STORE_EXPLICIT(&space->area->commitId, ++globalCommitId, memory_order_release);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -360,22 +356,22 @@ static int UpdateParam(const WorkSpace *workSpace, uint32_t *dataIndex, const ch
|
||||
PARAM_CHECK(entry->keyLength == strlen(name), return PARAM_CODE_INVALID_NAME, "Failed to check name len %s", name);
|
||||
|
||||
uint32_t valueLen = strlen(value);
|
||||
uint32_t commitId = atomic_load_explicit(&entry->commitId, memory_order_relaxed);
|
||||
atomic_store_explicit(&entry->commitId, commitId | PARAM_FLAGS_MODIFY, memory_order_relaxed);
|
||||
long long globalCommitId = atomic_load_explicit(&workSpace->area->commitId, memory_order_relaxed);
|
||||
uint32_t commitId = ATOMIC_LOAD_EXPLICIT(&entry->commitId, memory_order_relaxed);
|
||||
ATOMIC_STORE_EXPLICIT(&entry->commitId, commitId | PARAM_FLAGS_MODIFY, memory_order_relaxed);
|
||||
long long globalCommitId = ATOMIC_LOAD_EXPLICIT(&workSpace->area->commitId, memory_order_relaxed);
|
||||
if (entry->valueLength < PARAM_VALUE_LEN_MAX && valueLen < PARAM_VALUE_LEN_MAX) {
|
||||
int ret = memcpy_s(entry->data + entry->keyLength + 1, PARAM_VALUE_LEN_MAX, value, valueLen + 1);
|
||||
PARAM_CHECK(ret == EOK, return PARAM_CODE_INVALID_VALUE, "Failed to copy value");
|
||||
entry->valueLength = valueLen;
|
||||
}
|
||||
uint32_t flags = commitId & ~PARAM_FLAGS_COMMITID;
|
||||
atomic_store_explicit(&entry->commitId, (++commitId) | flags, memory_order_release);
|
||||
atomic_store_explicit(&workSpace->area->commitId, ++globalCommitId, memory_order_release);
|
||||
ATOMIC_STORE_EXPLICIT(&entry->commitId, (++commitId) | flags, memory_order_release);
|
||||
ATOMIC_STORE_EXPLICIT(&workSpace->area->commitId, ++globalCommitId, memory_order_release);
|
||||
#ifdef PARAM_SUPPORT_SELINUX
|
||||
WorkSpace *space = GetWorkSpace(WORKSPACE_NAME_DAC);
|
||||
if (space != workSpace) { // dac commit is global commit
|
||||
globalCommitId = atomic_load_explicit(&space->area->commitId, memory_order_relaxed);
|
||||
atomic_store_explicit(&space->area->commitId, ++globalCommitId, memory_order_release);
|
||||
globalCommitId = ATOMIC_LOAD_EXPLICIT(&space->area->commitId, memory_order_relaxed);
|
||||
ATOMIC_STORE_EXPLICIT(&space->area->commitId, ++globalCommitId, memory_order_release);
|
||||
}
|
||||
#endif
|
||||
PARAM_LOGV("UpdateParam name %s value: %s", name, value);
|
||||
@ -434,12 +430,12 @@ int AddSecurityLabel(const ParamAuditData *auditData)
|
||||
SaveIndex(&node->labelIndex, offset);
|
||||
} else {
|
||||
#ifdef STARTUP_INIT_TEST
|
||||
ParamSecruityNode *label = (ParamSecruityNode *)GetTrieNode(workSpace, node->labelIndex);
|
||||
ParamSecurityNode *label = (ParamSecurityNode *)GetTrieNode(workSpace, node->labelIndex);
|
||||
label->mode = auditData->dacData.mode;
|
||||
label->uid = auditData->dacData.uid;
|
||||
label->gid = auditData->dacData.gid;
|
||||
#endif
|
||||
PARAM_LOGE("Error, repeate to add label for name %s", auditData->name);
|
||||
PARAM_LOGE("Error, repeat to add label for name %s", auditData->name);
|
||||
}
|
||||
PARAM_LOGV("AddSecurityLabel label %d gid %d uid %d mode %o name: %s", offset,
|
||||
auditData->dacData.gid, auditData->dacData.uid, auditData->dacData.mode, auditData->name);
|
||||
@ -463,8 +459,8 @@ ParamNode *SystemCheckMatchParamWait(const char *name, const char *value)
|
||||
if ((param->keyLength != nameLength) || (strncmp(param->data, name, nameLength) != 0)) { // compare name
|
||||
return NULL;
|
||||
}
|
||||
atomic_store_explicit(¶m->commitId,
|
||||
atomic_load_explicit(¶m->commitId, memory_order_relaxed) | PARAM_FLAGS_WAITED, memory_order_release);
|
||||
ATOMIC_STORE_EXPLICIT(¶m->commitId,
|
||||
ATOMIC_LOAD_EXPLICIT(¶m->commitId, memory_order_relaxed) | PARAM_FLAGS_WAITED, memory_order_release);
|
||||
if ((strncmp(value, "*", 1) == 0) || (strcmp(param->data + nameLength + 1, value) == 0)) { // compare value
|
||||
return param;
|
||||
}
|
||||
@ -513,10 +509,9 @@ int SystemTraversalParameter(const char *prefix, TraversalParamPtr traversalPara
|
||||
context.prefix = (char *)prefix;
|
||||
}
|
||||
#ifdef PARAM_SUPPORT_SELINUX
|
||||
// open all workspace
|
||||
OpenPermissionWorkSpace();
|
||||
#endif
|
||||
WorkSpace *workSpace = GetFristWorkSpace();
|
||||
WorkSpace *workSpace = GetFirstWorkSpace();
|
||||
if (workSpace != NULL && strcmp(workSpace->fileName, WORKSPACE_NAME_DAC) == 0) {
|
||||
workSpace = GetNextWorkSpace(workSpace);
|
||||
}
|
||||
@ -580,7 +575,7 @@ static int DumpTrieDataNodeTraversal(const WorkSpace *workSpace, const ParamTrie
|
||||
}
|
||||
}
|
||||
if (current->labelIndex != 0 && verbose) {
|
||||
ParamSecruityNode *label = (ParamSecruityNode *)GetTrieNode(workSpace, current->labelIndex);
|
||||
ParamSecurityNode *label = (ParamSecurityNode *)GetTrieNode(workSpace, current->labelIndex);
|
||||
if (label != NULL) {
|
||||
PARAM_DUMP("\tparameter label dac %d %d %o \n\t label: %s \n",
|
||||
label->uid, label->gid, label->mode, (label->length > 0) ? label->data : "null");
|
||||
@ -627,7 +622,7 @@ void SystemDumpParameters(int verbose)
|
||||
g_paramWorkSpace.securityLabel.cred.uid,
|
||||
g_paramWorkSpace.securityLabel.cred.gid);
|
||||
}
|
||||
WorkSpace *workSpace = GetFristWorkSpace();
|
||||
WorkSpace *workSpace = GetFirstWorkSpace();
|
||||
while (workSpace != NULL) {
|
||||
WorkSpace *next = GetNextWorkSpace(workSpace);
|
||||
HashNodeTraverseForDump(workSpace, verbose);
|
||||
@ -735,7 +730,7 @@ ParamTrieNode *GetTrieNodeByHandle(ParamHandle handle)
|
||||
return (ParamTrieNode *)GetTrieNode(workSpace, index);
|
||||
}
|
||||
|
||||
WorkSpace *GetFristWorkSpace(void)
|
||||
WorkSpace *GetFirstWorkSpace(void)
|
||||
{
|
||||
WorkSpace *workSpace = NULL;
|
||||
WORKSPACE_RD_LOCK(g_paramWorkSpace);
|
||||
@ -760,7 +755,7 @@ WorkSpace *GetNextWorkSpace(WorkSpace *curr)
|
||||
return workSpace;
|
||||
}
|
||||
|
||||
int SystemReadParam(const char *name, char *value, unsigned int *len)
|
||||
int SystemReadParam(const char *name, char *value, uint32_t *len)
|
||||
{
|
||||
PARAM_WORKSPACE_CHECK(&g_paramWorkSpace, return -1, "Invalid space");
|
||||
PARAM_CHECK(name != NULL && len != NULL && strlen(name) > 0, return -1, "The name or value is null");
|
||||
@ -772,17 +767,6 @@ int SystemReadParam(const char *name, char *value, unsigned int *len)
|
||||
return ReadParamValue(handle, value, len);
|
||||
}
|
||||
|
||||
int SystemFindParameter(const char *name, ParamHandle *handle)
|
||||
{
|
||||
PARAM_WORKSPACE_CHECK(&g_paramWorkSpace, return -1, "Invalid space");
|
||||
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) {
|
||||
PARAM_CHECK(ret == 0, return ret, "Forbid to access parameter %s", name);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SysCheckParamExist(const char *name)
|
||||
{
|
||||
PARAM_WORKSPACE_CHECK(&g_paramWorkSpace, return -1, "Invalid space");
|
||||
@ -791,7 +775,7 @@ int SysCheckParamExist(const char *name)
|
||||
// open all workspace
|
||||
OpenPermissionWorkSpace();
|
||||
#endif
|
||||
WorkSpace *workSpace = GetFristWorkSpace();
|
||||
WorkSpace *workSpace = GetFirstWorkSpace();
|
||||
while (workSpace != NULL) {
|
||||
PARAM_LOGV("SysCheckParamExist name %s in space %s", name, workSpace->fileName);
|
||||
WorkSpace *next = GetNextWorkSpace(workSpace);
|
||||
@ -820,7 +804,7 @@ long long GetSystemCommitId(void)
|
||||
if (space == NULL || space->area == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return atomic_load_explicit(&space->area->commitId, memory_order_acquire);
|
||||
return ATOMIC_LOAD_EXPLICIT(&space->area->commitId, memory_order_acquire);
|
||||
}
|
||||
|
||||
int SystemGetParameterName(ParamHandle handle, char *name, unsigned int len)
|
||||
@ -845,7 +829,7 @@ int GetParamSecurityAuditData(const char *name, int type, ParamAuditData *auditD
|
||||
WorkSpace *space = GetWorkSpace(WORKSPACE_NAME_DAC);
|
||||
PARAM_CHECK(space != NULL, return -1, "Invalid workSpace");
|
||||
FindTrieNode(space, name, strlen(name), &labelIndex);
|
||||
ParamSecruityNode *node = (ParamSecruityNode *)GetTrieNode(space, labelIndex);
|
||||
ParamSecurityNode *node = (ParamSecurityNode *)GetTrieNode(space, labelIndex);
|
||||
PARAM_CHECK(node != NULL, return DAC_RESULT_FORBIDED, "Can not get security label %d", labelIndex);
|
||||
|
||||
auditData->name = name;
|
||||
@ -873,6 +857,7 @@ int CheckParameterSet(const char *name, const char *value, const ParamSecurityLa
|
||||
PARAM_CHECK(ret == 0, return ret, "Illegal param value %s", value);
|
||||
*ctrlService = 0;
|
||||
|
||||
#ifndef __LITEOS_M__
|
||||
if (getpid() != 1) { // none init
|
||||
#ifdef PARAM_SUPPORT_SELINUX
|
||||
*ctrlService |= PARAM_NEED_CHECK_IN_SERVICE;
|
||||
@ -884,7 +869,7 @@ int CheckParameterSet(const char *name, const char *value, const ParamSecurityLa
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
char *key = GetServiceCtrlName(name, value);
|
||||
ret = CheckParamPermission(srcLabel, (key == NULL) ? name : key, DAC_WRITE);
|
||||
if (key != NULL) { // ctrl param
|
||||
@ -932,7 +917,7 @@ long long GetPersistCommitId(void)
|
||||
if (space == NULL || space->area == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return atomic_load_explicit(&space->area->commitPersistId, memory_order_acquire);
|
||||
return ATOMIC_LOAD_EXPLICIT(&space->area->commitPersistId, memory_order_acquire);
|
||||
}
|
||||
|
||||
void UpdatePersistCommitId(void)
|
||||
@ -942,8 +927,8 @@ void UpdatePersistCommitId(void)
|
||||
if (space == NULL || space->area == NULL) {
|
||||
return;
|
||||
}
|
||||
long long globalCommitId = atomic_load_explicit(&space->area->commitPersistId, memory_order_relaxed);
|
||||
atomic_store_explicit(&space->area->commitPersistId, ++globalCommitId, memory_order_release);
|
||||
long long globalCommitId = ATOMIC_LOAD_EXPLICIT(&space->area->commitPersistId, memory_order_relaxed);
|
||||
ATOMIC_STORE_EXPLICIT(&space->area->commitPersistId, ++globalCommitId, memory_order_release);
|
||||
}
|
||||
|
||||
#if defined STARTUP_INIT_TEST || defined LOCAL_TEST
|
||||
|
@ -25,6 +25,14 @@
|
||||
#include "param_trie.h"
|
||||
|
||||
static ParamPersistWorkSpace g_persistWorkSpace = {0, 0, NULL, 0, {}};
|
||||
static int IsNeedToSave(const char *name)
|
||||
{
|
||||
#if defined(__LITEOS_M__) || defined(__LITEOS_A__)
|
||||
return IS_READY_ONLY(name) ? 0 : 1;
|
||||
#else
|
||||
return (strncmp(name, PARAM_PERSIST_PREFIX, strlen(PARAM_PERSIST_PREFIX)) == 0) ? 1 : 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int SavePersistParam(const WorkSpace *workSpace, const ParamTrieNode *node, const void *cookie)
|
||||
{
|
||||
@ -36,7 +44,8 @@ static int SavePersistParam(const WorkSpace *workSpace, const ParamTrieNode *nod
|
||||
if (entry == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (strncmp(entry->data, PARAM_PERSIST_PREFIX, strlen(PARAM_PERSIST_PREFIX)) != 0) {
|
||||
|
||||
if (!IsNeedToSave(entry->data)) {
|
||||
return 0;
|
||||
}
|
||||
static char name[PARAM_NAME_LEN_MAX] = {0};
|
||||
@ -61,11 +70,16 @@ static int BatchSavePersistParam()
|
||||
PERSIST_SAVE_HANDLE handle;
|
||||
int ret = g_persistWorkSpace.persistParamOps.batchSaveBegin(&handle);
|
||||
PARAM_CHECK(ret == 0, return PARAM_CODE_INVALID_NAME, "Failed to save persist");
|
||||
#if defined(__LITEOS_M__) || defined(__LITEOS_A__)
|
||||
const char *prefix = "";
|
||||
#else
|
||||
const char *prefix = PARAM_PERSIST_PREFIX;
|
||||
#endif
|
||||
// walk and save persist param
|
||||
WorkSpace *workSpace = GetFristWorkSpace();
|
||||
WorkSpace *workSpace = GetFirstWorkSpace();
|
||||
while (workSpace != NULL) {
|
||||
WorkSpace *next = GetNextWorkSpace(workSpace);
|
||||
ParamTrieNode *root = FindTrieNode(workSpace, PARAM_PERSIST_PREFIX, strlen(PARAM_PERSIST_PREFIX), NULL);
|
||||
ParamTrieNode *root = FindTrieNode(workSpace, prefix, strlen(prefix), NULL);
|
||||
PARAMSPACE_AREA_RD_LOCK(workSpace);
|
||||
TraversalTrieNode(workSpace, root, SavePersistParam, (void *)handle);
|
||||
PARAMSPACE_AREA_RW_UNLOCK(workSpace);
|
||||
@ -112,7 +126,7 @@ PARAM_STATIC void TimerCallbackForSave(const ParamTaskPtr timer, void *context)
|
||||
#else
|
||||
// check commit
|
||||
long long commit = GetPersistCommitId();
|
||||
PARAM_LOGV("TimerCallbackForSave commit %lld ", commit);
|
||||
PARAM_LOGV("TimerCallbackForSave commit %lld %lld", commit, g_persistWorkSpace.commitId);
|
||||
if (g_persistWorkSpace.commitId == commit) {
|
||||
return;
|
||||
}
|
||||
@ -124,7 +138,7 @@ PARAM_STATIC void TimerCallbackForSave(const ParamTaskPtr timer, void *context)
|
||||
int WritePersistParam(const char *name, const char *value)
|
||||
{
|
||||
PARAM_CHECK(value != NULL && name != NULL, return PARAM_CODE_INVALID_PARAM, "Invalid param");
|
||||
if (strncmp(name, PARAM_PERSIST_PREFIX, strlen(PARAM_PERSIST_PREFIX)) != 0) {
|
||||
if (!IsNeedToSave(name)) {
|
||||
return 0;
|
||||
}
|
||||
PARAM_LOGV("WritePersistParam name %s ", name);
|
||||
@ -145,7 +159,7 @@ int WritePersistParam(const char *name, const char *value)
|
||||
// check timer for save all
|
||||
time_t currTimer;
|
||||
(void)time(&currTimer);
|
||||
uint32_t diff = (uint32_t)difftime(currTimer, g_persistWorkSpace.lastSaveTimer);
|
||||
uint32_t diff = Difftime(currTimer, g_persistWorkSpace.lastSaveTimer);
|
||||
if (diff > PARAM_MUST_SAVE_PARAM_DIFF) {
|
||||
if (g_persistWorkSpace.saveTimer != NULL) {
|
||||
ParamTimerClose(g_persistWorkSpace.saveTimer);
|
||||
@ -319,7 +333,7 @@ static int ProcessParamFile(const char *fileName, void *context)
|
||||
|
||||
int LoadDefaultParams(const char *fileName, uint32_t mode)
|
||||
{
|
||||
PARAM_CHECK(fileName != NULL, return -1, "Invalid fielname for load");
|
||||
PARAM_CHECK(fileName != NULL, return -1, "Invalid filename for load");
|
||||
PARAM_LOGI("load default parameters %s.", fileName);
|
||||
int ret = 0;
|
||||
struct stat st;
|
||||
@ -333,23 +347,24 @@ int LoadDefaultParams(const char *fileName, uint32_t mode)
|
||||
return LoadSecurityLabel(fileName);
|
||||
}
|
||||
|
||||
static void LoadBuildParameter(void)
|
||||
void LoadParamFromBuild(void)
|
||||
{
|
||||
// load dynamic parameter
|
||||
PARAM_LOGI("load parameters from build ");
|
||||
#ifdef INCREMENTAL_VERSION
|
||||
WriteParam(name, value, NULL, LOAD_PARAM_NORMAL);
|
||||
WriteParam("const.product.incremental.version", INCREMENTAL_VERSION, NULL, LOAD_PARAM_NORMAL);
|
||||
#endif
|
||||
#ifdef BUILD_TYPE
|
||||
WriteParam(name, BUILD_TYPE, NULL, LOAD_PARAM_NORMAL);
|
||||
WriteParam("const.product.build.type", BUILD_TYPE, NULL, LOAD_PARAM_NORMAL);
|
||||
#endif
|
||||
#ifdef BUILD_USER
|
||||
WriteParam(name, BUILD_USER, NULL, LOAD_PARAM_NORMAL);
|
||||
WriteParam("const.product.build.user", BUILD_USER, NULL, LOAD_PARAM_NORMAL);
|
||||
#endif
|
||||
#ifdef BUILD_TIME
|
||||
WriteParam(name, BUILD_TIME, NULL, LOAD_PARAM_NORMAL);
|
||||
PARAM_LOGI("const.product.build.date %s", BUILD_TIME);
|
||||
WriteParam("const.product.build.date", BUILD_TIME, NULL, LOAD_PARAM_NORMAL);
|
||||
#endif
|
||||
#ifdef BUILD_HOST
|
||||
WriteParam(name, BUILD_HOST, NULL, LOAD_PARAM_NORMAL);
|
||||
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);
|
||||
@ -358,9 +373,6 @@ static void LoadBuildParameter(void)
|
||||
|
||||
int LoadPersistParams(void)
|
||||
{
|
||||
// first get build parameter
|
||||
LoadBuildParameter();
|
||||
|
||||
// get persist parameter
|
||||
int ret = InitPersistParamWorkSpace();
|
||||
PARAM_CHECK(ret == 0, return ret, "Failed to init persist param");
|
||||
|
@ -48,6 +48,8 @@ static int InitWorkSpace_(WorkSpace *workSpace, uint32_t spaceSize, int readOnly
|
||||
"Failed to map memory error %d spaceSize %d", errno, spaceSize);
|
||||
if (!readOnly) {
|
||||
workSpace->area = (ParamTrieHeader *)areaAddr;
|
||||
ATOMIC_INIT(&workSpace->area->commitId, 0);
|
||||
ATOMIC_INIT(&workSpace->area->commitPersistId, 0);
|
||||
workSpace->area->trieNodeCount = 0;
|
||||
workSpace->area->paramNodeCount = 0;
|
||||
workSpace->area->securityNodeCount = 0;
|
||||
@ -325,14 +327,14 @@ uint32_t AddParamSecruityNode(WorkSpace *workSpace, const ParamAuditData *auditD
|
||||
PARAM_CHECK(auditData != NULL && auditData->name != NULL, return 0, "Invalid auditData");
|
||||
#ifdef PARAM_SUPPORT_SELINUX
|
||||
const uint32_t labelLen = strlen(auditData->label);
|
||||
uint32_t realLen = sizeof(ParamSecruityNode) + PARAM_ALIGN(labelLen + 1);
|
||||
uint32_t realLen = sizeof(ParamSecurityNode) + PARAM_ALIGN(labelLen + 1);
|
||||
#else
|
||||
uint32_t realLen = sizeof(ParamSecruityNode);
|
||||
uint32_t realLen = sizeof(ParamSecurityNode);
|
||||
#endif
|
||||
PARAM_CHECK((workSpace->area->currOffset + realLen) < workSpace->area->dataSize, return 0,
|
||||
"Failed to allocate currOffset %u, dataSize %u datalen %u",
|
||||
workSpace->area->currOffset, workSpace->area->dataSize, realLen);
|
||||
ParamSecruityNode *node = (ParamSecruityNode *)(workSpace->area->data + workSpace->area->currOffset);
|
||||
ParamSecurityNode *node = (ParamSecurityNode *)(workSpace->area->data + workSpace->area->currOffset);
|
||||
node->uid = auditData->dacData.uid;
|
||||
node->gid = auditData->dacData.gid;
|
||||
node->mode = auditData->dacData.mode;
|
||||
@ -369,7 +371,7 @@ uint32_t AddParamNode(WorkSpace *workSpace, const char *key, uint32_t keyLen, co
|
||||
workSpace->area->currOffset, workSpace->area->dataSize, realLen);
|
||||
|
||||
ParamNode *node = (ParamNode *)(workSpace->area->data + workSpace->area->currOffset);
|
||||
atomic_init(&node->commitId, 0);
|
||||
ATOMIC_INIT(&node->commitId, 0);
|
||||
|
||||
node->keyLength = keyLen;
|
||||
node->valueLength = valueLen;
|
||||
|
@ -50,6 +50,7 @@ float ConvertMicrosecondToSecond(int x)
|
||||
|
||||
uid_t DecodeUid(const char *name)
|
||||
{
|
||||
#ifndef __LITEOS_M__
|
||||
INIT_CHECK_RETURN_VALUE(name != NULL, -1);
|
||||
int digitFlag = 1;
|
||||
size_t nameLen = strlen(name);
|
||||
@ -71,6 +72,9 @@ uid_t DecodeUid(const char *name)
|
||||
}
|
||||
return userInf->pw_uid;
|
||||
}
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
char *ReadFileToBuf(const char *configFile)
|
||||
|
99
test/moduletest/syspara.cpp
Executable file
99
test/moduletest/syspara.cpp
Executable file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstdint>
|
||||
|
||||
#include "begetctl.h"
|
||||
#include "shell.h"
|
||||
#include "shell_utils.h"
|
||||
#include "parameter.h"
|
||||
#include "parameters.h"
|
||||
#include "sysversion.h"
|
||||
|
||||
using SysParaInfoItem = struct {
|
||||
char *infoName;
|
||||
const char *(*getInfoValue)(void);
|
||||
};
|
||||
|
||||
static const SysParaInfoItem SYSPARA_LIST[] = {
|
||||
{(char *)"DeviceType", GetDeviceType},
|
||||
{(char *)"Manufacture", GetManufacture},
|
||||
{(char *)"Brand", GetBrand},
|
||||
{(char *)"MarketName", GetMarketName},
|
||||
{(char *)"ProductSeries", GetProductSeries},
|
||||
{(char *)"ProductModel", GetProductModel},
|
||||
{(char *)"SoftwareModel", GetSoftwareModel},
|
||||
{(char *)"HardwareModel", GetHardwareModel},
|
||||
{(char *)"Serial", GetSerial},
|
||||
{(char *)"OSFullName", GetOSFullName},
|
||||
{(char *)"DisplayVersion", GetDisplayVersion},
|
||||
{(char *)"BootloaderVersion", GetBootloaderVersion},
|
||||
{(char *)"GetSecurityPatchTag", GetSecurityPatchTag},
|
||||
{(char *)"AbiList", GetAbiList},
|
||||
{(char *)"IncrementalVersion", GetIncrementalVersion},
|
||||
{(char *)"VersionId", GetVersionId},
|
||||
{(char *)"BuildType", GetBuildType},
|
||||
{(char *)"BuildUser", GetBuildUser},
|
||||
{(char *)"BuildHost", GetBuildHost},
|
||||
{(char *)"BuildTime", GetBuildTime},
|
||||
{(char *)"BuildRootHash", GetBuildRootHash},
|
||||
{(char *)"GetOsReleaseType", GetOsReleaseType},
|
||||
{(char *)"GetHardwareProfile", GetHardwareProfile},
|
||||
};
|
||||
|
||||
static int32_t SysParaApiDumpCmd(BShellHandle shell, int32_t argc, char *argv[])
|
||||
{
|
||||
int index = 0;
|
||||
int dumpInfoItemNum = (sizeof(SYSPARA_LIST) / sizeof(SYSPARA_LIST[0]));
|
||||
const char *temp = nullptr;
|
||||
BShellEnvOutput(shell, (char *)"Begin dump syspara\r\n");
|
||||
BShellEnvOutput(shell, (char *)"=======================\r\n");
|
||||
while (index < dumpInfoItemNum) {
|
||||
temp = SYSPARA_LIST[index].getInfoValue();
|
||||
BShellEnvOutput(shell, (char *)"%s:%s\r\n", SYSPARA_LIST[index].infoName, temp);
|
||||
index++;
|
||||
}
|
||||
BShellEnvOutput(shell, (char *)"FirstApiVersion:%d\r\n", GetFirstApiVersion());
|
||||
BShellEnvOutput(shell, (char *)"GetSerial:%s\r\n", GetSerial());
|
||||
#ifndef OHOS_LITE
|
||||
BShellEnvOutput(shell, (char *)"acl serial:%s\r\n", AclGetSerial());
|
||||
#endif
|
||||
char udid[65] = {0};
|
||||
GetDevUdid(udid, sizeof(udid));
|
||||
BShellEnvOutput(shell, (char *)"GetDevUdid:%s\r\n", udid);
|
||||
#ifndef OHOS_LITE
|
||||
AclGetDevUdid(udid, sizeof(udid));
|
||||
BShellEnvOutput(shell, (char *)"Acl devUdid:%s\r\n", udid);
|
||||
#endif
|
||||
BShellEnvOutput(shell, (char *)"Version:%d.%d.%d.%d\r\n",
|
||||
GetMajorVersion(), GetSeniorVersion(), GetFeatureVersion(), GetBuildVersion());
|
||||
BShellEnvOutput(shell, (char *)"GetSdkApiVersion:%d\r\n", GetSdkApiVersion());
|
||||
BShellEnvOutput(shell, (char *)"GetSystemCommitId:%lld\r\n", GetSystemCommitId());
|
||||
BShellEnvOutput(shell, (char *)"=======================\r\n");
|
||||
BShellEnvOutput(shell, (char *)"End dump syspara\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
MODULE_CONSTRUCTOR(void)
|
||||
{
|
||||
CmdInfo infos[] = {
|
||||
{(char *)"dump", SysParaApiDumpCmd, (char *)"dump api", (char *)"dump api", (char *)"dump api"},
|
||||
};
|
||||
for (size_t i = 0; i < sizeof(infos) / sizeof(infos[0]); i++) {
|
||||
BShellEnvRegitsterCmd(GetShellHandle(), &infos[i]);
|
||||
}
|
||||
}
|
@ -33,6 +33,8 @@ config("utest_config") {
|
||||
ohos_unittest("init_ut") {
|
||||
module_out_path = "startup/init"
|
||||
sources = [
|
||||
"//base/startup/init_lite/device_info/device_info.cpp",
|
||||
"//base/startup/init_lite/device_info/device_info_stub.cpp",
|
||||
"//base/startup/init_lite/interfaces/innerkits/file/init_file.c",
|
||||
"//base/startup/init_lite/interfaces/innerkits/fs_manager/fstab.c",
|
||||
"//base/startup/init_lite/interfaces/innerkits/fs_manager/fstab_mount.c",
|
||||
@ -105,7 +107,7 @@ ohos_unittest("init_ut") {
|
||||
[ "//base/startup/init_lite/services/param/adapter/param_selinux.c" ]
|
||||
}
|
||||
|
||||
if (param_feature_watcher) {
|
||||
if (enable_ohos_startup_init_feature_watcher) {
|
||||
sources += [
|
||||
"//base/startup/init_lite/services/param/watcher/agent/watcher.cpp",
|
||||
"//base/startup/init_lite/services/param/watcher/agent/watcher_manager_kits.cpp",
|
||||
@ -119,6 +121,7 @@ ohos_unittest("init_ut") {
|
||||
|
||||
sources += [
|
||||
"begetctl/begetctl_unittest.cpp",
|
||||
"deviceinfo/DeviceInfoUnittest.cpp",
|
||||
"init/SignalInitUnitTest.cpp",
|
||||
"init/cmds_unittest.cpp",
|
||||
"init/group_unittest.cpp",
|
||||
@ -150,6 +153,7 @@ ohos_unittest("init_ut") {
|
||||
|
||||
include_dirs = [
|
||||
"//base/customization/config_policy/interfaces/innerkits/include",
|
||||
"//base/startup/init_lite/device_info",
|
||||
"//base/startup/init_lite/services/init/standard",
|
||||
"//base/startup/init_lite/interfaces/innerkits/include",
|
||||
"//base/startup/init_lite/interfaces/innerkits/include/syspara",
|
||||
@ -222,7 +226,7 @@ ohos_unittest("init_ut") {
|
||||
"utils_base:utils",
|
||||
]
|
||||
|
||||
if (!defined(ohos_lite) && param_feature_watcher) {
|
||||
if (!defined(ohos_lite) && enable_ohos_startup_init_feature_watcher) {
|
||||
sources += [
|
||||
"param/watcher_agent_unittest.cpp",
|
||||
"param/watcher_proxy_unittest.cpp",
|
||||
@ -250,7 +254,14 @@ ohos_unittest("init_ut") {
|
||||
"PARAM_SUPPORT_SELINUX",
|
||||
]
|
||||
}
|
||||
|
||||
if (enable_ohos_startup_init_feature_deviceinfo) {
|
||||
sources += [
|
||||
"//base/startup/init_lite/device_info/device_info_kits.cpp",
|
||||
"//base/startup/init_lite/device_info/device_info_proxy.cpp",
|
||||
]
|
||||
defines += [ "PARAM_FEATURE_DEVICEINFO" ]
|
||||
external_deps += [ "access_token:libaccesstoken_sdk" ]
|
||||
}
|
||||
cflags_cc = [ "-fexceptions" ]
|
||||
sources += [
|
||||
"init/loopevent_unittest.cpp",
|
||||
|
92
test/unittest/deviceinfo/DeviceInfoUnittest.cpp
Executable file
92
test/unittest/deviceinfo/DeviceInfoUnittest.cpp
Executable file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <gtest/gtest.h>
|
||||
#include "parameter.h"
|
||||
#include "system_ability_definition.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "parcel.h"
|
||||
#include "string_ex.h"
|
||||
#include "device_info_kits.h"
|
||||
#include "idevice_info.h"
|
||||
#include "device_info_stub.h"
|
||||
using namespace testing::ext;
|
||||
using namespace std;
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::device_info;
|
||||
|
||||
const int UDID_LEN = 65;
|
||||
namespace init_ut {
|
||||
using DeviceInfoServicePtr = DeviceInfoService *;
|
||||
class DeviceInfoUnittest : public testing::Test {
|
||||
public:
|
||||
DeviceInfoUnittest() {};
|
||||
virtual ~DeviceInfoUnittest() {};
|
||||
static void SetUpTestCase(void) {};
|
||||
static void TearDownTestCase(void) {};
|
||||
void SetUp() {};
|
||||
void TearDown() {};
|
||||
void TestBody(void) {};
|
||||
DeviceInfoServicePtr GetDeviceInfoService()
|
||||
{
|
||||
static DeviceInfoServicePtr deviceInfoServicePtr = nullptr;
|
||||
if (deviceInfoServicePtr == nullptr) {
|
||||
deviceInfoServicePtr = new DeviceInfoService(0, true);
|
||||
if (deviceInfoServicePtr == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
deviceInfoServicePtr->OnStart();
|
||||
}
|
||||
return deviceInfoServicePtr;
|
||||
}
|
||||
};
|
||||
|
||||
HWTEST_F(DeviceInfoUnittest, GetDevUdidTest, TestSize.Level1)
|
||||
{
|
||||
char localDeviceId[UDID_LEN] = {0};
|
||||
int id = AclGetDevUdid(localDeviceId, UDID_LEN);
|
||||
EXPECT_EQ(id, 0);
|
||||
const char *serialNumber = AclGetSerial();
|
||||
EXPECT_NE(nullptr, serialNumber);
|
||||
|
||||
sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
ASSERT_NE(nullptr, samgr);
|
||||
sptr<IRemoteObject> object = samgr->GetSystemAbility(SYSPARAM_DEVICE_SERVICE_ID);
|
||||
ASSERT_NE(nullptr, samgr);
|
||||
OHOS::device_info::DeviceInfoKits &instance = OHOS::device_info::DeviceInfoKits::GetInstance();
|
||||
auto deathRecipientPtr = instance.GetDeathRecipient();
|
||||
deathRecipientPtr->OnRemoteDied(object);
|
||||
}
|
||||
HWTEST_F(DeviceInfoUnittest, StubTest, TestSize.Level1)
|
||||
{
|
||||
string result;
|
||||
DeviceInfoServicePtr deviceInfoService = GetDeviceInfoService();
|
||||
ASSERT_NE(deviceInfoService, nullptr);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
data.WriteInterfaceToken(DeviceInfoStub::GetDescriptor());
|
||||
int ret = deviceInfoService->OnRemoteRequest(IDeviceInfo::COMMAND_GET_UDID, data, reply, option);
|
||||
EXPECT_EQ(ret, 0);
|
||||
data.WriteInterfaceToken(DeviceInfoStub::GetDescriptor());
|
||||
deviceInfoService->OnRemoteRequest(IDeviceInfo::COMMAND_GET_SERIAL_ID, data, reply, option);
|
||||
deviceInfoService->GetUdid(result);
|
||||
deviceInfoService->GetSerialID(result);
|
||||
deviceInfoService->OnStop();
|
||||
delete deviceInfoService;
|
||||
}
|
||||
} // namespace init_ut
|
@ -185,7 +185,7 @@ HWTEST_F(CmdsUnitTest, TestCommonWrite, TestSize.Level1)
|
||||
close(fd);
|
||||
fd = -1;
|
||||
// abnormal
|
||||
DoCmdByName("write ", "/data/init_ut/test_dir0/test_file_write2 aaa");
|
||||
DoCmdByName("write ", "/data/init_ut/test_dir0/test_file_write2 aaa 2");
|
||||
}
|
||||
|
||||
HWTEST_F(CmdsUnitTest, TestCommonRm, TestSize.Level1)
|
||||
|
@ -163,6 +163,7 @@ HWTEST_F(InitGroupManagerUnitTest, TestHashMap, TestSize.Level1)
|
||||
TestHashNode *tmp = HASHMAP_ENTRY(node, TestHashNode, node);
|
||||
EXPECT_EQ(strcmp(tmp->name, act), 0);
|
||||
}
|
||||
HashMapTraverse(handle, nullptr, nullptr);
|
||||
HashMapDestory(handle);
|
||||
}
|
||||
|
||||
@ -188,7 +189,7 @@ HWTEST_F(InitGroupManagerUnitTest, TestInitGroupMgrInit, TestSize.Level1)
|
||||
const char *xxx14 = "{"
|
||||
"\"groups\": [\"subsystem.xxx11.group\""
|
||||
"}";
|
||||
const char *cmdLine = "BOOT_IMAGE=/kernel init=/init bootgroup=device.charing.group";
|
||||
const char *cmdLine = "BOOT_IMAGE=/kernel init=/init bootgroup=device.charge.group";
|
||||
CreateTestFile(GROUP_DEFAULT_PATH "/device.boot.group.cfg", data);
|
||||
CreateTestFile(GROUP_DEFAULT_PATH "/subsystem.xxx1.group.cfg", xxx1);
|
||||
CreateTestFile(GROUP_DEFAULT_PATH "/subsystem.xxx11.group.cfg", xxx11);
|
||||
@ -199,13 +200,13 @@ HWTEST_F(InitGroupManagerUnitTest, TestInitGroupMgrInit, TestSize.Level1)
|
||||
|
||||
InitServiceSpace();
|
||||
InitWorkspace *workspace = GetInitWorkspace();
|
||||
EXPECT_EQ(workspace->groupMode, GROUP_CHARING);
|
||||
EXPECT_EQ(workspace->groupMode, GROUP_CHARGE);
|
||||
workspace->groupMode = GROUP_BOOT;
|
||||
if (strcpy_s(workspace->groupModeStr, GROUP_NAME_MAX_LENGTH, "device.boot.group") != EOK) {
|
||||
EXPECT_EQ(1, 0);
|
||||
} // test read cfgfile
|
||||
int ret = InitParseGroupCfg();
|
||||
StartAllServices(GROUP_CHARING);
|
||||
StartAllServices(GROUP_CHARGE);
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
@ -297,7 +298,7 @@ HWTEST_F(InitGroupManagerUnitTest, TestAddServiceDeny, TestSize.Level1)
|
||||
"}]"
|
||||
"}";
|
||||
InitWorkspace *workspace = GetInitWorkspace();
|
||||
workspace->groupMode = GROUP_CHARING;
|
||||
workspace->groupMode = GROUP_CHARGE;
|
||||
|
||||
cJSON *fileRoot = cJSON_Parse(serviceStr);
|
||||
ASSERT_NE(nullptr, fileRoot);
|
||||
@ -327,7 +328,7 @@ HWTEST_F(InitGroupManagerUnitTest, TestAddService2, TestSize.Level1)
|
||||
"}";
|
||||
|
||||
InitWorkspace *workspace = GetInitWorkspace();
|
||||
workspace->groupMode = GROUP_CHARING;
|
||||
workspace->groupMode = GROUP_CHARGE;
|
||||
|
||||
InitGroupNode *node = AddGroupNode(NODE_TYPE_SERVICES, "test-service6");
|
||||
ASSERT_NE(nullptr, node);
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "param_stub.h"
|
||||
#include "init_utils.h"
|
||||
#include "trigger_manager.h"
|
||||
#include "init_group_manager.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace std;
|
||||
@ -52,5 +53,6 @@ HWTEST_F(InitRebootUnitTest, TestInitReboot, TestSize.Level1)
|
||||
EXPECT_EQ(ret, 0);
|
||||
ret = DoReboot(DEVICE_CMD_FREEZE);
|
||||
EXPECT_EQ(ret, 0);
|
||||
clearMisc();
|
||||
}
|
||||
} // namespace init_ut
|
||||
|
@ -176,14 +176,12 @@ public:
|
||||
sizeof(ParamMessage));
|
||||
|
||||
LE_Buffer *next = nullptr;
|
||||
LE_Buffer *nextBuff = GetNextBuffer((StreamTask *)client, next);
|
||||
if (nextBuff != nullptr) {
|
||||
LE_FreeBuffer(LE_GetDefaultLoop(), (TaskHandle)client, nextBuff);
|
||||
}
|
||||
EXPECT_EQ(GetNextBuffer((StreamTask *)client, next), nullptr);
|
||||
ParamWatcher *watcher = (ParamWatcher *)ParamGetTaskUserData(client);
|
||||
PARAM_CHECK(watcher != nullptr, return, "Failed to get watcher");
|
||||
ListInit(&watcher->triggerHead);
|
||||
OnClose(client);
|
||||
LE_FreeBuffer(LE_GetDefaultLoop(), (TaskHandle)client, nullptr);
|
||||
return;
|
||||
}
|
||||
void ProcessEventTest()
|
||||
@ -249,6 +247,13 @@ HWTEST_F(LoopEventUnittest, StreamTaskTest, TestSize.Level1)
|
||||
LoopEventUnittest loopevtest = LoopEventUnittest();
|
||||
loopevtest.CreateServerTask();
|
||||
loopevtest.StreamTaskTest();
|
||||
LE_StreamInfo streamInfo = {};
|
||||
streamInfo.recvMessage = OnReceiveRequest;
|
||||
streamInfo.baseInfo.flags = TASK_PIPE | TASK_CONNECT;
|
||||
streamInfo.server = (char *)PIPE_NAME;
|
||||
TaskHandle clientTaskHandlec = nullptr;
|
||||
LE_CreateStreamClient(LE_GetDefaultLoop(), &clientTaskHandlec, &streamInfo);
|
||||
EXPECT_NE(clientTaskHandlec, nullptr);
|
||||
}
|
||||
|
||||
HWTEST_F(LoopEventUnittest, LeTaskTest, TestSize.Level1)
|
||||
@ -289,9 +294,11 @@ HWTEST_F(LoopEventUnittest, RunLoopThread, TestSize.Level1)
|
||||
pthread_create(&tid, nullptr, RunLoopThread, nullptr);
|
||||
event.events = EPOLLOUT;
|
||||
epoll_ctl(((EventEpoll *)LE_GetDefaultLoop())->epollFd, EPOLL_CTL_ADD, fd, &event);
|
||||
HashMapHandle taskMap = ((EventLoop *)LE_GetDefaultLoop())->taskMap;
|
||||
((EventLoop *)LE_GetDefaultLoop())->taskMap = nullptr;
|
||||
StopParamService();
|
||||
pthread_join(tid, nullptr);
|
||||
InitParamService();
|
||||
((EventLoop *)LE_GetDefaultLoop())->taskMap = taskMap;
|
||||
}
|
||||
} // namespace init_ut
|
||||
|
@ -28,11 +28,6 @@
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace std;
|
||||
|
||||
extern "C" {
|
||||
void ClientDeinit(void);
|
||||
}
|
||||
|
||||
namespace init_ut {
|
||||
class ServiceUnitTest : public testing::Test {
|
||||
public:
|
||||
@ -284,9 +279,4 @@ HWTEST_F(ServiceUnitTest, TestServiceExec, TestSize.Level1)
|
||||
EXPECT_EQ(ret, -1);
|
||||
ReleaseService(service);
|
||||
}
|
||||
HWTEST_F(ServiceUnitTest, TestClientDeinit, TestSize.Level1)
|
||||
{
|
||||
ClientDeinit();
|
||||
HashMapDestory(GetInitWorkspace()->hashMap[0]);
|
||||
}
|
||||
} // namespace init_ut
|
||||
|
@ -65,9 +65,12 @@ HWTEST_F(UtilsUnitTest, TestString, TestSize.Level0)
|
||||
EXPECT_EQ(ret, 0);
|
||||
EXPECT_STREQ(rStr, "dbc");
|
||||
}
|
||||
HWTEST_F(UtilsUnitTest, TestConvertMicrosecondToSecond, TestSize.Level0)
|
||||
HWTEST_F(UtilsUnitTest, TestUtilsApi, TestSize.Level0)
|
||||
{
|
||||
float sec = ConvertMicrosecondToSecond(1000000); // 1000000 microseconds
|
||||
EXPECT_EQ(sec, 1);
|
||||
EXPECT_EQ(WriteAll(2, "test", strlen("test")), 4);
|
||||
EXPECT_EQ(InChargerMode(), 0);
|
||||
GetRandom();
|
||||
}
|
||||
} // namespace init_ut
|
||||
|
@ -47,6 +47,7 @@ HWTEST_F(ModuleMgrUnitTest, PluginAddCmd, TestSize.Level1)
|
||||
InitServiceSpace();
|
||||
const char *testName = "testCmd1";
|
||||
const char *cmdContent = "testCmd1 test1 test2 test3";
|
||||
const char *cmdContentNotValid = "testCmd1 t e s t 1 t e s t 2 t";
|
||||
int cmdExecId1 = AddCmdExecutor(testName, TestCmdExecutor);
|
||||
ASSERT_NE(cmdExecId1 > 0, 0);
|
||||
int cmdExecId2 = AddCmdExecutor("testCmd2", TestCmdExecutor);
|
||||
@ -55,6 +56,7 @@ HWTEST_F(ModuleMgrUnitTest, PluginAddCmd, TestSize.Level1)
|
||||
ASSERT_NE(cmdExecId2 > 0, 0);
|
||||
int cmdExecId4 = AddCmdExecutor("testCmd4", TestCmdExecutor);
|
||||
ASSERT_NE(cmdExecId4 > 0, 0);
|
||||
PluginExecCmd("testCmd4", 0, nullptr);
|
||||
|
||||
int cmdIndex = 0;
|
||||
const char *cmdName = PluginGetCmdIndex(cmdContent, &cmdIndex);
|
||||
@ -65,6 +67,8 @@ HWTEST_F(ModuleMgrUnitTest, PluginAddCmd, TestSize.Level1)
|
||||
g_cmdExecId = -1;
|
||||
PluginExecCmdByName(cmdName, cmdContent);
|
||||
ASSERT_EQ(cmdExecId1, g_cmdExecId);
|
||||
PluginExecCmdByName(cmdName, nullptr);
|
||||
PluginExecCmdByName(cmdName, cmdContentNotValid);
|
||||
g_cmdExecId = -1;
|
||||
PluginExecCmdByCmdIndex(cmdIndex, cmdContent);
|
||||
ASSERT_EQ(cmdExecId1, g_cmdExecId);
|
||||
@ -127,7 +131,7 @@ HWTEST_F(ModuleMgrUnitTest, ModuleInstallTest, TestSize.Level1)
|
||||
ModuleMgrUninstall(moduleMgr, NULL);
|
||||
cnt = ModuleMgrGetCnt(moduleMgr);
|
||||
ASSERT_EQ(cnt, 0);
|
||||
|
||||
ModuleMgrGetArgs();
|
||||
ModuleMgrDestroy(moduleMgr);
|
||||
}
|
||||
} // namespace init_ut
|
||||
|
@ -11,6 +11,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
if (defined(ohos_lite)) {
|
||||
import("//base/startup/init_lite/begetd.gni")
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
import("//build/lite/config/test.gni")
|
||||
if (ohos_kernel_type == "linux" || ohos_kernel_type == "liteos_a") {
|
||||
@ -38,7 +39,6 @@ if (defined(ohos_lite)) {
|
||||
}
|
||||
param_common_sources = [
|
||||
"//base/startup/init_lite/services/param/adapter/param_dac.c",
|
||||
"//base/startup/init_lite/services/param/adapter/param_persistadp.c",
|
||||
"//base/startup/init_lite/services/param/manager/param_manager.c",
|
||||
"//base/startup/init_lite/services/param/manager/param_persist.c",
|
||||
"//base/startup/init_lite/services/param/manager/param_trie.c",
|
||||
@ -79,6 +79,7 @@ if (defined(ohos_lite)) {
|
||||
"//base/startup/init_lite/services/init/include",
|
||||
"//base/startup/init_lite/services/log",
|
||||
"//base/startup/init_lite/services/loopevent/include",
|
||||
"//base/startup/init_lite/services/loopevent/timer",
|
||||
"//base/startup/init_lite/services/param/adapter",
|
||||
"//base/startup/init_lite/services/param/linux",
|
||||
"//base/startup/init_lite/services/param/include",
|
||||
@ -89,6 +90,7 @@ if (defined(ohos_lite)) {
|
||||
"//base/startup/init_lite/test/unittest/param",
|
||||
"//base/startup/init_lite/interfaces/innerkits/include",
|
||||
"//base/startup/init_lite/interfaces/innerkits/include/syspara",
|
||||
"//base/startup/init_lite/interfaces/innerkits/syspara",
|
||||
"//third_party/cJSON",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"//base/hiviewdfx/hilog_lite/interfaces/native/kits",
|
||||
@ -108,6 +110,7 @@ if (defined(ohos_lite)) {
|
||||
]
|
||||
sources += init_common_sources
|
||||
sources += [
|
||||
"//base/startup/init_lite/services/param/adapter/param_persistadp.c",
|
||||
"//base/startup/init_lite/services/param/liteos/param_client.c",
|
||||
"//base/startup/init_lite/services/param/liteos/param_osadp.c",
|
||||
"//base/startup/init_lite/services/param/liteos/param_service.c",
|
||||
@ -122,11 +125,15 @@ if (defined(ohos_lite)) {
|
||||
]
|
||||
|
||||
# add cfg.h
|
||||
deps += [
|
||||
"//base/startup/init_lite/services/param:lite_const_param_to",
|
||||
"//base/startup/init_lite/services/param:lite_ohos_param_to",
|
||||
]
|
||||
|
||||
if (enable_ohos_startup_init_feature_begetctl_liteos) {
|
||||
deps += [
|
||||
"$ohos_product_adapter_dir/utils/sys_param:hal_sysparam",
|
||||
"//base/startup/init_lite/services/param:lite_const_param_to",
|
||||
"//base/startup/init_lite/services/param:lite_ohos_param_to",
|
||||
]
|
||||
include_dirs += [ "$root_out_dir/gen/init_lite" ]
|
||||
defines += [ "PARAM_LOAD_CFG_FROM_CODE" ]
|
||||
}
|
||||
deps += [
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
|
||||
"//base/startup/init_lite/initsync:initsync",
|
||||
@ -134,7 +141,6 @@ if (defined(ohos_lite)) {
|
||||
"//build/lite/config/component/cJSON:cjson_static",
|
||||
"//third_party/mbedtls:mbedtls",
|
||||
]
|
||||
include_dirs += [ "$root_out_dir/gen/init_lite" ]
|
||||
}
|
||||
|
||||
if (ohos_kernel_type == "liteos_m") {
|
||||
@ -144,6 +150,14 @@ if (defined(ohos_lite)) {
|
||||
"//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" ]
|
||||
}
|
||||
sources += [
|
||||
"../param/dac_unittest.cpp",
|
||||
"../param/param_stub.cpp",
|
||||
@ -152,23 +166,26 @@ if (defined(ohos_lite)) {
|
||||
]
|
||||
|
||||
# add cfg.h
|
||||
deps += [
|
||||
"//base/startup/init_lite/services/param:lite_const_param_to",
|
||||
"//base/startup/init_lite/services/param:lite_ohos_param_to",
|
||||
]
|
||||
|
||||
if (enable_ohos_startup_init_feature_begetctl_liteos) {
|
||||
deps += [
|
||||
"//base/startup/init_lite/services/param:lite_const_param_to",
|
||||
"//base/startup/init_lite/services/param:lite_ohos_param_to",
|
||||
]
|
||||
include_dirs += [ "$root_out_dir/gen/init_lite" ]
|
||||
defines += [ "PARAM_LOAD_CFG_FROM_CODE" ]
|
||||
}
|
||||
deps += [
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_static",
|
||||
"//base/startup/init_lite/services/utils:libinit_tools",
|
||||
"//third_party/mbedtls:mbedtls",
|
||||
]
|
||||
include_dirs += [ "$root_out_dir/gen/init_lite" ]
|
||||
}
|
||||
if (ohos_kernel_type == "linux") {
|
||||
defines += [ "__LINUX__" ]
|
||||
|
||||
sources += init_common_sources
|
||||
sources += [
|
||||
"//base/startup/init_lite/services/param/adapter/param_persistadp.c",
|
||||
"//base/startup/init_lite/services/param/linux/param_message.c",
|
||||
"//base/startup/init_lite/services/param/linux/param_msgadp.c",
|
||||
"//base/startup/init_lite/services/param/linux/param_osadp.c",
|
||||
|
@ -687,7 +687,6 @@ static void CheckCmd(const TestCmdLine *resCmd)
|
||||
}
|
||||
} else if (strcmp("mkdir ", resCmd->name) == 0) {
|
||||
for (size_t i = 0; i < strlen(resCmd->cmdContent); ++i) {
|
||||
EXPECT_NE(' ', resCmd->cmdContent[i]); // no spaces in path string
|
||||
EXPECT_NE('.', resCmd->cmdContent[i]); // no dots in path string
|
||||
}
|
||||
} else if (strcmp("chmod ", resCmd->name) == 0) {
|
||||
@ -699,7 +698,6 @@ static void CheckCmd(const TestCmdLine *resCmd)
|
||||
}
|
||||
for (size_t i = 5; i < strlen(resCmd->cmdContent); ++i) { // target starts from index 5
|
||||
EXPECT_NE(' ', resCmd->cmdContent[i]); // no spaces allowed
|
||||
EXPECT_NE('.', resCmd->cmdContent[i]); // no dots allowed
|
||||
}
|
||||
} else if (strcmp("chown ", resCmd->name) == 0) {
|
||||
EXPECT_TRUE(strlen(resCmd->cmdContent) >= 5); // x y z at least 5 characters
|
||||
|
@ -26,7 +26,7 @@ static void ClientCheckParamValue(const char *name, const char *expectValue)
|
||||
char tmp[PARAM_BUFFER_SIZE] = {0};
|
||||
u_int32_t len = sizeof(tmp);
|
||||
int ret = SystemGetParameter(name, tmp, &len);
|
||||
printf("ClientCheckParamValue name %s value: \'%s\' expectValue:\'%s\' \n", name, tmp, expectValue);
|
||||
PARAM_LOGI("ClientCheckParamValue name %s value: \'%s\' expectValue:\'%s\' ", name, tmp, expectValue);
|
||||
if (ret == 0 && len > 0) {
|
||||
EXPECT_NE((int)strlen(tmp), 0);
|
||||
if (expectValue != nullptr) {
|
||||
@ -44,10 +44,8 @@ static void *TestSendParamSetMsg(void *args)
|
||||
return nullptr;
|
||||
}
|
||||
std::string name = (char *)args;
|
||||
printf("TestSendParamSetMsg name :\'%s\' \n", name.c_str());
|
||||
SystemWriteParam(name.c_str(), name.c_str());
|
||||
PARAM_LOGI("TestSendParamSetMsg name :\'%s\' ", name.c_str());
|
||||
SystemSetParameter(name.c_str(), name.c_str());
|
||||
ClientCheckParamValue(name.c_str(), name.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -58,7 +56,7 @@ static void *TestSendParamWaitMsg(void *args)
|
||||
}
|
||||
std::string name = "Wati.";
|
||||
name = name + (char *)args;
|
||||
printf("TestSendParamWaitMsg name :\'%s\' \n", name.c_str());
|
||||
PARAM_LOGI("TestSendParamWaitMsg name :\'%s\' \n", name.c_str());
|
||||
SystemWaitParameter(name.c_str(), name.c_str(), 1);
|
||||
return nullptr;
|
||||
}
|
||||
@ -66,7 +64,7 @@ static void *TestSendParamWaitMsg(void *args)
|
||||
static void TestForMultiThread()
|
||||
{
|
||||
static const int threadMaxNumer = 2;
|
||||
printf("TestForMultiThread \n");
|
||||
PARAM_LOGI("TestForMultiThread \n");
|
||||
pthread_t tids[threadMaxNumer + threadMaxNumer];
|
||||
const char *names[] = {
|
||||
"thread.1111.2222.3333.4444.5555",
|
||||
@ -227,6 +225,6 @@ HWTEST_F(ClientUnitTest, TestClient_04, TestSize.Level0)
|
||||
|
||||
HWTEST_F(ClientUnitTest, TestClient_05, TestSize.Level0)
|
||||
{
|
||||
// TestForMultiThread
|
||||
TestForMultiThread();
|
||||
}
|
||||
} // namespace init_ut
|
@ -207,6 +207,7 @@ static void PrepareInnerKitsCfg()
|
||||
"aa aa aa aa\n";
|
||||
mkdir("/data/init_ut/mount_unitest/", S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
CreateTestFile("/data/init_ut/mount_unitest/ReadFstabFromFile1.fstable", innerKitsCfg);
|
||||
CreateTestFile("/etc/fstab.required", "test");
|
||||
}
|
||||
static bool IsDir(const std::string &path)
|
||||
{
|
||||
@ -361,6 +362,12 @@ int TestFreeLocalSecurityLabel(ParamSecurityLabel *srcLabel)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static __attribute__((constructor(101))) void ParamTestStubInit(void)
|
||||
{
|
||||
PARAM_LOGI("ParamTestStubInit");
|
||||
PrepareInitUnitTestEnv();
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public:
|
||||
// get root
|
||||
WorkSpace *workspace = GetWorkSpace(WORKSPACE_NAME_DAC);
|
||||
(void)FindTrieNode(workspace, name, strlen(name), &labelIndex);
|
||||
ParamSecruityNode *node = (ParamSecruityNode *)GetTrieNode(workspace, labelIndex);
|
||||
ParamSecurityNode *node = (ParamSecurityNode *)GetTrieNode(workspace, labelIndex);
|
||||
if (node == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return 0;
|
||||
@ -106,7 +106,7 @@ public:
|
||||
AddSecurityLabel(&auditData);
|
||||
WorkSpace *workspace = GetWorkSpace(WORKSPACE_NAME_DAC);
|
||||
(void)FindTrieNode(workspace, name, strlen(name), &labelIndex);
|
||||
ParamSecruityNode *node = (ParamSecruityNode *)GetTrieNode(workspace, labelIndex);
|
||||
ParamSecurityNode *node = (ParamSecurityNode *)GetTrieNode(workspace, labelIndex);
|
||||
if (node == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return 0;
|
||||
@ -139,7 +139,7 @@ public:
|
||||
uint32_t labelIndex = 0;
|
||||
WorkSpace *workspace = GetWorkSpace(WORKSPACE_NAME_DAC);
|
||||
ParamTrieNode *paramNode = FindTrieNode(workspace, name, strlen(name), &labelIndex);
|
||||
ParamSecruityNode *node = (ParamSecruityNode *)GetTrieNode(workspace, labelIndex);
|
||||
ParamSecurityNode *node = (ParamSecurityNode *)GetTrieNode(workspace, labelIndex);
|
||||
if (paramNode == nullptr || node == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return 0;
|
||||
@ -164,7 +164,7 @@ public:
|
||||
AddSecurityLabel(&auditData);
|
||||
WorkSpace *workspace = GetWorkSpace(WORKSPACE_NAME_DAC);
|
||||
ParamTrieNode *paramNode = FindTrieNode(workspace, name, strlen(name), &labelIndex);
|
||||
ParamSecruityNode *node = (ParamSecruityNode *)GetTrieNode(workspace, labelIndex);
|
||||
ParamSecurityNode *node = (ParamSecurityNode *)GetTrieNode(workspace, labelIndex);
|
||||
if (paramNode == nullptr || node == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return 0;
|
||||
|
@ -18,9 +18,16 @@
|
||||
#include "param_message.h"
|
||||
#include "param_stub.h"
|
||||
#include "trigger_manager.h"
|
||||
#include "le_timer.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace std;
|
||||
|
||||
static int TestTriggerExecute(TriggerNode *trigger, const char *content, uint32_t size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
void OnClose(ParamTaskPtr client);
|
||||
}
|
||||
@ -85,7 +92,7 @@ public:
|
||||
// 获取到跟属性
|
||||
WorkSpace *workspace = GetWorkSpace(WORKSPACE_NAME_DAC);
|
||||
(void)FindTrieNode(workspace, name, strlen(name), &labelIndex);
|
||||
ParamSecruityNode *node = (ParamSecruityNode *)GetTrieNode(workspace, labelIndex);
|
||||
ParamSecurityNode *node = (ParamSecurityNode *)GetTrieNode(workspace, labelIndex);
|
||||
if (node == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return 0;
|
||||
@ -110,7 +117,7 @@ public:
|
||||
AddSecurityLabel(&auditData);
|
||||
WorkSpace *workspace = GetWorkSpace(WORKSPACE_NAME_DAC);
|
||||
(void)FindTrieNode(workspace, name, strlen(name), &labelIndex);
|
||||
ParamSecruityNode *node = (ParamSecruityNode *)GetTrieNode(workspace, labelIndex);
|
||||
ParamSecurityNode *node = (ParamSecurityNode *)GetTrieNode(workspace, labelIndex);
|
||||
if (node == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return 0;
|
||||
@ -143,7 +150,7 @@ public:
|
||||
uint32_t labelIndex = 0;
|
||||
WorkSpace *workspace = GetWorkSpace(WORKSPACE_NAME_DAC);
|
||||
ParamTrieNode *paramNode = FindTrieNode(workspace, name, strlen(name), &labelIndex);
|
||||
ParamSecruityNode *node = (ParamSecruityNode *)GetTrieNode(workspace, labelIndex);
|
||||
ParamSecurityNode *node = (ParamSecurityNode *)GetTrieNode(workspace, labelIndex);
|
||||
if (paramNode == nullptr || node == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return 0;
|
||||
@ -168,7 +175,7 @@ public:
|
||||
AddSecurityLabel(&auditData);
|
||||
WorkSpace *workspace = GetWorkSpace(WORKSPACE_NAME_DAC);
|
||||
ParamTrieNode *paramNode = FindTrieNode(workspace, name, strlen(name), &labelIndex);
|
||||
ParamSecruityNode *node = (ParamSecruityNode *)GetTrieNode(workspace, labelIndex);
|
||||
ParamSecurityNode *node = (ParamSecurityNode *)GetTrieNode(workspace, labelIndex);
|
||||
if (paramNode == nullptr || node == nullptr) {
|
||||
EXPECT_EQ(1, 0);
|
||||
return 0;
|
||||
@ -419,6 +426,10 @@ public:
|
||||
newName += ".test.test.test";
|
||||
SystemWriteParam(newName.c_str(), value);
|
||||
AddWatch(MSG_ADD_WATCHER, name, value);
|
||||
char buffer[] = "testbuff";
|
||||
CheckTrigger(GetTriggerWorkSpace(), TRIGGER_PARAM_WATCH, buffer, strlen(buffer), TestTriggerExecute);
|
||||
SystemDumpTriggers(1);
|
||||
AddWatch(MSG_DEL_WATCHER, name, value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -498,6 +509,11 @@ HWTEST_F(ParamServiceUnitTest, TestAddParamWatch3, TestSize.Level0)
|
||||
{
|
||||
ParamServiceUnitTest test;
|
||||
test.TestAddParamWatch3();
|
||||
if (GetParamService()->timer != nullptr) {
|
||||
((TimerTask *)GetParamService()->timer)->processTimer(nullptr, nullptr);
|
||||
}
|
||||
int hashCode = CheckWatchTriggerTimeout();
|
||||
EXPECT_EQ(hashCode, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(ParamServiceUnitTest, TestCloseTriggerWatch, TestSize.Level0)
|
||||
@ -510,7 +526,11 @@ HWTEST_F(ParamServiceUnitTest, TestServiceCtrl, TestSize.Level0)
|
||||
{
|
||||
ParamServiceUnitTest test;
|
||||
int ret = test.TestServiceCtrl("server1", 0770);
|
||||
#ifdef PARAM_SUPPORT_SELINUX
|
||||
EXPECT_EQ(ret, 0);
|
||||
#else
|
||||
EXPECT_NE(ret, 0);
|
||||
#endif
|
||||
ret = test.TestServiceCtrl("server2", 0772);
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
@ -519,19 +539,35 @@ HWTEST_F(ParamServiceUnitTest, TestPowerCtrl, TestSize.Level0)
|
||||
{
|
||||
ParamServiceUnitTest test;
|
||||
int ret = test.TestPowerCtrl("reboot,shutdown", 0770);
|
||||
#ifdef PARAM_SUPPORT_SELINUX
|
||||
EXPECT_EQ(ret, 0);
|
||||
#else
|
||||
EXPECT_NE(ret, 0);
|
||||
#endif
|
||||
ret = test.TestPowerCtrl("reboot,shutdown", 0772);
|
||||
EXPECT_EQ(ret, 0);
|
||||
ret = test.TestPowerCtrl("reboot,updater", 0770);
|
||||
#ifdef PARAM_SUPPORT_SELINUX
|
||||
EXPECT_EQ(ret, 0);
|
||||
#else
|
||||
EXPECT_NE(ret, 0);
|
||||
#endif
|
||||
ret = test.TestPowerCtrl("reboot,updater", 0772);
|
||||
EXPECT_EQ(ret, 0);
|
||||
ret = test.TestPowerCtrl("reboot,flash", 0770);
|
||||
#ifdef PARAM_SUPPORT_SELINUX
|
||||
EXPECT_EQ(ret, 0);
|
||||
#else
|
||||
EXPECT_NE(ret, 0);
|
||||
#endif
|
||||
ret = test.TestPowerCtrl("reboot,flash", 0772);
|
||||
EXPECT_EQ(ret, 0);
|
||||
ret = test.TestPowerCtrl("reboot", 0770);
|
||||
#ifdef PARAM_SUPPORT_SELINUX
|
||||
EXPECT_EQ(ret, 0);
|
||||
#else
|
||||
EXPECT_NE(ret, 0);
|
||||
#endif
|
||||
ret = test.TestPowerCtrl("reboot", 0772);
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
|
@ -200,6 +200,7 @@ public:
|
||||
CheckTrigger(GetTriggerWorkSpace(), TRIGGER_PARAM, buffer, strlen(buffer), TestTriggerExecute);
|
||||
EXPECT_EQ(1, g_matchTrigger);
|
||||
EXPECT_EQ(0, strcmp(triggerName, g_matchTriggerName));
|
||||
CheckTrigger(GetTriggerWorkSpace(), TRIGGER_PARAM_WATCH, buffer, strlen(buffer), TestTriggerExecute);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -97,6 +97,7 @@ public:
|
||||
if (watcher != nullptr) {
|
||||
watcher->OnRemoteRequest(IWatcher::PARAM_CHANGE, data, reply, option);
|
||||
watcher->OnRemoteRequest(IWatcher::PARAM_CHANGE + 1, data, reply, option);
|
||||
watcher->OnParamerterChange("testname", "testvalue");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -41,9 +41,8 @@ if (defined(ohos_lite)) {
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//base/startup/init_lite/interfaces/innerkits:libbegetutil",
|
||||
"//base/startup/init_lite/services/log:init_log",
|
||||
"//base/startup/init_lite/services/param:param_client",
|
||||
"//base/startup/init_lite/services/utils:libinit_tools",
|
||||
"//third_party/bounds_checking_function:libsec_static",
|
||||
]
|
||||
}
|
||||
@ -123,10 +122,7 @@ if (defined(ohos_lite)) {
|
||||
"//base/startup/init_lite/interfaces/innerkits/include",
|
||||
]
|
||||
deps = service_ueventd_deps
|
||||
deps += [
|
||||
"//base/startup/init_lite/interfaces/innerkits:libbegetutil",
|
||||
"//base/startup/init_lite/services/param:param_client",
|
||||
]
|
||||
deps += [ "//base/startup/init_lite/interfaces/innerkits:libbegetutil" ]
|
||||
cflags = []
|
||||
|
||||
if (build_selinux) {
|
||||
|
@ -34,6 +34,12 @@ if (defined(ohos_lite)) {
|
||||
defines += [ "LINUX_WATCHDOG" ]
|
||||
}
|
||||
}
|
||||
|
||||
group("init_watchdog") {
|
||||
if (ohos_kernel_type == "linux" || ohos_kernel_type == "liteos_a") {
|
||||
deps = [ ":watchdog_service" ]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
import("//build/ohos.gni")
|
||||
ohos_executable("watchdog_service") {
|
||||
|
Loading…
Reference in New Issue
Block a user