mirror of
https://gitee.com/openharmony/startup_init
synced 2024-11-23 16:20:00 +00:00
commit
4072dde35b
@ -379,7 +379,7 @@ int MountOneItem(FstabItem *item)
|
||||
mountFlags = GetMountFlags(item->mountOptions, fsSpecificData, sizeof(fsSpecificData),
|
||||
item->mountPoint);
|
||||
if (!IsSupportedFilesystem(item->fsType)) {
|
||||
BEGET_LOGE("Unsupported file system \" %s \"", item->fsType);
|
||||
BEGET_LOGW("Unsupported file system \" %s \"", item->fsType);
|
||||
return 0;
|
||||
}
|
||||
if (FM_MANAGER_WAIT_ENABLED(item->fsManagerFlags)) {
|
||||
|
@ -599,7 +599,7 @@ static void RunChildProcess(Service *service, ServiceArgs *pathArgs)
|
||||
int ServiceStart(Service *service, ServiceArgs *pathArgs)
|
||||
{
|
||||
INIT_ERROR_CHECK(service != NULL, return SERVICE_FAILURE, "start service failed! null ptr.");
|
||||
INIT_ERROR_CHECK(service->pid <= 0, return SERVICE_SUCCESS, "Service info %s already started", service->name);
|
||||
INIT_INFO_CHECK(service->pid <= 0, return SERVICE_SUCCESS, "Service info %s already started", service->name);
|
||||
INIT_ERROR_CHECK(pathArgs != NULL && pathArgs->count > 0,
|
||||
return SERVICE_FAILURE, "start service %s pathArgs is NULL.", service->name);
|
||||
|
||||
|
@ -55,11 +55,14 @@ static void MountBasicFs(void)
|
||||
if (mount("tmpfs", "/storage", "tmpfs", MS_NOEXEC | MS_NODEV| MS_NOSUID, "mode=0755") != 0) {
|
||||
INIT_LOGE("Mount storage failed. %s", strerror(errno));
|
||||
}
|
||||
if (mkdir("/dev/pts", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) {
|
||||
INIT_LOGE("mkdir /dev/pts failed. %s", strerror(errno));
|
||||
}
|
||||
if (mount("devpts", "/dev/pts", "devpts", 0, NULL) != 0) {
|
||||
INIT_LOGE("Mount devpts failed. %s", strerror(errno));
|
||||
struct stat st;
|
||||
if (!(stat("/dev/pts", &st) == 0 && S_ISDIR(st.st_mode))) {
|
||||
if (mkdir("/dev/pts", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) {
|
||||
INIT_LOGE("mkdir /dev/pts failed. %s", strerror(errno));
|
||||
}
|
||||
if (mount("devpts", "/dev/pts", "devpts", 0, NULL) != 0) {
|
||||
INIT_LOGE("Mount devpts failed. %s", strerror(errno));
|
||||
}
|
||||
}
|
||||
if (mount("proc", "/proc", "proc", 0, "gid=3009,hidepid=2") != 0) {
|
||||
INIT_LOGE("Mount procfs failed. %s", strerror(errno));
|
||||
@ -74,15 +77,22 @@ static void MountBasicFs(void)
|
||||
|
||||
static void CreateDeviceNode(void)
|
||||
{
|
||||
if (mknod("/dev/null", S_IFCHR | DEFAULT_RW_MODE, makedev(MEM_MAJOR, DEV_NULL_MINOR)) != 0) {
|
||||
INIT_LOGE("Create /dev/null device node failed. %s", strerror(errno));
|
||||
}
|
||||
if (mknod("/dev/random", S_IFCHR | DEFAULT_RW_MODE, makedev(MEM_MAJOR, DEV_RANDOM_MINOR)) != 0) {
|
||||
INIT_LOGE("Create /dev/random device node failed. %s", strerror(errno));
|
||||
if (access("/dev/null", F_OK) != 0) {
|
||||
if (mknod("/dev/null", S_IFCHR | DEFAULT_RW_MODE, makedev(MEM_MAJOR, DEV_NULL_MINOR)) != 0) {
|
||||
INIT_LOGE("Create /dev/null device node failed. %s", strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
if (mknod("/dev/urandom", S_IFCHR | DEFAULT_RW_MODE, makedev(MEM_MAJOR, DEV_URANDOM_MINOR)) != 0) {
|
||||
INIT_LOGE("Create /dev/urandom device node failed. %s", strerror(errno));
|
||||
if (access("/dev/random", F_OK) != 0) {
|
||||
if (mknod("/dev/random", S_IFCHR | DEFAULT_RW_MODE, makedev(MEM_MAJOR, DEV_RANDOM_MINOR)) != 0) {
|
||||
INIT_LOGE("Create /dev/random device node failed. %s", strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
if (access("/dev/urandom", F_OK) != 0) {
|
||||
if (mknod("/dev/urandom", S_IFCHR | DEFAULT_RW_MODE, makedev(MEM_MAJOR, DEV_URANDOM_MINOR)) != 0) {
|
||||
INIT_LOGW("Create /dev/urandom device node failed. %s", strerror(errno));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,9 +43,9 @@ static pid_t HandleSigChild(const struct signalfd_siginfo *siginfo)
|
||||
|
||||
// check child process exit status
|
||||
if (WIFSIGNALED(procStat)) {
|
||||
INIT_LOGE("Child process %s(pid %d) exit with signal : %d", serviceName, sigPID, WTERMSIG(procStat));
|
||||
INIT_LOGW("Child process %s(pid %d) exit with signal : %d", serviceName, sigPID, WTERMSIG(procStat));
|
||||
} else if (WIFEXITED(procStat)) {
|
||||
INIT_LOGE("Child process %s(pid %d) exit with code : %d", serviceName, sigPID, WEXITSTATUS(procStat));
|
||||
INIT_LOGW("Child process %s(pid %d) exit with code : %d", serviceName, sigPID, WEXITSTATUS(procStat));
|
||||
if (service != NULL) {
|
||||
service->lastErrno = WEXITSTATUS(procStat);
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ static int LoadOnePersistParam_(const uint32_t *context, const char *name, const
|
||||
static void LoadPersistParam_(const char *fileName, char *buffer, uint32_t buffSize)
|
||||
{
|
||||
FILE *fp = fopen(fileName, "r");
|
||||
PARAM_CHECK(fp != NULL, return, "No valid persist parameter file %s", fileName);
|
||||
PARAM_WARNING_CHECK(fp != NULL, return, "No valid persist parameter file %s", fileName);
|
||||
|
||||
uint32_t paramNum = 0;
|
||||
while (fgets(buffer, buffSize, fp) != NULL) {
|
||||
|
@ -76,7 +76,6 @@ typedef enum {
|
||||
#define DATA_PATH STARTUP_INIT_UT_PATH"/data/service/el1/startup/parameters/"
|
||||
#endif
|
||||
#define PARAM_AREA_SIZE_CFG STARTUP_INIT_UT_PATH"/etc/param/ohos.para.size"
|
||||
|
||||
#define CLIENT_PIPE_NAME "/dev/unix/socket/paramservice"
|
||||
#define PIPE_NAME STARTUP_INIT_UT_PATH "/dev/unix/socket/paramservice"
|
||||
#define PARAM_STORAGE_PATH STARTUP_INIT_UT_PATH "/dev/__parameters__"
|
||||
@ -121,6 +120,18 @@ INIT_LOCAL_API void ParamWorBaseLog(InitLogLevel logLevel, uint32_t domain, cons
|
||||
exper; \
|
||||
}
|
||||
|
||||
#define PARAM_INFO_CHECK(retCode, exper, ...) \
|
||||
if (!(retCode)) { \
|
||||
PARAM_LOGI(__VA_ARGS__); \
|
||||
exper; \
|
||||
}
|
||||
|
||||
#define PARAM_WARNING_CHECK(retCode, exper, ...) \
|
||||
if (!(retCode)) { \
|
||||
PARAM_LOGW(__VA_ARGS__); \
|
||||
exper; \
|
||||
}
|
||||
|
||||
#define PARAM_ONLY_CHECK(retCode, exper) \
|
||||
if (!(retCode)) { \
|
||||
exper; \
|
||||
|
@ -53,6 +53,7 @@ typedef struct CmdLineInfoContainer {
|
||||
typedef struct CmdLineIteratorCtx {
|
||||
char *cmdline;
|
||||
bool gotSn;
|
||||
bool *matches;
|
||||
} CmdLineIteratorCtx;
|
||||
|
||||
static int CommonDealFun(const char *name, const char *value)
|
||||
@ -160,31 +161,42 @@ static int MatchReserverCmdline(const NAME_VALUE_PAIR* nv, CmdLineIteratorCtx *c
|
||||
if (ret <= 0) {
|
||||
continue;
|
||||
}
|
||||
if (ctx->matches[i]) {
|
||||
return PARAM_CODE_SUCCESS;
|
||||
}
|
||||
bool isSnSet = ((container->cmdLineInfo + i)->processor == SnDealFun);
|
||||
if (isSnSet && ctx->gotSn) {
|
||||
return PARAM_CODE_SUCCESS;
|
||||
}
|
||||
PARAM_LOGV("proc cmdline %s matched.", fullName);
|
||||
ret = (container->cmdLineInfo + i)->processor(fullName, nv->value);
|
||||
if ((ret == 0) && (SnDealFun == (container->cmdLineInfo + i)->processor)) {
|
||||
ctx->gotSn = true;
|
||||
if (ret == 0) {
|
||||
ctx->matches[i] = true;
|
||||
if (isSnSet) {
|
||||
ctx->gotSn = true;
|
||||
}
|
||||
}
|
||||
return PARAM_CODE_SUCCESS;
|
||||
}
|
||||
return PARAM_CODE_NOT_FOUND;
|
||||
}
|
||||
|
||||
static const CmdLineInfo CMDLINES[] = {
|
||||
{ "hardware", CommonDealFun },
|
||||
{ "bootgroup", CommonDealFun },
|
||||
{ "reboot_reason", CommonDealFun },
|
||||
{ "bootslots", CommonDealFun },
|
||||
{ "sn", SnDealFun },
|
||||
{ "root_package", CommonDealFun },
|
||||
{ "serialno", SnDealFun },
|
||||
{ "udid", Common2ConstDealFun },
|
||||
{ "productid", Common2ConstDealFun }
|
||||
};
|
||||
|
||||
static void CmdlineIterator(const NAME_VALUE_PAIR *nv, void *context)
|
||||
{
|
||||
CmdLineIteratorCtx *ctx = (CmdLineIteratorCtx *)context;
|
||||
char *data = (char *)ctx->cmdline;
|
||||
static const CmdLineInfo CMDLINES[] = {
|
||||
{ "hardware", CommonDealFun },
|
||||
{ "bootgroup", CommonDealFun },
|
||||
{ "reboot_reason", CommonDealFun },
|
||||
{ "bootslots", CommonDealFun },
|
||||
{ "sn", SnDealFun },
|
||||
{ "root_package", CommonDealFun },
|
||||
{ "serialno", SnDealFun },
|
||||
{ "udid", Common2ConstDealFun },
|
||||
{ "productid", Common2ConstDealFun }
|
||||
};
|
||||
|
||||
data[nv->nameEnd - data] = '\0';
|
||||
data[nv->valueEnd - data] = '\0';
|
||||
@ -208,7 +220,7 @@ static void CmdlineIterator(const NAME_VALUE_PAIR *nv, void *context)
|
||||
}
|
||||
|
||||
// cmdline with prefix but not matched, add to param by default
|
||||
PARAM_LOGE("add proc cmdline param %s by default.", nv->name);
|
||||
PARAM_LOGI("add proc cmdline param %s by default.", nv->name);
|
||||
CommonDealFun(nv->name, nv->value);
|
||||
}
|
||||
|
||||
@ -234,7 +246,8 @@ INIT_LOCAL_API int LoadParamFromCmdLine(void)
|
||||
ctx.gotSn = false;
|
||||
ctx.cmdline = ReadFileData(BOOT_CMD_LINE);
|
||||
PARAM_CHECK(ctx.cmdline != NULL, return -1, "Failed to read file %s", BOOT_CMD_LINE);
|
||||
|
||||
bool matches[ARRAY_LENGTH(CMDLINES)] = {false};
|
||||
ctx.matches = matches;
|
||||
IterateNameValuePairs(ctx.cmdline, CmdlineIterator, (void *)(&ctx));
|
||||
|
||||
// sn is critical, it must be specified
|
||||
@ -377,7 +390,7 @@ static int LoadDefaultParam_(const char *fileName, uint32_t mode,
|
||||
realpath(fileName, realPath);
|
||||
FILE *fp = fopen(realPath, "r");
|
||||
if (fp == NULL) {
|
||||
PARAM_LOGE("Failed to open file '%s' error:%d ", fileName, errno);
|
||||
PARAM_LOGW("Failed to open file '%s' error:%d ", fileName, errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -422,14 +435,16 @@ int LoadDefaultParams(const char *fileName, uint32_t mode)
|
||||
PARAM_LOGI("Load default parameters from %s.", fileName);
|
||||
struct stat st;
|
||||
if ((stat(fileName, &st) == 0) && !S_ISDIR(st.st_mode)) {
|
||||
(void)ProcessParamFile(fileName, &mode);
|
||||
if (strstr(fileName, ".para.dac")) {
|
||||
return LoadSecurityLabel(fileName);
|
||||
} else {
|
||||
return ProcessParamFile(fileName, &mode);
|
||||
}
|
||||
} else {
|
||||
(void)ReadFileInDir(fileName, ".para", ProcessParamFile, &mode);
|
||||
(void)ReadFileInDir(fileName, ".para.import", LoadParamFromImport, &mode);
|
||||
return LoadSecurityLabel(fileName);
|
||||
}
|
||||
|
||||
// load security label
|
||||
return LoadSecurityLabel(fileName);
|
||||
}
|
||||
|
||||
INIT_LOCAL_API void LoadParamFromBuild(void)
|
||||
|
Loading…
Reference in New Issue
Block a user