mirror of
https://gitee.com/openharmony/startup_init
synced 2024-11-30 22:01:06 +00:00
commit
19f4b40a15
@ -50,6 +50,8 @@ extern "C" {
|
||||
#define SERVICE_ATTR_NEEDWAIT 0x400 // service should execute waitpid while stopping
|
||||
#define SERVICE_ATTR_WITHOUT_SANDBOX 0x800 // make service not enter sandbox
|
||||
|
||||
#define SERVICE_ATTR_NOTIFY_STATE 0x1000 // service notify state
|
||||
|
||||
#define MAX_SERVICE_NAME 32
|
||||
#define MAX_APL_NAME 32
|
||||
#define MAX_ENV_NAME 64
|
||||
@ -155,7 +157,7 @@ typedef struct Service_ {
|
||||
size_t fdCount;
|
||||
TimerHandle timer;
|
||||
ServiceJobs serviceJobs;
|
||||
cpu_set_t cpuSet;
|
||||
cpu_set_t *cpuSet;
|
||||
struct ListNode extDataNode;
|
||||
} Service;
|
||||
#pragma pack()
|
||||
|
@ -264,15 +264,15 @@ static void PublishHoldFds(Service *service)
|
||||
|
||||
static int BindCpuCore(Service *service)
|
||||
{
|
||||
if (service == NULL) {
|
||||
if (service == NULL || service->cpuSet == NULL) {
|
||||
return SERVICE_SUCCESS;
|
||||
}
|
||||
if (CPU_COUNT(&service->cpuSet) == 0) {
|
||||
if (CPU_COUNT(service->cpuSet) == 0) {
|
||||
return SERVICE_SUCCESS;
|
||||
}
|
||||
#ifndef __LITEOS_A__
|
||||
int pid = getpid();
|
||||
INIT_ERROR_CHECK(sched_setaffinity(pid, sizeof(service->cpuSet), &service->cpuSet) == 0,
|
||||
INIT_ERROR_CHECK(sched_setaffinity(pid, sizeof(cpu_set_t), service->cpuSet) == 0,
|
||||
return SERVICE_FAILURE, "%s set affinity between process(pid=%d) with CPU's core failed", service->name, pid);
|
||||
INIT_LOGI("%s set affinity between process(pid=%d) with CPU's core successfully", service->name, pid);
|
||||
#endif
|
||||
@ -414,6 +414,8 @@ int ServiceStop(Service *service)
|
||||
"stop service %s pid %d failed! err %d.", service->name, service->pid, errno);
|
||||
NotifyServiceChange(service, SERVICE_STOPPING);
|
||||
INIT_LOGI("stop service %s, pid %d.", service->name, service->pid);
|
||||
service->pid = -1;
|
||||
NotifyServiceChange(service, SERVICE_STOPPED);
|
||||
return SERVICE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ Service *AddService(const char *name)
|
||||
node->data.service = service;
|
||||
service->name = node->name;
|
||||
service->status = SERVICE_IDLE;
|
||||
CPU_ZERO(&service->cpuSet);
|
||||
service->cpuSet = NULL;
|
||||
OH_ListInit(&service->extDataNode);
|
||||
g_serviceSpace.serviceCount++;
|
||||
INIT_LOGV("AddService %s", node->name);
|
||||
@ -150,6 +150,10 @@ void ReleaseService(Service *service)
|
||||
}
|
||||
service->serviceJobs.jobsName[i] = NULL;
|
||||
}
|
||||
if (service->cpuSet != NULL) {
|
||||
free(service->cpuSet);
|
||||
service->cpuSet = NULL;
|
||||
}
|
||||
#ifndef OHOS_LITE
|
||||
// clear ext data
|
||||
SERVICE_INFO_CTX ctx = {0};
|
||||
@ -684,6 +688,11 @@ static int GetCpuArgs(const cJSON *argJson, const char *name, Service *service)
|
||||
int count = cJSON_GetArraySize(obj);
|
||||
int cpus = -1;
|
||||
int cpuNumMax = sysconf(_SC_NPROCESSORS_CONF);
|
||||
if (count > 0 && service->cpuSet == NULL) {
|
||||
service->cpuSet = malloc(sizeof(cpu_set_t));
|
||||
INIT_ERROR_CHECK(service->cpuSet != NULL, return SERVICE_FAILURE, "Failed to malloc for cpuset");
|
||||
}
|
||||
CPU_ZERO(service->cpuSet);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
cJSON *item = cJSON_GetArrayItem(obj, i);
|
||||
INIT_ERROR_CHECK(item != NULL, return SERVICE_FAILURE, "prase invalid");
|
||||
@ -692,10 +701,10 @@ static int GetCpuArgs(const cJSON *argJson, const char *name, Service *service)
|
||||
INIT_LOGW("%s core number %d of CPU cores does not exist", service->name, cpus);
|
||||
continue;
|
||||
}
|
||||
if (CPU_ISSET(cpus, &service->cpuSet)) {
|
||||
if (CPU_ISSET(cpus, service->cpuSet)) {
|
||||
continue;
|
||||
}
|
||||
CPU_SET(cpus, &service->cpuSet);
|
||||
CPU_SET(cpus, service->cpuSet);
|
||||
}
|
||||
return SERVICE_SUCCESS;
|
||||
}
|
||||
@ -836,6 +845,8 @@ int ParseOneService(const cJSON *curItem, Service *service)
|
||||
INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get disabled flag for service %s", service->name);
|
||||
ret = GetServiceAttr(curItem, service, CONSOLE_STR_IN_CFG, SERVICE_ATTR_CONSOLE, NULL);
|
||||
INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get console for service %s", service->name);
|
||||
ret = GetServiceAttr(curItem, service, "notify-state", SERVICE_ATTR_NOTIFY_STATE, NULL);
|
||||
INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get notify-state for service %s", service->name);
|
||||
|
||||
ParseOneServiceArgs(curItem, service);
|
||||
ret = GetServiceSandbox(curItem, service);
|
||||
|
@ -295,9 +295,15 @@ static int UpdaterCheckParamPermission(const ParamSecurityLabel *srcLabel, const
|
||||
|
||||
static int OpenPermissionWorkSpace(const char *path)
|
||||
{
|
||||
static int loadLabels = 0;
|
||||
UNUSED(path);
|
||||
// open workspace by readonly
|
||||
return SelinuxGetAllLabel(1);
|
||||
int ret = 0;
|
||||
if (loadLabels == 0) {
|
||||
// open workspace by readonly
|
||||
ret = SelinuxGetAllLabel(1);
|
||||
}
|
||||
loadLabels = 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
INIT_LOCAL_API int RegisterSecuritySelinuxOps(ParamSecurityOps *ops, int isInit)
|
||||
|
Loading…
Reference in New Issue
Block a user