提交 00a7a514 编写于 作者: 熊磊 提交者: Gitee

Merge branch 'master' of gitee.com:openharmony/startup_init_lite into init0210xyt

Signed-off-by: Nxionglei <xionglei6@huawei.com>
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
static int BuildClientSocket(void) static int BuildClientSocket(void)
{ {
int sockFd; int sockFd;
sockFd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); sockFd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (sockFd < 0) { if (sockFd < 0) {
BEGET_LOGE("Failed to build socket, err = %d", errno); BEGET_LOGE("Failed to build socket, err = %d", errno);
return -1; return -1;
......
...@@ -40,7 +40,7 @@ int BuildControlMessage(struct msghdr *msghdr, int *fds, int fdCount, bool send ...@@ -40,7 +40,7 @@ int BuildControlMessage(struct msghdr *msghdr, int *fds, int fdCount, bool send
msghdr->msg_controllen += CMSG_SPACE(sizeof(struct ucred)); msghdr->msg_controllen += CMSG_SPACE(sizeof(struct ucred));
} }
msghdr->msg_control = calloc(1, (msghdr->msg_controllen == 0 ? 1 : msghdr->msg_controllen)); msghdr->msg_control = calloc(1, ((msghdr->msg_controllen == 0) ? 1 : msghdr->msg_controllen));
if (msghdr->msg_control == NULL) { if (msghdr->msg_control == NULL) {
BEGET_LOGE("Failed to build control message"); BEGET_LOGE("Failed to build control message");
return -1; return -1;
......
...@@ -170,7 +170,8 @@ static int DoResizeF2fs(const char* device, const unsigned long long size) ...@@ -170,7 +170,8 @@ static int DoResizeF2fs(const char* device, const unsigned long long size)
char **argv = (char **)cmd; char **argv = (char **)cmd;
ret = ExecCommand(argc, argv); ret = ExecCommand(argc, argv);
} else { } else {
unsigned long long realSize = size * ((unsigned long long)1024 * 1024 / 512); unsigned long long realSize = size *
((unsigned long long)RESIZE_BUFFER_SIZE * RESIZE_BUFFER_SIZE / FS_MANAGER_BUFFER_SIZE);
char sizeStr[RESIZE_BUFFER_SIZE] = {0}; char sizeStr[RESIZE_BUFFER_SIZE] = {0};
sprintf_s(sizeStr, RESIZE_BUFFER_SIZE, "%llu", realSize); sprintf_s(sizeStr, RESIZE_BUFFER_SIZE, "%llu", realSize);
char *cmd[] = { char *cmd[] = {
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#define SYSCAP_MAX_SIZE 100 #define SYSCAP_MAX_SIZE 100
#define SYSCAP_PREFIX_NAME "SystemCapability" #define SYSCAP_PREFIX_NAME "SystemCapability"
#define CONST_SYSCAP_PREFIX_NAME "const.SystemCapability"
bool HasSystemCapability(const char *cap) bool HasSystemCapability(const char *cap)
{ {
...@@ -32,12 +33,12 @@ bool HasSystemCapability(const char *cap) ...@@ -32,12 +33,12 @@ bool HasSystemCapability(const char *cap)
char paramValue[PARAM_VALUE_LEN_MAX] = { 0 }; char paramValue[PARAM_VALUE_LEN_MAX] = { 0 };
unsigned int valueLen = PARAM_VALUE_LEN_MAX; unsigned int valueLen = PARAM_VALUE_LEN_MAX;
if (strncmp(SYSCAP_PREFIX_NAME, cap, sizeof(SYSCAP_PREFIX_NAME) - 1) != 0) { if (strncmp(SYSCAP_PREFIX_NAME, cap, sizeof(SYSCAP_PREFIX_NAME) - 1) == 0) {
if (strncpy_s(capName, sizeof(capName), cap, sizeof(capName) - 1) < 0) { if (snprintf_s(capName, SYSCAP_MAX_SIZE, SYSCAP_MAX_SIZE - 1, "const.%s", cap) == -1) {
BEGET_LOGE("Failed strncpy_s err=%d", errno); BEGET_LOGE("Failed snprintf_s err=%d", errno);
return false; return false;
} }
} else if (snprintf_s(capName, SYSCAP_MAX_SIZE, SYSCAP_MAX_SIZE - 1, SYSCAP_PREFIX_NAME".%s", cap) == -1) { } else if (snprintf_s(capName, SYSCAP_MAX_SIZE, SYSCAP_MAX_SIZE - 1, CONST_SYSCAP_PREFIX_NAME".%s", cap) == -1) {
BEGET_LOGE("Failed snprintf_s err=%d", errno); BEGET_LOGE("Failed snprintf_s err=%d", errno);
return false; return false;
} }
......
...@@ -275,6 +275,23 @@ if (defined(ohos_lite)) { ...@@ -275,6 +275,23 @@ if (defined(ohos_lite)) {
part_name = "init" part_name = "init"
} }
ohos_prebuilt_etc("syscap.para") {
source =
"${preloader_output_dir}/${product_name}/system/etc/param/syscap.para"
module_install_dir = "etc/param/"
part_name = "init"
}
ohos_prebuilt_etc("syscap.json") {
source = "${preloader_output_dir}/${product_name}/system/etc/syscap.json"
part_name = "init"
}
ohos_prebuilt_etc("systemcapability.json") {
source = "${preloader_output_dir}/${product_name}/system/etc/SystemCapability.json"
part_name = "init"
}
group("init_etc") { group("init_etc") {
deps = [ deps = [
":boot.group", ":boot.group",
...@@ -286,6 +303,9 @@ if (defined(ohos_lite)) { ...@@ -286,6 +303,9 @@ if (defined(ohos_lite)) {
":ohos.para", ":ohos.para",
":ohos.para.dac", ":ohos.para.dac",
":passwd", ":passwd",
":syscap.json",
":syscap.para",
":systemcapability.json",
] ]
} }
} }
...@@ -202,7 +202,7 @@ static int32_t BShellParamCmdLs(BShellHandle shell, int32_t argc, char *argv[]) ...@@ -202,7 +202,7 @@ static int32_t BShellParamCmdLs(BShellHandle shell, int32_t argc, char *argv[])
char *buffer = GetLocalBuffer(&buffSize); char *buffer = GetLocalBuffer(&buffSize);
char *realParameter = GetRealParameter(shell, (input == NULL) ? "" : input, buffer, buffSize); char *realParameter = GetRealParameter(shell, (input == NULL) ? "" : input, buffer, buffSize);
BSH_CHECK(realParameter != NULL, return BSH_INVALID_PARAM, "Invalid shell env"); BSH_CHECK(realParameter != NULL, return BSH_INVALID_PARAM, "Invalid shell env");
char *prefix = strdup(strlen(realParameter) == 0 ? "#" : realParameter); char *prefix = strdup((strlen(realParameter) == 0) ? "#" : realParameter);
BSH_LOGV("BShellParamCmdLs prefix %s", prefix); BSH_LOGV("BShellParamCmdLs prefix %s", prefix);
int ret = 0; int ret = 0;
if (all != 0) { if (all != 0) {
......
...@@ -14,11 +14,11 @@ ...@@ -14,11 +14,11 @@
*/ */
#include "service_control.h" #include "service_control.h"
#include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "begetctl.h" #include "begetctl.h"
#include "securec.h"
#include "sys_param.h" #include "sys_param.h"
#define SERVICE_START_NUMBER 2 #define SERVICE_START_NUMBER 2
......
...@@ -152,7 +152,7 @@ void BShellEnvOutputResult(BShellHandle handle, int32_t result) ...@@ -152,7 +152,7 @@ void BShellEnvOutputResult(BShellHandle handle, int32_t result)
static void BShellEnvOutputParam(BShellHandle handle, char *var) static void BShellEnvOutputParam(BShellHandle handle, char *var)
{ {
BShellEnvOutput(handle, var[0] == '$' ? var + 1 : var); BShellEnvOutput(handle, (var[0] == '$') ? var + 1 : var);
BShellEnvOutputString(handle, " = "); BShellEnvOutputString(handle, " = ");
BShellEnvOutputString(handle, BShellEnvGetStringParam(handle, var)); BShellEnvOutputString(handle, BShellEnvGetStringParam(handle, var));
} }
......
...@@ -4,6 +4,7 @@ system:x:1000: ...@@ -4,6 +4,7 @@ system:x:1000:
radio:x:1001: radio:x:1001:
bluetooth:x:1002: bluetooth:x:1002:
graphics:x:1003: graphics:x:1003:
file_manager:x:1006:
log:x:1007: log:x:1007:
user_data_rw:x:1008: user_data_rw:x:1008:
dfs:x:1009: dfs:x:1009:
......
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
"start watchdog_service", "start watchdog_service",
"mkdir /data", "mkdir /data",
"mount_fstab /vendor/etc/fstab.${ohos.boot.hardware}", "mount_fstab /vendor/etc/fstab.${ohos.boot.hardware}",
"chown system system /data",
"chmod 0771 /data",
"mkdir /data/service 0711 root root",
"mkdir /data/service/el0 0711 root root",
"load_persist_params ", "load_persist_params ",
"chown access_token access_token /dev/access_token_id", "chown access_token access_token /dev/access_token_id",
"chmod 0666 /dev/access_token_id" "chmod 0666 /dev/access_token_id"
...@@ -143,6 +147,9 @@ ...@@ -143,6 +147,9 @@
"chown system system /sys/power/state", "chown system system /sys/power/state",
"chown system system /sys/power/wakeup_count", "chown system system /sys/power/wakeup_count",
"chmod 0660 /sys/power/state", "chmod 0660 /sys/power/state",
"mount pstore pstore /sys/fs/pstore nodev noexec nosuid",
"chown system log /sys/fs/pstore",
"chmod 0550 /sys/fs/pstore",
"ifup lo", "ifup lo",
"hostname localhost", "hostname localhost",
"domainname localdomain" "domainname localdomain"
...@@ -184,8 +191,6 @@ ...@@ -184,8 +191,6 @@
}, { }, {
"name" : "post-fs-data", "name" : "post-fs-data",
"cmds" : [ "cmds" : [
"chown system system /data",
"chmod 0771 /data",
"mkdir /data/app 0711 root root", "mkdir /data/app 0711 root root",
"mkdir /data/app/el1 0711 root root", "mkdir /data/app/el1 0711 root root",
"mkdir /data/app/el1/bundle 0711 root root", "mkdir /data/app/el1/bundle 0711 root root",
...@@ -193,8 +198,6 @@ ...@@ -193,8 +198,6 @@
"mkdir /data/app/el2 0711 root root", "mkdir /data/app/el2 0711 root root",
"mkdir /data/app/el3 0711 root root", "mkdir /data/app/el3 0711 root root",
"mkdir /data/app/el4 0711 root root", "mkdir /data/app/el4 0711 root root",
"mkdir /data/service 0711 root root",
"mkdir /data/service/el0 0711 root root",
"mkdir /data/service/el1 0711 root root", "mkdir /data/service/el1 0711 root root",
"mkdir /data/service/el1/public 0711 root root", "mkdir /data/service/el1/public 0711 root root",
"mkdir /data/service/el1/public/AbilityManagerService 0711 system system", "mkdir /data/service/el1/public/AbilityManagerService 0711 system system",
......
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
"mkdir /data", "mkdir /data",
"mount ext4 /dev/block/platform/soc/10100000.himci.eMMC/by-name/vendor /vendor wait rdonly barrier=1", "mount ext4 /dev/block/platform/soc/10100000.himci.eMMC/by-name/vendor /vendor wait rdonly barrier=1",
"mount ext4 /dev/block/platform/soc/10100000.himci.eMMC/by-name/userdata /data wait nosuid nodev noatime barrier=1,data=ordered,noauto_da_alloc", "mount ext4 /dev/block/platform/soc/10100000.himci.eMMC/by-name/userdata /data wait nosuid nodev noatime barrier=1,data=ordered,noauto_da_alloc",
"chown system system /data",
"chmod 0771 /data",
"mkdir /data/service 0711 root root",
"mkdir /data/service/el0 0711 root root",
"load_persist_params " "load_persist_params "
] ]
}, { }, {
...@@ -184,8 +188,6 @@ ...@@ -184,8 +188,6 @@
}, { }, {
"name" : "post-fs-data", "name" : "post-fs-data",
"cmds" : [ "cmds" : [
"chown system system /data",
"chmod 0771 /data",
"mkdir /data/app 0711 root root", "mkdir /data/app 0711 root root",
"mkdir /data/app/el1 0711 root root", "mkdir /data/app/el1 0711 root root",
"mkdir /data/app/el1/bundle 0711 root root", "mkdir /data/app/el1/bundle 0711 root root",
...@@ -193,8 +195,6 @@ ...@@ -193,8 +195,6 @@
"mkdir /data/app/el2 0711 root root", "mkdir /data/app/el2 0711 root root",
"mkdir /data/app/el3 0711 root root", "mkdir /data/app/el3 0711 root root",
"mkdir /data/app/el4 0711 root root", "mkdir /data/app/el4 0711 root root",
"mkdir /data/service 0711 root root",
"mkdir /data/service/el0 0711 root root",
"mkdir /data/service/el1 0711 root root", "mkdir /data/service/el1 0711 root root",
"mkdir /data/service/el1/public 0711 root root", "mkdir /data/service/el1/public 0711 root root",
"mkdir /data/service/el2 0711 root root", "mkdir /data/service/el2 0711 root root",
......
...@@ -4,6 +4,7 @@ system:x:1000:1000:::/bin/false ...@@ -4,6 +4,7 @@ system:x:1000:1000:::/bin/false
radio:x:1001:1001:::/bin/false radio:x:1001:1001:::/bin/false
bluetooth:x:1002:1002:::/bin/false bluetooth:x:1002:1002:::/bin/false
graphics:x:1003:1003:::/bin/false graphics:x:1003:1003:::/bin/false
file_manager:x:1006:1006:::/bin/false
log:x:1007:1007:::/bin/false log:x:1007:1007:::/bin/false
user_data_rw:x:1008:1008:::/bin/false user_data_rw:x:1008:1008:::/bin/false
dfs:x:1009:1009:::/bin/false dfs:x:1009:1009:::/bin/false
......
...@@ -19,6 +19,6 @@ extern "C" { ...@@ -19,6 +19,6 @@ extern "C" {
#endif #endif
void RegisterFdHoldWatcher(int sock); void RegisterFdHoldWatcher(int sock);
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { }
#endif #endif
#endif // BASE_STARTUP_INITLITE_FD_HOLDER_SERVICE_H #endif // BASE_STARTUP_INITLITE_FD_HOLDER_SERVICE_H
...@@ -30,6 +30,7 @@ extern "C" { ...@@ -30,6 +30,7 @@ extern "C" {
#define DEFAULT_UID_KIT_FRAMEWORK 3 #define DEFAULT_UID_KIT_FRAMEWORK 3
// max length of one param/path // max length of one param/path
#define MAX_ONE_ARG_LEN 200 #define MAX_ONE_ARG_LEN 200
#define FD_HOLDER_BUFFER_SIZE 4096
#define UNUSED(x) (void)(x) #define UNUSED(x) (void)(x)
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
#include <sched.h>
#include <stdio.h>
#include "cJSON.h" #include "cJSON.h"
#include "init_cmds.h" #include "init_cmds.h"
...@@ -89,11 +91,6 @@ typedef enum { ...@@ -89,11 +91,6 @@ typedef enum {
END_RECV_READY, END_RECV_READY,
} ServiceEndMode; } ServiceEndMode;
typedef struct {
int *cpus;
int cpuNum;
} CpuArgs;
typedef struct { typedef struct {
uid_t uID; uid_t uID;
gid_t *gIDArray; gid_t *gIDArray;
...@@ -148,7 +145,7 @@ typedef struct Service_ { ...@@ -148,7 +145,7 @@ typedef struct Service_ {
size_t fdCount; size_t fdCount;
TimerHandle timer; TimerHandle timer;
ServiceJobs serviceJobs; ServiceJobs serviceJobs;
CpuArgs cpuInfo; cpu_set_t cpuSet;
} Service; } Service;
int ServiceStart(Service *service); int ServiceStart(Service *service);
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
#include <signal.h> #include <signal.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sched.h>
#include <stdio.h>
#ifdef __MUSL__ #ifdef __MUSL__
#include <stropts.h> #include <stropts.h>
#endif #endif
...@@ -238,32 +236,17 @@ static void PublishHoldFds(Service *service) ...@@ -238,32 +236,17 @@ static void PublishHoldFds(Service *service)
static int BindCpuCore(Service *service) static int BindCpuCore(Service *service)
{ {
if (service == NULL || service->cpuInfo.cpuNum <= 0) { if (service == NULL) {
return SERVICE_SUCCESS; return SERVICE_SUCCESS;
} }
long cpuNum = sysconf(_SC_NPROCESSORS_CONF); #ifndef __LITEOS__
INIT_ERROR_CHECK(service->cpuInfo.cpuNum <= cpuNum, return SERVICE_FAILURE, int pid = getpid();
"%s cpus cores exceeds total number of device cores", service->name); if (sched_setaffinity(pid, sizeof(service->cpuSet), &service->cpuSet) != 0) {
int index = 0; INIT_LOGE("%s set affinity between process(pid=%d) with CPU's core failed", service->name, pid);
cpu_set_t setMask; return SERVICE_FAILURE;
CPU_ZERO(&setMask);
int pid = getpid();
for (int i = 0; i < service->cpuInfo.cpuNum; i++) {
index = (int)service->cpuInfo.cpus[i];
if ((int)cpuNum <= index) {
INIT_LOGW("%s core number %d of CPU cores does not exist", service->name, index);
continue;
}
if (CPU_ISSET(index, &setMask)) {
continue;
}
CPU_SET(index, &setMask);
}
if (sched_setaffinity(pid, sizeof(setMask), &setMask) != 0) {
INIT_LOGI("%s set affinity between process(pid=%d) with CPU's core failed", service->name, pid);
} else {
INIT_LOGE("%s set affinity between process(pid=%d) with CPU's core successfully", service->name, pid);
} }
INIT_LOGI("%s set affinity between process(pid=%d) with CPU's core successfully", service->name, pid);
#endif
return SERVICE_SUCCESS; return SERVICE_SUCCESS;
} }
......
...@@ -114,10 +114,10 @@ static char *GetAbsolutePath(const char *path, const char *cfgName, char *buffer ...@@ -114,10 +114,10 @@ static char *GetAbsolutePath(const char *path, const char *cfgName, char *buffer
ext = strcmp(cfgName + cfgNameLen - strlen(".cfg"), ".cfg") == 0; ext = strcmp(cfgName + cfgNameLen - strlen(".cfg"), ".cfg") == 0;
} }
if (cfgName[0] != '/') { if (cfgName[0] != '/') {
const char *format = (ext != 0) ? "%s/%s" : "%s/%s.cfg"; const char *format = ((ext != 0) ? "%s/%s" : "%s/%s.cfg");
len = sprintf_s(buffer, buffSize, format, path, cfgName); len = sprintf_s(buffer, buffSize, format, path, cfgName);
} else { } else {
const char *format = (ext != 0) ? "%s" : "%s.cfg"; const char *format = ((ext != 0) ? "%s" : "%s.cfg");
len = sprintf_s(buffer, buffSize, format, cfgName); len = sprintf_s(buffer, buffSize, format, cfgName);
} }
if (len <= 0) { if (len <= 0) {
......
...@@ -175,6 +175,7 @@ Service *AddService(const char *name) ...@@ -175,6 +175,7 @@ Service *AddService(const char *name)
node->data.service = service; node->data.service = service;
service->name = node->name; service->name = node->name;
service->status = SERVICE_IDLE; service->status = SERVICE_IDLE;
CPU_ZERO(&service->cpuSet);
g_serviceSpace.serviceCount++; g_serviceSpace.serviceCount++;
INIT_LOGV("AddService %s", node->name); INIT_LOGV("AddService %s", node->name);
return service; return service;
...@@ -203,11 +204,6 @@ void ReleaseService(Service *service) ...@@ -203,11 +204,6 @@ void ReleaseService(Service *service)
FreeServiceArg(&service->writePidArgs); FreeServiceArg(&service->writePidArgs);
FreeServiceArg(&service->capsArgs); FreeServiceArg(&service->capsArgs);
if (service->cpuInfo.cpus != NULL) {
free(service->cpuInfo.cpus);
service->cpuInfo.cpus = NULL;
}
service->cpuInfo.cpuNum = 0;
if (service->servPerm.caps != NULL) { if (service->servPerm.caps != NULL) {
free(service->servPerm.caps); free(service->servPerm.caps);
service->servPerm.caps = NULL; service->servPerm.caps = NULL;
...@@ -274,7 +270,7 @@ static int GetServiceArgs(const cJSON *argJson, const char *name, int maxCount, ...@@ -274,7 +270,7 @@ static int GetServiceArgs(const cJSON *argJson, const char *name, int maxCount,
for (int i = 0; i < count + 1; ++i) { for (int i = 0; i < count + 1; ++i) {
args->argv[i] = NULL; args->argv[i] = NULL;
} }
// ServiceArgs have a variety of uses, some requiring a NULL ending, some not // ServiceArgs have a variety of uses, some requiring a NULL ending, some not
if (strcmp(name, D_CAPS_STR_IN_CFG) != 0) { if (strcmp(name, D_CAPS_STR_IN_CFG) != 0) {
args->count = count + 1; args->count = count + 1;
} else { } else {
...@@ -767,12 +763,7 @@ int GetCritical(const cJSON *curArrItem, Service *curServ, const char *attrName ...@@ -767,12 +763,7 @@ int GetCritical(const cJSON *curArrItem, Service *curServ, const char *attrName
return SERVICE_SUCCESS; return SERVICE_SUCCESS;
} }
static int Comparefunc(const void *before, const void *after) static int GetCpuArgs(const cJSON *argJson, const char *name, Service *service)
{
return (*(int*)before - *(int*)after);
}
static int GetCpuArgs(const cJSON *argJson, const char *name, CpuArgs *args)
{ {
INIT_ERROR_CHECK(argJson != NULL, return SERVICE_FAILURE, "Invalid argJson"); INIT_ERROR_CHECK(argJson != NULL, return SERVICE_FAILURE, "Invalid argJson");
cJSON *obj = cJSON_GetObjectItem(argJson, name); cJSON *obj = cJSON_GetObjectItem(argJson, name);
...@@ -781,31 +772,20 @@ static int GetCpuArgs(const cJSON *argJson, const char *name, CpuArgs *args) ...@@ -781,31 +772,20 @@ static int GetCpuArgs(const cJSON *argJson, const char *name, CpuArgs *args)
int ret = cJSON_IsArray(obj); int ret = cJSON_IsArray(obj);
INIT_ERROR_CHECK(ret, return SERVICE_FAILURE, "Invalid type"); INIT_ERROR_CHECK(ret, return SERVICE_FAILURE, "Invalid type");
int count = cJSON_GetArraySize(obj); int count = cJSON_GetArraySize(obj);
int tmpArray[count]; int cpus = -1;
int cpuNumMax = sysconf(_SC_NPROCESSORS_CONF);
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
cJSON *item = cJSON_GetArrayItem(obj, i); cJSON *item = cJSON_GetArrayItem(obj, i);
INIT_ERROR_CHECK(item != NULL, return SERVICE_FAILURE, "prase invalid"); INIT_ERROR_CHECK(item != NULL, return SERVICE_FAILURE, "prase invalid");
tmpArray[i] = (int)cJSON_GetNumberValue(item); cpus = (int)cJSON_GetNumberValue(item);
} if (cpuNumMax <= cpus) {
qsort(tmpArray, count, sizeof(int), Comparefunc); INIT_LOGW("%s core number %d of CPU cores does not exist", service->name, cpus);
int cpuCount = 0;
for (int j = 0; j < count; j++) {
if (j == 0 && tmpArray[0] == 0) {
tmpArray[cpuCount++] = 0;
continue; continue;
} }
if (tmpArray[j] != tmpArray[j-1]) { if (CPU_ISSET(cpus, &service->cpuSet)) {
tmpArray[cpuCount++] = tmpArray[j]; continue;
} }
} CPU_SET(cpus, &service->cpuSet);
args->cpus=(int*)malloc(cpuCount * sizeof(int));
INIT_ERROR_CHECK(args->cpus != NULL, return SERVICE_FAILURE, "Failed to malloc for argv");
for (int i = 0; i < cpuCount; ++i) {
args->cpus[i] = -1;
}
args->cpuNum = cpuCount;
for (int i = 0; i < count; ++i) {
args->cpus[i] = tmpArray[i];
} }
return SERVICE_SUCCESS; return SERVICE_SUCCESS;
} }
...@@ -843,7 +823,7 @@ int ParseOneService(const cJSON *curItem, Service *service) ...@@ -843,7 +823,7 @@ int ParseOneService(const cJSON *curItem, Service *service)
(void)GetServiceArgs(curItem, "writepid", MAX_WRITEPID_FILES, &service->writePidArgs); (void)GetServiceArgs(curItem, "writepid", MAX_WRITEPID_FILES, &service->writePidArgs);
(void)GetServiceArgs(curItem, D_CAPS_STR_IN_CFG, MAX_WRITEPID_FILES, &service->capsArgs); (void)GetServiceArgs(curItem, D_CAPS_STR_IN_CFG, MAX_WRITEPID_FILES, &service->capsArgs);
(void)GetStringItem(curItem, APL_STR_IN_CFG, service->apl, MAX_APL_NAME); (void)GetStringItem(curItem, APL_STR_IN_CFG, service->apl, MAX_APL_NAME);
(void)GetCpuArgs(curItem, CPU_CORE_STR_IN_CFG, &service->cpuInfo); (void)GetCpuArgs(curItem, CPU_CORE_STR_IN_CFG, service);
ret = GetServiceCaps(curItem, service); ret = GetServiceCaps(curItem, service);
INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get caps for service %s", service->name); INIT_ERROR_CHECK(ret == 0, return SERVICE_FAILURE, "Failed to get caps for service %s", service->name);
ret = GetDynamicService(curItem, service); ret = GetDynamicService(curItem, service);
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#endif #endif
#include "loop_event.h" #include "loop_event.h"
#include "parameter.h" #include "parameter.h"
#include "securec.h"
static void PrintSysInfo(void) static void PrintSysInfo(void)
{ {
......
...@@ -17,11 +17,6 @@ ...@@ -17,11 +17,6 @@
static const pid_t INIT_PROCESS_PID = 1; static const pid_t INIT_PROCESS_PID = 1;
int __attribute__((weak)) AtlibInit(void)
{
return 0;
}
int main(int argc, char * const argv[]) int main(int argc, char * const argv[])
{ {
int isSecondStage = 0; int isSecondStage = 0;
...@@ -40,7 +35,6 @@ int main(int argc, char * const argv[]) ...@@ -40,7 +35,6 @@ int main(int argc, char * const argv[])
LogInit(); LogInit();
} }
LogInit(); LogInit();
(void)AtlibInit();
SystemInit(); SystemInit();
SystemExecuteRcs(); SystemExecuteRcs();
SystemConfig(); SystemConfig();
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include "loop_event.h" #include "loop_event.h"
#include "securec.h" #include "securec.h"
#define MSG_ARRAY_INDEX 2
static void FreeFds(int *fds) static void FreeFds(int *fds)
{ {
if (fds != NULL) { if (fds != NULL) {
...@@ -190,7 +192,7 @@ static void HandlerFdHolder(int sock) ...@@ -190,7 +192,7 @@ static void HandlerFdHolder(int sock)
} }
char *serviceName = msg[0]; char *serviceName = msg[0];
char *action = msg[1]; char *action = msg[1];
char *pollStr = msg[2]; char *pollStr = msg[MSG_ARRAY_INDEX];
Service *service = GetServiceByName(serviceName); Service *service = GetServiceByName(serviceName);
if (CheckFdHolderPermission(service, requestPid) < 0) { if (CheckFdHolderPermission(service, requestPid) < 0) {
......
...@@ -47,8 +47,8 @@ static int FdHolderSockInit(void) ...@@ -47,8 +47,8 @@ static int FdHolderSockInit(void)
{ {
int sock = -1; int sock = -1;
int on = 1; int on = 1;
int fdHolderBufferSize = 4 * 1024; // 4KiB int fdHolderBufferSize = FD_HOLDER_BUFFER_SIZE; // 4KiB
sock = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); sock = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
if (sock < 0) { if (sock < 0) {
INIT_LOGE("Failed to create fd holder socket, err = %d", errno); INIT_LOGE("Failed to create fd holder socket, err = %d", errno);
return -1; return -1;
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "fs_manager/fs_manager.h" #include "fs_manager/fs_manager.h"
#include "init_cmds.h" #include "init_cmds.h"
#include "init_log.h" #include "init_log.h"
#include "securec.h"
int MountRequriedPartitions(const Fstab *fstab) int MountRequriedPartitions(const Fstab *fstab)
{ {
......
...@@ -99,10 +99,9 @@ int ServiceExec(const Service *service) ...@@ -99,10 +99,9 @@ int ServiceExec(const Service *service)
int SetAccessToken(const Service *service) int SetAccessToken(const Service *service)
{ {
INIT_ERROR_CHECK(service != NULL, return SERVICE_FAILURE, "%s failed", service->name); INIT_ERROR_CHECK(service != NULL, return SERVICE_FAILURE, "%s failed", service->name);
if (service->tokenId != 0 && SetSelfTokenID(service->tokenId) != 0) { int ret = SetSelfTokenID(service->tokenId);
INIT_LOGE("%s: token id %lld, set token id result %d", service->name, service->tokenId, errno); INIT_LOGI("%s: token id %lld, set token id result %d", service->name, service->tokenId, ret);
} return ret == 0 ? SERVICE_SUCCESS : SERVICE_FAILURE;
return 0;
} }
void GetAccessToken(void) void GetAccessToken(void)
...@@ -115,8 +114,7 @@ void GetAccessToken(void) ...@@ -115,8 +114,7 @@ void GetAccessToken(void)
service->capsArgs.argv = NULL; service->capsArgs.argv = NULL;
} }
if (strlen(service->apl) == 0) { if (strlen(service->apl) == 0) {
(void)strncpy_s(service->apl, sizeof(service->apl), (void)strncpy_s(service->apl, sizeof(service->apl), "system_core", sizeof(service->apl) - 1);
"system_core", sizeof(service->apl) - 1);
} }
uint64_t tokenId = GetAccessTokenId(service->name, (const char **)service->capsArgs.argv, uint64_t tokenId = GetAccessTokenId(service->name, (const char **)service->capsArgs.argv,
service->capsArgs.count, service->apl); service->capsArgs.count, service->apl);
......
...@@ -97,8 +97,7 @@ LE_STATUS LE_StartAsyncEvent(const LoopHandle loopHandle, ...@@ -97,8 +97,7 @@ LE_STATUS LE_StartAsyncEvent(const LoopHandle loopHandle,
const TaskHandle taskHandle, uint64_t eventId, const uint8_t *data, uint32_t buffLen) const TaskHandle taskHandle, uint64_t eventId, const uint8_t *data, uint32_t buffLen)
{ {
LE_CHECK(loopHandle != NULL && taskHandle != NULL, return LE_INVALID_PARAM, "Invalid parameters"); LE_CHECK(loopHandle != NULL && taskHandle != NULL, return LE_INVALID_PARAM, "Invalid parameters");
BufferHandle handle = NULL; BufferHandle handle = LE_CreateBuffer(loopHandle, buffLen + 1 + sizeof(eventId));
handle = LE_CreateBuffer(loopHandle, buffLen + 1 + sizeof(eventId));
char *buff = (char *)LE_GetBufferInfo(handle, NULL, NULL); char *buff = (char *)LE_GetBufferInfo(handle, NULL, NULL);
int ret = memcpy_s(buff, sizeof(eventId), &eventId, sizeof(eventId)); int ret = memcpy_s(buff, sizeof(eventId), &eventId, sizeof(eventId));
LE_CHECK(ret == 0, return -1, "Failed to copy data"); LE_CHECK(ret == 0, return -1, "Failed to copy data");
......
...@@ -27,9 +27,9 @@ ...@@ -27,9 +27,9 @@
static LE_STATUS SetTimer_(int tfd, uint64_t timeout) static LE_STATUS SetTimer_(int tfd, uint64_t timeout)
{ {
struct itimerspec timeValue; struct itimerspec timeValue;
time_t sec = timeout / 1000; time_t sec = timeout / TIMEOUT_BASE;
timeValue.it_interval.tv_sec = sec; timeValue.it_interval.tv_sec = sec;
long nsec = (timeout % 1000) * 1000; long nsec = (timeout % TIMEOUT_BASE) * TIMEOUT_BASE;
timeValue.it_interval.tv_nsec = nsec; timeValue.it_interval.tv_nsec = nsec;
timeValue.it_value.tv_sec = sec; timeValue.it_value.tv_sec = sec;
timeValue.it_value.tv_nsec = nsec; timeValue.it_value.tv_nsec = nsec;
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include "le_task.h" #include "le_task.h"
#include "loop_event.h" #include "loop_event.h"
#define TIMEOUT_BASE 1000
typedef struct { typedef struct {
BaseTask base; BaseTask base;
LE_ProcessTimer processTimer; LE_ProcessTimer processTimer;
......
...@@ -410,8 +410,7 @@ static int CheckParamMatch_(const TriggerWorkSpace *workSpace, ...@@ -410,8 +410,7 @@ static int CheckParamMatch_(const TriggerWorkSpace *workSpace,
PARAM_CHECK((type == TRIGGER_PARAM) || (type == TRIGGER_PARAM_WAIT), return -1, "Invaid type"); PARAM_CHECK((type == TRIGGER_PARAM) || (type == TRIGGER_PARAM_WAIT), return -1, "Invaid type");
CalculatorInit(calculator, MAX_CONDITION_NUMBER, sizeof(LogicData), 1); CalculatorInit(calculator, MAX_CONDITION_NUMBER, sizeof(LogicData), 1);
int ret = GetValueFromContent(content, contentSize, int ret = GetValueFromContent(content, contentSize, 0, calculator->inputName, SUPPORT_DATA_BUFFER_MAX);
0, calculator->inputName, SUPPORT_DATA_BUFFER_MAX);
PARAM_CHECK(ret == 0, return -1, "Failed parse content name"); PARAM_CHECK(ret == 0, return -1, "Failed parse content name");
ret = GetValueFromContent(content, contentSize, ret = GetValueFromContent(content, contentSize,
strlen(calculator->inputName) + 1, calculator->inputContent, SUPPORT_DATA_BUFFER_MAX); strlen(calculator->inputName) + 1, calculator->inputContent, SUPPORT_DATA_BUFFER_MAX);
...@@ -727,7 +726,7 @@ int CheckWatchTriggerTimeout(void) ...@@ -727,7 +726,7 @@ int CheckWatchTriggerTimeout(void)
TriggerHeader *GetTriggerHeader(const TriggerWorkSpace *workSpace, int type) TriggerHeader *GetTriggerHeader(const TriggerWorkSpace *workSpace, int type)
{ {
if (workSpace== NULL || type >= TRIGGER_MAX) { if (workSpace == NULL || type >= TRIGGER_MAX) {
return NULL; return NULL;
} }
return (TriggerHeader *)&workSpace->triggerHead[type]; return (TriggerHeader *)&workSpace->triggerHead[type];
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <time.h> #include <time.h>
#include "plugin_test.h" #include "plugin_test.h"
#include "init_param.h"
#include "init_plugin.h" #include "init_plugin.h"
#define MAX_COUNT 1000 #define MAX_COUNT 1000
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册