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

!787 优化service内存占用

Merge pull request !787 from Mupceet/initselinux
...@@ -126,7 +126,7 @@ typedef struct { ...@@ -126,7 +126,7 @@ typedef struct {
typedef struct Service_ { typedef struct Service_ {
char *name; char *name;
#ifdef WITH_SELINUX #ifdef WITH_SELINUX
char secon[MAX_SECON_LEN]; char *secon;
#endif // WITH_SELINUX #endif // WITH_SELINUX
int pid; int pid;
int crashCnt; int crashCnt;
......
...@@ -171,7 +171,7 @@ static int WritePid(const Service *service) ...@@ -171,7 +171,7 @@ static int WritePid(const Service *service)
void SetSecon(Service *service) void SetSecon(Service *service)
{ {
#ifdef WITH_SELINUX #ifdef WITH_SELINUX
if (*(service->secon)) { if (service->secon != NULL) {
if (setexeccon(service->secon) < 0) { if (setexeccon(service->secon) < 0) {
INIT_LOGE("failed to set service %s's secon (%s).", service->name, service->secon); INIT_LOGE("failed to set service %s's secon (%s).", service->name, service->secon);
_exit(PROCESS_EXIT_CODE); _exit(PROCESS_EXIT_CODE);
......
...@@ -93,6 +93,11 @@ void DumpOneService(const Service *service) ...@@ -93,6 +93,11 @@ void DumpOneService(const Service *service)
int size = 0; int size = 0;
const InitArgInfo *statusMap = GetServieStatusMap(&size); const InitArgInfo *statusMap = GetServieStatusMap(&size);
printf("\tservice name: [%s] \n", service->name); printf("\tservice name: [%s] \n", service->name);
#ifdef WITH_SELINUX
if (service->secon != NULL) {
printf("\tservice secon: [%s] \n", service->secon);
}
#endif
printf("\tservice pid: [%d] \n", service->pid); printf("\tservice pid: [%d] \n", service->pid);
printf("\tservice crashCnt: [%d] \n", service->crashCnt); printf("\tservice crashCnt: [%d] \n", service->crashCnt);
printf("\tservice attribute: [%d] \n", service->attribute); printf("\tservice attribute: [%d] \n", service->attribute);
...@@ -204,6 +209,12 @@ void ReleaseService(Service *service) ...@@ -204,6 +209,12 @@ void ReleaseService(Service *service)
if (service == NULL) { if (service == NULL) {
return; return;
} }
#ifdef WITH_SELINUX
if (service->secon != NULL) {
free(service->secon);
service->secon = NULL;
}
#endif
FreeServiceArg(&service->pathArgs); FreeServiceArg(&service->pathArgs);
FreeServiceArg(&service->writePidArgs); FreeServiceArg(&service->writePidArgs);
FreeServiceArg(&service->capsArgs); FreeServiceArg(&service->capsArgs);
...@@ -788,7 +799,12 @@ int ParseOneService(const cJSON *curItem, Service *service) ...@@ -788,7 +799,12 @@ int ParseOneService(const cJSON *curItem, Service *service)
INIT_CHECK_RETURN_VALUE(curItem != NULL && service != NULL, SERVICE_FAILURE); INIT_CHECK_RETURN_VALUE(curItem != NULL && service != NULL, SERVICE_FAILURE);
int ret = 0; int ret = 0;
#ifdef WITH_SELINUX #ifdef WITH_SELINUX
(void)GetStringItem(curItem, SECON_STR_IN_CFG, service->secon, MAX_SECON_LEN); size_t strLen = 0;
char *fieldStr = GetStringValue(curItem, SECON_STR_IN_CFG, &strLen);
if (fieldStr != NULL) {
service->secon = strdup(fieldStr);
INIT_ERROR_CHECK(service->secon != NULL, return -1, "Failed to get secon for service %s", service->name);
}
#endif // WITH_SELINUX #endif // WITH_SELINUX
ret = GetServiceArgs(curItem, "path", MAX_PATH_ARGS_CNT, &service->pathArgs); ret = GetServiceArgs(curItem, "path", MAX_PATH_ARGS_CNT, &service->pathArgs);
INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get path for service %s", service->name); INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get path for service %s", service->name);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册