From e18e0d7f0702f6f692b411645d3e0dafb7b30afd Mon Sep 17 00:00:00 2001 From: cheng_jinsong Date: Mon, 8 May 2023 15:09:35 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cheng_jinsong --- interfaces/innerkits/fs_manager/fstab.c | 8 +------- interfaces/innerkits/fs_manager/fstab_mount.c | 8 ++------ .../innerkits/fs_manager/libfs_hvb/fs_hvb.c | 12 +----------- services/include/init_utils.h | 1 + services/init/init_group_manager.c | 16 ++++++---------- services/log/init_log.c | 8 +------- services/modules/seccomp/seccomp_policy_static.c | 2 -- services/param/linux/param_request.c | 12 ++++++++++++ services/utils/init_utils.c | 10 ++++++++++ ueventd/ueventd.c | 10 ++-------- ueventd/ueventd_device_handler.c | 6 ++++-- 11 files changed, 40 insertions(+), 53 deletions(-) diff --git a/interfaces/innerkits/fs_manager/fstab.c b/interfaces/innerkits/fs_manager/fstab.c index 6be617ff..cc5586d7 100644 --- a/interfaces/innerkits/fs_manager/fstab.c +++ b/interfaces/innerkits/fs_manager/fstab.c @@ -306,13 +306,7 @@ static char *GetFstabFile(char *fileName, size_t size) } } else { char hardware[MAX_BUFFER_LEN] = {0}; - char *buffer = ReadFileData("/proc/cmdline"); - if (buffer == NULL) { - BEGET_LOGE("Failed to read \"/proc/cmdline\""); - return NULL; - } - int ret = GetProcCmdlineValue("hardware", buffer, hardware, MAX_BUFFER_LEN); - free(buffer); + int ret = GetParameterFromCmdLine("hardware", hardware, MAX_BUFFER_LEN); if (ret != 0) { BEGET_LOGE("Failed get hardware from cmdline"); return NULL; diff --git a/interfaces/innerkits/fs_manager/fstab_mount.c b/interfaces/innerkits/fs_manager/fstab_mount.c index 5d18c84e..7274f6e9 100755 --- a/interfaces/innerkits/fs_manager/fstab_mount.c +++ b/interfaces/innerkits/fs_manager/fstab_mount.c @@ -318,12 +318,8 @@ static int GetSlotInfoFromParameter(const char *slotInfoName) static int GetSlotInfoFromCmdLine(const char *slotInfoName) { char value[MAX_BUFFER_LEN] = {0}; - char *buffer = ReadFileData(BOOT_CMD_LINE); - BEGET_ERROR_CHECK(buffer != NULL, return -1, "Failed to read cmdline"); - BEGET_INFO_CHECK(GetProcCmdlineValue(slotInfoName, buffer, value, MAX_BUFFER_LEN) == 0, - free(buffer); buffer = NULL; return -1, "Failed to get %s value from cmdline", slotInfoName); - free(buffer); - buffer = NULL; + BEGET_INFO_CHECK(GetParameterFromCmdLine(slotInfoName, value, MAX_BUFFER_LEN) == 0, + return -1, "Failed to get %s value from cmdline", slotInfoName); return atoi(value); } diff --git a/interfaces/innerkits/fs_manager/libfs_hvb/fs_hvb.c b/interfaces/innerkits/fs_manager/libfs_hvb/fs_hvb.c index a7ae5079..186b7819 100755 --- a/interfaces/innerkits/fs_manager/libfs_hvb/fs_hvb.c +++ b/interfaces/innerkits/fs_manager/libfs_hvb/fs_hvb.c @@ -512,20 +512,10 @@ int FsHvbGetValueFromCmdLine(char *val, size_t size, const char *key) FS_HVB_RETURN_ERR_IF_NULL(val); FS_HVB_RETURN_ERR_IF_NULL(key); - - char *buffer = ReadFileData(FS_HVB_CMDLINE_PATH); - if (buffer == NULL) { - BEGET_LOGE("error, read %s fail", FS_HVB_CMDLINE_PATH); - return -1; - } - - ret = GetProcCmdlineValue(key, buffer, val, size); + ret = GetParameterFromCmdLine(key, val, size); if (ret != 0) { BEGET_LOGE("error 0x%x, get %s val from cmdline", ret, key); } - - free(buffer); - return ret; } diff --git a/services/include/init_utils.h b/services/include/init_utils.h index 6843ca08..b64dea47 100644 --- a/services/include/init_utils.h +++ b/services/include/init_utils.h @@ -95,6 +95,7 @@ void CloseStdio(void); void RedirectStdio(int fd); int GetServiceGroupIdByPid(pid_t pid, gid_t *gids, uint32_t gidSize); +int GetParameterFromCmdLine(const char *paramName, char *value, size_t valueLen); #ifdef __cplusplus #if __cplusplus } diff --git a/services/init/init_group_manager.c b/services/init/init_group_manager.c index 3343742a..1018d651 100644 --- a/services/init/init_group_manager.c +++ b/services/init/init_group_manager.c @@ -190,17 +190,13 @@ void InitServiceSpace(void) } // get boot mode, set default mode strcpy_s(g_initWorkspace.groupModeStr, sizeof(g_initWorkspace.groupModeStr), BOOT_GROUP_DEFAULT); - char *data = ReadFileData(BOOT_CMD_LINE); - if (data != NULL) { - int ret = GetProcCmdlineValue(BOOT_GROUP_NAME, data, - g_initWorkspace.groupModeStr, sizeof(g_initWorkspace.groupModeStr)); - if (ret != 0) { - INIT_LOGV("Failed to get boot group"); - if (GetBootModeFromMisc() == GROUP_CHARGE) { - strcpy_s(g_initWorkspace.groupModeStr, sizeof(g_initWorkspace.groupModeStr), "device.charge.group"); - } + int ret = GetParameterFromCmdLine(BOOT_GROUP_NAME, + g_initWorkspace.groupModeStr, sizeof(g_initWorkspace.groupModeStr)); + if (ret != 0) { + INIT_LOGV("Failed to get boot group"); + if (GetBootModeFromMisc() == GROUP_CHARGE) { + strcpy_s(g_initWorkspace.groupModeStr, sizeof(g_initWorkspace.groupModeStr), "device.charge.group"); } - free(data); } INIT_LOGI("boot start %s", g_initWorkspace.groupModeStr); g_initWorkspace.groupMode = GetBootGroupMode(); diff --git a/services/log/init_log.c b/services/log/init_log.c index c231f25f..fa00f7ee 100644 --- a/services/log/init_log.c +++ b/services/log/init_log.c @@ -149,13 +149,7 @@ INIT_LOCAL_API void EnableInitLogFromCmdline(void) { SetInitCommLog(InitLog); char level[MAX_BUFFER_LEN] = {0}; - char *buffer = ReadFileData(BOOT_CMD_LINE); - if (buffer == NULL) { - INIT_LOGE("Failed to read \"/proc/cmdline\""); - return; - } - int ret = GetProcCmdlineValue("initloglevel", buffer, level, MAX_BUFFER_LEN); - free(buffer); + int ret = GetParameterFromCmdLine("initloglevel", level, MAX_BUFFER_LEN); if (ret == 0) { errno = 0; unsigned int logLevel = (unsigned int)strtoul(level, 0, 10); // 10 is decimal diff --git a/services/modules/seccomp/seccomp_policy_static.c b/services/modules/seccomp/seccomp_policy_static.c index 98f82cc4..bccc31e7 100644 --- a/services/modules/seccomp/seccomp_policy_static.c +++ b/services/modules/seccomp/seccomp_policy_static.c @@ -21,7 +21,6 @@ static int SetSystemSeccompPolicy(int id, const char *name, int argc, const char **argv) { - PLUGIN_LOGI("SetSystemSeccompPolicy argc %d %s", argc, name); PLUGIN_CHECK(argc == 2, return -1, "Invalid parameter"); SeccompFilterType type = SYSTEM_SA; if (strncmp(SA_MAIN_PATH, argv[1], strlen(SA_MAIN_PATH)) != 0) { @@ -39,7 +38,6 @@ static int SetSeccompPolicyInit(void) { if (g_executorId == -1) { g_executorId = AddCmdExecutor("SetSeccompPolicy", SetSystemSeccompPolicy); - PLUGIN_LOGI("SetSeccompPolicy executorId %d", g_executorId); } return 0; } diff --git a/services/param/linux/param_request.c b/services/param/linux/param_request.c index cc06d09f..ca250829 100644 --- a/services/param/linux/param_request.c +++ b/services/param/linux/param_request.c @@ -45,6 +45,18 @@ __attribute__((constructor)) static void ParameterInit(void) ops.setfilecon = NULL; #endif InitParamWorkSpace(1, &ops); + + // modify log level + char logLevel[2] = {0}; // 2 is set param "persist.init.debug.loglevel" value length. + 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."); + errno = 0; + int level = atoi(logLevel); + if (errno != 0) { + return; + } + SetInitLogLevel((InitLogLevel)level); } __attribute__((destructor)) static void ParameterDeinit(void) diff --git a/services/utils/init_utils.c b/services/utils/init_utils.c index fe9398c8..53334217 100644 --- a/services/utils/init_utils.c +++ b/services/utils/init_utils.c @@ -674,3 +674,13 @@ char *TrimHead(char *str, char c) } return head; } + +int GetParameterFromCmdLine(const char *paramName, char *value, size_t valueLen) +{ + char *buffer = ReadFileData(BOOT_CMD_LINE); + BEGET_ERROR_CHECK(buffer != NULL, return -1, "Failed to read /proc/cmdline"); + int ret = GetProcCmdlineValue(paramName, buffer, value, valueLen); + free(buffer); + return ret; +} + diff --git a/ueventd/ueventd.c b/ueventd/ueventd.c index e443ba1e..831ab2f3 100755 --- a/ueventd/ueventd.c +++ b/ueventd/ueventd.c @@ -190,11 +190,9 @@ static void HandleRequiredBlockDeviceNodes(const struct Uevent *uevent, char **d INIT_LOGI("Handle required partitionName %s", uevent->partitionName); HandleBlockDeviceEvent(uevent); return; - } else { - INIT_LOGI("Handle required partitionName %s", uevent->partitionName); - INIT_LOGE("Handle required device %s", devices[i]); } } + INIT_LOGW("Not found device for partitionName %s ", uevent->partitionName); } static void HandleUeventRequired(const struct Uevent *uevent, char **devices, int num) @@ -360,13 +358,9 @@ void RetriggerUeventByPath(int sockFd, char *path) void RetriggerUevent(int sockFd, char **devices, int num) { - char *buffer = ReadFileData("/proc/cmdline"); - int ret = GetProcCmdlineValue("default_boot_device", buffer, bootDevice, CMDLINE_VALUE_LEN_MAX); + int ret = GetParameterFromCmdLine("default_boot_device", bootDevice, CMDLINE_VALUE_LEN_MAX); INIT_CHECK_ONLY_ELOG(ret == 0, "Failed get default_boot_device value from cmdline"); Trigger("/sys/block", sockFd, devices, num); Trigger("/sys/class", sockFd, devices, num); Trigger("/sys/devices", sockFd, devices, num); - if (buffer != NULL) { - free(buffer); - } } diff --git a/ueventd/ueventd_device_handler.c b/ueventd/ueventd_device_handler.c index 92b7fcfa..f4906bf4 100755 --- a/ueventd/ueventd_device_handler.c +++ b/ueventd/ueventd_device_handler.c @@ -95,9 +95,9 @@ static inline void AdjustDeviceNodePermissions(const char *deviceNode, uid_t uid } } +#if defined(WITH_SELINUX) && !defined(__RAMDISK__) static void SetDeviceLable(const char *path) { -#ifdef WITH_SELINUX int rc = 0; char buffer[PATH_MAX] = {}; const char *p = NULL; @@ -130,8 +130,8 @@ static void SetDeviceLable(const char *path) } return; -#endif } +#endif static int CreateDeviceNode(const struct Uevent *uevent, const char *deviceNode, char **symLinks, bool isBlock) { @@ -180,7 +180,9 @@ static int CreateDeviceNode(const struct Uevent *uevent, const char *deviceNode, if (symLinks != NULL) { CreateSymbolLinks(deviceNode, symLinks); } +#if defined(WITH_SELINUX) && !defined(__RAMDISK__) SetDeviceLable(deviceNode); +#endif // No matter what result the symbol links returns, // as long as create device node done, just returns success. rc = 0; -- GitLab