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

!1987 FIX:修改静态告警

Merge pull request !1987 from cheng_jinsong/0525_codeCkeck
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "device_info_stub.h" #include "device_info_stub.h"
#include <chrono> #include <chrono>
#include <signal.h> #include <csignal>
#include <unistd.h> #include <unistd.h>
#include "beget_ext.h" #include "beget_ext.h"
......
...@@ -145,7 +145,7 @@ static int LoadDmDeviceTable(int fd, const char *devName, ...@@ -145,7 +145,7 @@ static int LoadDmDeviceTable(int fd, const char *devName,
break; break;
} }
err = strcpy_s(paras, target->paras_len + 1,target->paras); err = strcpy_s(paras, target->paras_len + 1, target->paras);
if (err != EOK) { if (err != EOK) {
rc = -1; rc = -1;
BEGET_LOGE("error 0x%x, cp target paras", err); BEGET_LOGE("error 0x%x, cp target paras", err);
......
...@@ -28,7 +28,7 @@ extern "C" { ...@@ -28,7 +28,7 @@ extern "C" {
#define INVALID_PID 0 #define INVALID_PID 0
typedef struct serviceInfo { typedef struct serviceInfo_ {
ServiceStatus status; ServiceStatus status;
pid_t pid; pid_t pid;
} ServiceInfo; } ServiceInfo;
......
/*
* 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.
*/
/**
* A static class pertaining to the product information.
*
* @devices phone, tablet
* @since 6
* @Syscap SystemCapability.Startup.SysInfo
*/
declare namespace deviceInfo {
/**
* Obtains the device type represented by a string,
* which can be {@code phone} (or {@code default} for phones), {@code wearable}, {@code liteWearable},
* {@code tablet}, {@code tv}, {@code car}, or {@code smartVision}.
*
* @since 6
*/
const deviceType: string;
/**
* Obtains the device manufacturer represented by a string.
*
* @since 6
*/
const manufacture: string;
/**
* Obtains the device brand represented by a string.
*
* @since 6
*/
const brand: string;
/**
* Obtains the external product series represented by a string.
*
* @since 6
*/
const marketName: string;
/**
* Obtains the product series represented by a string.
*
* @since 6
*/
const productSeries: string;
/**
* Obtains the product model represented by a string.
*
* @since 6
*/
const productModel: string;
/**
* Obtains the software model represented by a string.
*
* @since 6
*/
const softwareModel: string;
/**
* Obtains the hardware model represented by a string.
*
* @since 6
*/
const hardwareModel: string;
/**
* Obtains the hardware profile represented by a string.
*
* @since 6
*/
const hardwareProfile: string;
/**
* Obtains the device serial number represented by a string.
*
* @since 6
*/
const serial: string;
/**
* Obtains the bootloader version number represented by a string.
*
* @since 6
*/
const bootloaderVersion: string;
/**
* Obtains the application binary interface (Abi) list represented by a string.
*
* @since 6
*/
const abiList: string;
/**
* Obtains the security patch level represented by a string.
*
* @since 6
*/
const securityPatchTag: string;
/**
* Obtains the product version represented by a string.
*
* @since 6
*/
const displayVersion: string;
/**
* Obtains the incremental version represented by a string.
*
* @since 6
*/
const incrementalVersion: string;
/**
* Obtains the OS release type represented by a string.
*
* <p>The OS release category can be {@code Release}, {@code Beta}, or {@code Canary}.
* The specific release type may be {@code Release}, {@code Beta1}, or others alike.
*
* @since 6
*/
const osReleaseType: string;
/**
* Obtains the OS version represented by a string.
*
* @since 6
*/
const osFullName: string;
/**
* 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.
*
* @since 6
*/
const majorVersion: number;
/**
* Obtains the senior (S) version number, which increases with any updates to the partial
* architecture or major features.
* <p>The S version number monotonically increases from 0 to 99.
*
* @since 6
*/
const seniorVersion: number;
/**
* Obtains the feature (F) version number, which increases with any planned new features.
* <p>The F version number monotonically increases from 0 or 1 to 99.
*
* @since 6
*/
const featureVersion: number;
/**
* Obtains the build (B) version number, which increases with each new development build.
* <p>The B version number monotonically increases from 0 or 1 to 999.
*
* @since 6
*/
const buildVersion: number;
/**
* Obtains the SDK API version number.
*
* @since 6
*/
const sdkApiVersion: number;
/**
* Obtains the first API version number.
*
* @since 6
*/
const firstApiVersion: number;
/**
* Obtains the version ID by a string.
*
* @since 6
*/
const versionId: string;
/**
* Obtains the build types of the same baseline code.
*
* @since 6
*/
const buildType: string;
/**
* Obtains the different build user of the same baseline code.
*
* @since 6
*/
const buildUser: string;
/**
* Obtains the different build host of the same baseline code.
*
* @since 6
*/
const buildHost: string;
/**
* Obtains the build time.
*
* @since 6
*/
const buildTime: string;
/**
* Obtains the version hash.
*
* @since 6
*/
const buildRootHash: string;
/**
* Obtains the device udid.
*
* @since 7
*/
const udid: string;
}
export default deviceInfo;
/*
* 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.
*/
import { AsyncCallback, BusinessError } from './@ohos.base';
/**
* The interface of system parameters class.
*
* @devices phone, tablet
* @since 6
* @Syscap SystemCapability.Startup.SysInfo
* @systemapi
*/
declare namespace systemParameter {
/**
* Gets the value of the attribute with the specified key.
*
* @param key Key of the system attribute.
* @param def Default value.
* @return if the parameter is empty or doesn't exist, empty string will be returned.
* @since 6
*/
function getSync(key: string, def?: string): string;
/**
* Gets the value of the attribute with the specified key.
*
* @param key Key of the system attribute.
* @param callback Callback function.
* @since 6
*/
function get(key: string, callback: AsyncCallback<string>): void;
/**
* Gets the value of the attribute with the specified key.
*
* @param key Key of the system attribute.
* @param def Default value.
* @param callback Callback function.
* @since 6
*/
function get(key: string, def: string, callback: AsyncCallback<string>): void;
/**
* Gets the value of the attribute with the specified key.
*
* @param key Key of the system attribute.
* @param def Default value.
* @return Promise, which is used to obtain the result asynchronously.
* @since 6
*/
function get(key: string, def?: string): Promise<string>;
/**
* Sets a value for the attribute with the specified key.
*
* @param key Key of the system attribute.
* @param value System attribute value to set.
* @since 6
*/
function setSync(key: string, value: string): void;
/**
* Sets a value for the attribute with the specified key.
*
* @param key Key of the system attribute.
* @param value System attribute value to set.
* @param callback Callback function.
* @since 6
*/
function set(key: string, value: string, callback: AsyncCallback<void>): void;
/**
* Sets a value for the attribute with the specified key.
*
* @param key Key of the system attribute.
* @param value Default value.
* @return Promise, which is used to obtain the result asynchronously.
* @since 6
*/
function set(key: string, value: string): Promise<void>;
/**
* Wait for a parameter with specified value.
*
* @param key Key of the system parameter.
* @param value System parameter value to be wait.
* @param timeout Indicates the timeout value, in seconds.
* <=0 means wait for ever.
* >0 means wait for specified seconds
* @param callback Callback function.
* @since 7
*/
function wait(key: string, value: string, timeout: number, callback: AsyncCallback<void>): void;
/**
* Sets a value for the parameter with the specified key.
*
* @param key Key of the system parameter.
* @param value System parameter value to be wait.
* @param timeout Indicates the timeout value, in seconds.
* <=0 means wait for ever.
* >0 means wait for specified seconds
* @return Promise, which is used to obtain the result asynchronously.
* @since 7
*/
function wait(key: string, value: string, timeout: number): Promise<void>;
/**
* Wait for a parameter with specified value.
*
* @param keyPrefix Key prefix of the system parameters to be watched.
* @param callback Callback function.
* @since 7
*/
function getWatcher(keyPrefix: string): Watcher;
/**
* Called when the system parameter value changes. You need to implement this method in a child class.
*
* @param key Indicates changed system parameter key name.
* @param value Indicates changed system parameter value.
* @since 7
*/
export interface ParameterChangeCallback {
(key: string, value: string): void;
}
export interface Watcher {
/**
* Subscribe to parameter value changess
*
* @since 7
*/
on(eventType: 'valueChange', callback: ParameterChangeCallback): void;
/**
* Unsubscribe to parameter value changess
*
* @since 7
*/
off(eventType: 'valueChange', callback?: ParameterChangeCallback): void;
}
}
export default systemParameter;
...@@ -66,12 +66,12 @@ static int SetInitLogLevelFromParam(BShellHandle shell, int argc, char **argv) ...@@ -66,12 +66,12 @@ static int SetInitLogLevelFromParam(BShellHandle shell, int argc, char **argv)
return -1; return -1;
} }
if ((level >= INIT_DEBUG) && (level <= INIT_FATAL)) { if ((level >= INIT_DEBUG) && (level <= INIT_FATAL)) {
const char *LOG_LEVEL_STR[] = { "DEBUG", "INFO", "WARNING", "ERROR", "FATAL" }; const char *logLevelStr[] = { "DEBUG", "INFO", "WARNING", "ERROR", "FATAL" };
int ret = HandleCmd(shell, "setloglevel", argc - 1, &argv[1]); int ret = HandleCmd(shell, "setloglevel", argc - 1, &argv[1]);
if (ret != 0) { if (ret != 0) {
printf("Failed to set log level %s. \n", LOG_LEVEL_STR[level]); printf("Failed to set log level %s. \n", logLevelStr[level]);
} else { } else {
printf("Success to set log level %s. \n", LOG_LEVEL_STR[level]); printf("Success to set log level %s. \n", logLevelStr[level]);
} }
} else { } else {
printf("%s is invalid. \n", argv[1]); printf("%s is invalid. \n", argv[1]);
...@@ -83,8 +83,8 @@ static int32_t GetInitLogLevelFromParam(BShellHandle shell, int argc, char **arg ...@@ -83,8 +83,8 @@ static int32_t GetInitLogLevelFromParam(BShellHandle shell, int argc, char **arg
{ {
int level = GetIntParameter(INIT_DEBUG_LEVEL, (int)INIT_ERROR); int level = GetIntParameter(INIT_DEBUG_LEVEL, (int)INIT_ERROR);
if ((level >= INIT_DEBUG) && (level <= INIT_FATAL)) { if ((level >= INIT_DEBUG) && (level <= INIT_FATAL)) {
const char *LOG_LEVEL_STR[] = { "DEBUG", "INFO", "WARNING", "ERROR", "FATAL" }; const char *logLevelStr[] = { "DEBUG", "INFO", "WARNING", "ERROR", "FATAL" };
printf("Init log level: %s \n", LOG_LEVEL_STR[level]); printf("Init log level: %s \n", logLevelStr[level]);
} }
return 0; return 0;
} }
......
...@@ -134,10 +134,8 @@ static void ServiceHookExecute(const char *serviceName, const char *info, int st ...@@ -134,10 +134,8 @@ static void ServiceHookExecute(const char *serviceName, const char *info, int st
} }
#endif #endif
static int SetPerms(const Service *service) static int ServiceCheck(const Service *service)
{ {
INIT_CHECK_RETURN_VALUE(KeepCapability() == 0, SERVICE_FAILURE);
if (service->servPerm.gIDCnt == 0) { if (service->servPerm.gIDCnt == 0) {
// use uid as gid // use uid as gid
INIT_ERROR_CHECK(setgid(service->servPerm.uID) == 0, return SERVICE_FAILURE, INIT_ERROR_CHECK(setgid(service->servPerm.uID) == 0, return SERVICE_FAILURE,
...@@ -153,6 +151,16 @@ static int SetPerms(const Service *service) ...@@ -153,6 +151,16 @@ static int SetPerms(const Service *service)
"SetPerms, setgroups failed. errno = %d, gIDCnt=%d", errno, service->servPerm.gIDCnt); "SetPerms, setgroups failed. errno = %d, gIDCnt=%d", errno, service->servPerm.gIDCnt);
} }
return SERVICE_SUCCESS;
}
static int SetPerms(const Service *service)
{
INIT_CHECK_RETURN_VALUE(KeepCapability() == 0, SERVICE_FAILURE);
INIT_ERROR_CHECK(ServiceCheck(service) == SERVICE_SUCCESS, return SERVICE_FAILURE,
"set seccomp policy failed for service %s", service->name);
// set seccomp policy before setuid // set seccomp policy before setuid
INIT_ERROR_CHECK(SetSystemSeccompPolicy(service) == SERVICE_SUCCESS, return SERVICE_FAILURE, INIT_ERROR_CHECK(SetSystemSeccompPolicy(service) == SERVICE_SUCCESS, return SERVICE_FAILURE,
"set seccomp policy failed for service %s", service->name); "set seccomp policy failed for service %s", service->name);
......
...@@ -113,7 +113,7 @@ static void PrintLog(InitLogLevel logLevel, unsigned int domain, const char *tag ...@@ -113,7 +113,7 @@ static void PrintLog(InitLogLevel logLevel, unsigned int domain, const char *tag
#endif #endif
} }
static void PrintLog_(int logLevel, unsigned int domain, const char *tag, const char *fmt, va_list vargs) static void PrintLogFmt(int logLevel, unsigned int domain, const char *tag, const char *fmt, va_list vargs)
{ {
char tmpFmt[DEF_LOG_SIZE] = {0}; char tmpFmt[DEF_LOG_SIZE] = {0};
if (vsnprintf_s(tmpFmt, sizeof(tmpFmt), sizeof(tmpFmt) - 1, fmt, vargs) == -1) { if (vsnprintf_s(tmpFmt, sizeof(tmpFmt), sizeof(tmpFmt) - 1, fmt, vargs) == -1) {
...@@ -128,7 +128,7 @@ INIT_LOCAL_API void InitLog(int logLevel, unsigned int domain, const char *tag, ...@@ -128,7 +128,7 @@ INIT_LOCAL_API void InitLog(int logLevel, unsigned int domain, const char *tag,
if ((int)g_logLevel > logLevel) { if ((int)g_logLevel > logLevel) {
return; return;
} }
PrintLog_((InitLogLevel)logLevel, domain, tag, fmt, vargs); PrintLogFmt((InitLogLevel)logLevel, domain, tag, fmt, vargs);
} }
INIT_PUBLIC_API void SetInitLogLevel(InitLogLevel level) INIT_PUBLIC_API void SetInitLogLevel(InitLogLevel level)
......
...@@ -81,13 +81,11 @@ ENG_STATIC void BuildMountCmd(char *buffer, size_t len, const char *mp, const ch ...@@ -81,13 +81,11 @@ ENG_STATIC void BuildMountCmd(char *buffer, size_t len, const char *mp, const ch
ENG_STATIC void MountEngPartitions(void) ENG_STATIC void MountEngPartitions(void)
{ {
char mountCmd[MOUNT_CMD_MAX_LEN] = {}; char mountCmd[MOUNT_CMD_MAX_LEN] = {};
// Mount eng_system // Mount eng_system
BuildMountCmd(mountCmd, MOUNT_CMD_MAX_LEN, "/eng_system", BuildMountCmd(mountCmd, MOUNT_CMD_MAX_LEN, "/eng_system",
"/dev/block/by-name/eng_system", "ext4"); "/dev/block/by-name/eng_system", "ext4");
WaitForFile(ENG_SYSTEM_DEVICE_PATH, WAIT_MAX_SECOND); WaitForFile(ENG_SYSTEM_DEVICE_PATH, WAIT_MAX_SECOND);
DoCmdByName("mount ", mountCmd); DoCmdByName("mount ", mountCmd);
// Mount eng_chipset // Mount eng_chipset
BuildMountCmd(mountCmd, MOUNT_CMD_MAX_LEN, "/eng_chipset", BuildMountCmd(mountCmd, MOUNT_CMD_MAX_LEN, "/eng_chipset",
"/dev/block/by-name/eng_chipset", "ext4"); "/dev/block/by-name/eng_chipset", "ext4");
...@@ -156,7 +154,7 @@ ENG_STATIC void DebugFilesOverlay(const char *source, const char *target) ...@@ -156,7 +154,7 @@ ENG_STATIC void DebugFilesOverlay(const char *source, const char *target)
if (de->d_name[0] == '.') { if (de->d_name[0] == '.') {
continue; continue;
} }
if (snprintf_s(srcPath, PATH_MAX, PATH_MAX - 1, "%s/%s",source, de->d_name) == -1) { if (snprintf_s(srcPath, PATH_MAX, PATH_MAX - 1, "%s/%s", source, de->d_name) == -1) {
PLUGIN_LOGE("Failed to build path for overlaying"); PLUGIN_LOGE("Failed to build path for overlaying");
break; break;
} }
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
static int InitEngEarlyHook(const HOOK_INFO *info, void *cookie) static int InitEngEarlyHook(const HOOK_INFO *info, void *cookie)
{ {
char value[MAX_BUFFER_LEN] = {0}; char value[MAX_BUFFER_LEN] = {0};
int ret = GetParameterFromCmdLine("eng_mode", value, MAX_BUFFER_LEN); int ret = GetParameterFromCmdLine("eng_mode", value, MAX_BUFFER_LEN);
if (ret == 0 && strcmp(value, "on") == 0) { if (ret == 0 && strcmp(value, "on") == 0) {
......
...@@ -143,7 +143,7 @@ static int CmdClear(int id, const char *name, int argc, const char **argv) ...@@ -143,7 +143,7 @@ static int CmdClear(int id, const char *name, int argc, const char **argv)
return 0; return 0;
} }
static void SetLogLevel_(const char *value) static void SetLogLevelFunc(const char *value)
{ {
unsigned int level; unsigned int level;
int ret = StringToUint(value, &level); int ret = StringToUint(value, &level);
...@@ -159,20 +159,20 @@ static int CmdSetLogLevel(int id, const char *name, int argc, const char **argv) ...@@ -159,20 +159,20 @@ static int CmdSetLogLevel(int id, const char *name, int argc, const char **argv)
PLUGIN_CHECK(argc >= 1, return -1, "Invalid input args"); PLUGIN_CHECK(argc >= 1, return -1, "Invalid input args");
const char *value = strrchr(argv[0], '.'); const char *value = strrchr(argv[0], '.');
PLUGIN_CHECK(value != NULL, return -1, "Failed get \'.\' from string %s", argv[0]); PLUGIN_CHECK(value != NULL, return -1, "Failed get \'.\' from string %s", argv[0]);
SetLogLevel_(value + 1); SetLogLevelFunc(value + 1);
return 0; return 0;
} }
static int initCmd(int id, const char *name, int argc, const char **argv) static int InitCmd(int id, const char *name, int argc, const char **argv)
{ {
UNUSED(id); UNUSED(id);
// process cmd by name // process cmd by name
PLUGIN_LOGI("initCmd %s argc %d", name, argc); PLUGIN_LOGI("InitCmd %s argc %d", name, argc);
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++) {
PLUGIN_LOGI("initCmd %s", argv[i]); PLUGIN_LOGI("InitCmd %s", argv[i]);
} }
if (argc > 1 && strcmp(argv[0], "setloglevel") == 0) { if (argc > 1 && strcmp(argv[0], "setloglevel") == 0) {
SetLogLevel_(argv[1]); SetLogLevelFunc(argv[1]);
} }
return 0; return 0;
} }
...@@ -181,7 +181,7 @@ static int ParamSetInitCmdHook(const HOOK_INFO *hookInfo, void *cookie) ...@@ -181,7 +181,7 @@ static int ParamSetInitCmdHook(const HOOK_INFO *hookInfo, void *cookie)
{ {
AddCmdExecutor("clear", CmdClear); AddCmdExecutor("clear", CmdClear);
AddCmdExecutor("setloglevel", CmdSetLogLevel); AddCmdExecutor("setloglevel", CmdSetLogLevel);
AddCmdExecutor("initcmd", initCmd); AddCmdExecutor("initcmd", InitCmd);
return 0; return 0;
} }
...@@ -213,7 +213,7 @@ static void InitLogLevelFromPersist(void) ...@@ -213,7 +213,7 @@ static void InitLogLevelFromPersist(void)
uint32_t len = sizeof(logLevel); uint32_t len = sizeof(logLevel);
int ret = SystemReadParam(INIT_DEBUG_LEVEL, logLevel, &len); int ret = SystemReadParam(INIT_DEBUG_LEVEL, logLevel, &len);
INIT_INFO_CHECK(ret == 0, return, "Can not get log level from param, keep the original loglevel."); INIT_INFO_CHECK(ret == 0, return, "Can not get log level from param, keep the original loglevel.");
SetLogLevel_(logLevel); SetLogLevelFunc(logLevel);
return; return;
} }
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "service_watcher.h" #include "service_watcher.h"
#include "fuzz_utils.h" #include "fuzz_utils.h"
void callback(const char *key, const ServiceInfo *status) static void callback(const char *key, const ServiceInfo *status)
{ {
printf("key is: %s, ServiceStatus is: %d\n", key, status->status); printf("key is: %s, ServiceStatus is: %d\n", key, status->status);
} }
......
...@@ -172,16 +172,16 @@ public: ...@@ -172,16 +172,16 @@ public:
instance.remoteWatcher_->OnRemoteRequest(IWatcher::PARAM_CHANGE, data, reply, option); instance.remoteWatcher_->OnRemoteRequest(IWatcher::PARAM_CHANGE, data, reply, option);
instance.remoteWatcher_->OnRemoteRequest(IWatcher::PARAM_CHANGE + 1, data, reply, option); instance.remoteWatcher_->OnRemoteRequest(IWatcher::PARAM_CHANGE + 1, data, reply, option);
instance.remoteWatcher_->OnParameterChange(name.c_str(), "testname", "testvalue"); instance.remoteWatcher_->OnParameterChange(name.c_str(), "testname", "testvalue");
EXPECT_EQ(g_callbackCount, 2); EXPECT_EQ(g_callbackCount, 2); // 2 is callback Count
instance.remoteWatcher_->OnParameterChange(name.c_str(), "testname.2", "testvalue"); instance.remoteWatcher_->OnParameterChange(name.c_str(), "testname.2", "testvalue");
EXPECT_EQ(g_callbackCount, 3); EXPECT_EQ(g_callbackCount, 3); // 3 is callback Count
instance.remoteWatcher_->OnParameterChange(name.c_str(), "testname.2", "testvalue"); instance.remoteWatcher_->OnParameterChange(name.c_str(), "testname.2", "testvalue");
EXPECT_EQ(g_callbackCount, 3); EXPECT_EQ(g_callbackCount, 3); // 3 is callback Count
// prefix not exit // prefix not exit
instance.remoteWatcher_->OnParameterChange("44444444444444444444", "testname.2", "testvalue"); instance.remoteWatcher_->OnParameterChange("44444444444444444444", "testname.2", "testvalue");
} }
EXPECT_EQ(g_callbackCount, 3); EXPECT_EQ(g_callbackCount, 3); // 3 is callback Count
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册