提交 e18e0d7f 编写于 作者: C cheng_jinsong

系统优化

Signed-off-by: Ncheng_jinsong <chengjinsong2@huawei.com>
上级 1a391451
......@@ -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;
......
......@@ -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);
}
......
......@@ -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;
}
......
......@@ -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
}
......
......@@ -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();
......
......@@ -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
......
......@@ -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;
}
......
......@@ -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)
......
......@@ -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;
}
......@@ -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);
}
}
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册