diff --git a/device_info/device_info_stub.cpp b/device_info/device_info_stub.cpp index a8d489e2780edc8977038fe852e055f9349ee6a5..5fb7c0a7005a7918b0397e9a4c9d1b3d0341956b 100644 --- a/device_info/device_info_stub.cpp +++ b/device_info/device_info_stub.cpp @@ -16,7 +16,7 @@ #include "device_info_stub.h" #include -#include +#include #include #include "beget_ext.h" diff --git a/interfaces/innerkits/fs_manager/libfs_dm/fs_dm.c b/interfaces/innerkits/fs_manager/libfs_dm/fs_dm.c index 8ac87ceca0a61b5cc76dbef90ad7e14bfa9f2e8d..ac0f21cc22b8c91d0893d4b33e120f99df454e9a 100755 --- a/interfaces/innerkits/fs_manager/libfs_dm/fs_dm.c +++ b/interfaces/innerkits/fs_manager/libfs_dm/fs_dm.c @@ -145,7 +145,7 @@ static int LoadDmDeviceTable(int fd, const char *devName, break; } - err = strcpy_s(paras, target->paras_len + 1,target->paras); + err = strcpy_s(paras, target->paras_len + 1, target->paras); if (err != EOK) { rc = -1; BEGET_LOGE("error 0x%x, cp target paras", err); diff --git a/interfaces/innerkits/include/service_watcher.h b/interfaces/innerkits/include/service_watcher.h index 4708e829a36fe874f93a28a99c75f9538a89451a..3573966a91ddc2ac2811eab364de1b795f513535 100644 --- a/interfaces/innerkits/include/service_watcher.h +++ b/interfaces/innerkits/include/service_watcher.h @@ -28,7 +28,7 @@ extern "C" { #define INVALID_PID 0 -typedef struct serviceInfo { +typedef struct serviceInfo_ { ServiceStatus status; pid_t pid; } ServiceInfo; diff --git a/interfaces/kits/jskits/@ohos.deviceInfo.d.ts b/interfaces/kits/jskits/@ohos.deviceInfo.d.ts deleted file mode 100755 index 38199d28f47a711da06a6231a0c6370ffaed8074..0000000000000000000000000000000000000000 --- a/interfaces/kits/jskits/@ohos.deviceInfo.d.ts +++ /dev/null @@ -1,245 +0,0 @@ -/* - * 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. - * - *

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. - *

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. - *

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. - *

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. - *

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; diff --git a/interfaces/kits/jskits/@ohos.systemparameter.d.ts b/interfaces/kits/jskits/@ohos.systemparameter.d.ts deleted file mode 100755 index db56689748d42f6ae0cd7e267fd247e810a9380c..0000000000000000000000000000000000000000 --- a/interfaces/kits/jskits/@ohos.systemparameter.d.ts +++ /dev/null @@ -1,157 +0,0 @@ -/* - * 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): 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): 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; - - /** - * 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; - - /** - * 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; - - /** - * 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; - - /** - * 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; - - /** - * 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; diff --git a/services/begetctl/begetctl_cmd.c b/services/begetctl/begetctl_cmd.c index 91547951203e9bca6793a628f8457a8705a541ac..d4413c5bd9c90821704b9e496cbdcebdaf32ddae 100644 --- a/services/begetctl/begetctl_cmd.c +++ b/services/begetctl/begetctl_cmd.c @@ -66,12 +66,12 @@ static int SetInitLogLevelFromParam(BShellHandle shell, int argc, char **argv) return -1; } 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]); 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 { - printf("Success to set log level %s. \n", LOG_LEVEL_STR[level]); + printf("Success to set log level %s. \n", logLevelStr[level]); } } else { printf("%s is invalid. \n", argv[1]); @@ -83,8 +83,8 @@ static int32_t GetInitLogLevelFromParam(BShellHandle shell, int argc, char **arg { int level = GetIntParameter(INIT_DEBUG_LEVEL, (int)INIT_ERROR); if ((level >= INIT_DEBUG) && (level <= INIT_FATAL)) { - const char *LOG_LEVEL_STR[] = { "DEBUG", "INFO", "WARNING", "ERROR", "FATAL" }; - printf("Init log level: %s \n", LOG_LEVEL_STR[level]); + const char *logLevelStr[] = { "DEBUG", "INFO", "WARNING", "ERROR", "FATAL" }; + printf("Init log level: %s \n", logLevelStr[level]); } return 0; } diff --git a/services/init/init_common_service.c b/services/init/init_common_service.c index 719b5d083da31162ca2caac08873da2f6dde79eb..7a77ebe7c2d1740dbdaef7be6f2ee28cd12d9a5c 100644 --- a/services/init/init_common_service.c +++ b/services/init/init_common_service.c @@ -134,10 +134,8 @@ static void ServiceHookExecute(const char *serviceName, const char *info, int st } #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) { // use uid as gid INIT_ERROR_CHECK(setgid(service->servPerm.uID) == 0, return SERVICE_FAILURE, @@ -153,6 +151,16 @@ static int SetPerms(const Service *service) "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 INIT_ERROR_CHECK(SetSystemSeccompPolicy(service) == SERVICE_SUCCESS, return SERVICE_FAILURE, "set seccomp policy failed for service %s", service->name); diff --git a/services/log/init_log.c b/services/log/init_log.c index 3c93213056baeafdffcb06905bd76bc5f08608f7..62fa86f594355ed4b7f180d1d2fb35f664fc1b01 100644 --- a/services/log/init_log.c +++ b/services/log/init_log.c @@ -113,7 +113,7 @@ static void PrintLog(InitLogLevel logLevel, unsigned int domain, const char *tag #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}; 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, if ((int)g_logLevel > logLevel) { return; } - PrintLog_((InitLogLevel)logLevel, domain, tag, fmt, vargs); + PrintLogFmt((InitLogLevel)logLevel, domain, tag, fmt, vargs); } INIT_PUBLIC_API void SetInitLogLevel(InitLogLevel level) diff --git a/services/modules/init_eng/init_eng.c b/services/modules/init_eng/init_eng.c index f7144cc097e1e0f346a90a1a183f8bc16a9f4975..5b7c854fff5a101d8679d684648c4536bb2af825 100644 --- a/services/modules/init_eng/init_eng.c +++ b/services/modules/init_eng/init_eng.c @@ -81,13 +81,11 @@ ENG_STATIC void BuildMountCmd(char *buffer, size_t len, const char *mp, const ch ENG_STATIC void MountEngPartitions(void) { char mountCmd[MOUNT_CMD_MAX_LEN] = {}; - // Mount eng_system BuildMountCmd(mountCmd, MOUNT_CMD_MAX_LEN, "/eng_system", "/dev/block/by-name/eng_system", "ext4"); WaitForFile(ENG_SYSTEM_DEVICE_PATH, WAIT_MAX_SECOND); DoCmdByName("mount ", mountCmd); - // Mount eng_chipset BuildMountCmd(mountCmd, MOUNT_CMD_MAX_LEN, "/eng_chipset", "/dev/block/by-name/eng_chipset", "ext4"); @@ -156,7 +154,7 @@ ENG_STATIC void DebugFilesOverlay(const char *source, const char *target) if (de->d_name[0] == '.') { 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"); break; } diff --git a/services/modules/init_eng/init_eng_static.c b/services/modules/init_eng/init_eng_static.c index 07bcd14e979994796ef146642d1d4748636ea722..5adc92ee5df326c510a93eed1d546441957d30de 100644 --- a/services/modules/init_eng/init_eng_static.c +++ b/services/modules/init_eng/init_eng_static.c @@ -20,7 +20,6 @@ static int InitEngEarlyHook(const HOOK_INFO *info, void *cookie) { - char value[MAX_BUFFER_LEN] = {0}; int ret = GetParameterFromCmdLine("eng_mode", value, MAX_BUFFER_LEN); if (ret == 0 && strcmp(value, "on") == 0) { diff --git a/services/modules/init_hook/init_hook.c b/services/modules/init_hook/init_hook.c index 5548c10e1c82fad73130ac5eb4a47682ba42082b..1948664199a008b3a80142037ba7797233f5c8b5 100755 --- a/services/modules/init_hook/init_hook.c +++ b/services/modules/init_hook/init_hook.c @@ -143,7 +143,7 @@ static int CmdClear(int id, const char *name, int argc, const char **argv) return 0; } -static void SetLogLevel_(const char *value) +static void SetLogLevelFunc(const char *value) { unsigned int level; int ret = StringToUint(value, &level); @@ -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"); const char *value = strrchr(argv[0], '.'); PLUGIN_CHECK(value != NULL, return -1, "Failed get \'.\' from string %s", argv[0]); - SetLogLevel_(value + 1); + SetLogLevelFunc(value + 1); 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); // 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++) { - PLUGIN_LOGI("initCmd %s", argv[i]); + PLUGIN_LOGI("InitCmd %s", argv[i]); } if (argc > 1 && strcmp(argv[0], "setloglevel") == 0) { - SetLogLevel_(argv[1]); + SetLogLevelFunc(argv[1]); } return 0; } @@ -181,7 +181,7 @@ static int ParamSetInitCmdHook(const HOOK_INFO *hookInfo, void *cookie) { AddCmdExecutor("clear", CmdClear); AddCmdExecutor("setloglevel", CmdSetLogLevel); - AddCmdExecutor("initcmd", initCmd); + AddCmdExecutor("initcmd", InitCmd); return 0; } @@ -213,7 +213,7 @@ static void InitLogLevelFromPersist(void) uint32_t len = sizeof(logLevel); 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."); - SetLogLevel_(logLevel); + SetLogLevelFunc(logLevel); return; } diff --git a/test/fuzztest/ServiceWatchForStatus_fuzzer/ServiceWatchForStatus_fuzzer.cpp b/test/fuzztest/ServiceWatchForStatus_fuzzer/ServiceWatchForStatus_fuzzer.cpp index d92113369170fd3f3afdd5cfaaa97ebd70d087ea..4aa148875bc07d76d1080f33194e2ec2e838449c 100644 --- a/test/fuzztest/ServiceWatchForStatus_fuzzer/ServiceWatchForStatus_fuzzer.cpp +++ b/test/fuzztest/ServiceWatchForStatus_fuzzer/ServiceWatchForStatus_fuzzer.cpp @@ -18,7 +18,7 @@ #include "service_watcher.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); } diff --git a/test/unittest/param/watcher_agent_unittest.cpp b/test/unittest/param/watcher_agent_unittest.cpp index 7e593f5030ebf99e8bf8c2a15ce4f48d3911c674..681e76a710b0a81c9ae9a90d23e033ad6f7e1016 100644 --- a/test/unittest/param/watcher_agent_unittest.cpp +++ b/test/unittest/param/watcher_agent_unittest.cpp @@ -172,16 +172,16 @@ public: instance.remoteWatcher_->OnRemoteRequest(IWatcher::PARAM_CHANGE, data, reply, option); instance.remoteWatcher_->OnRemoteRequest(IWatcher::PARAM_CHANGE + 1, data, reply, option); 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"); - EXPECT_EQ(g_callbackCount, 3); + EXPECT_EQ(g_callbackCount, 3); // 3 is callback Count 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 instance.remoteWatcher_->OnParameterChange("44444444444444444444", "testname.2", "testvalue"); } - EXPECT_EQ(g_callbackCount, 3); + EXPECT_EQ(g_callbackCount, 3); // 3 is callback Count return 0; }