提交 993580a8 编写于 作者: O openharmony_ci 提交者: Gitee

!69 修改l2init

Merge pull request !69 from 熊磊/init0727
...@@ -71,6 +71,7 @@ typedef struct { ...@@ -71,6 +71,7 @@ typedef struct {
time_t firstCriticalCrashTime; // record for critical time_t firstCriticalCrashTime; // record for critical
char *writepidFiles[MAX_WRITEPID_FILES]; char *writepidFiles[MAX_WRITEPID_FILES];
unsigned int attribute; unsigned int attribute;
int importance;
Perms servPerm; Perms servPerm;
struct OnRestartCmd *onRestart; struct OnRestartCmd *onRestart;
struct ServiceSocket *socketCfg; struct ServiceSocket *socketCfg;
......
...@@ -80,11 +80,21 @@ void SetLogLevel(InitLogLevel logLevel); ...@@ -80,11 +80,21 @@ void SetLogLevel(InitLogLevel logLevel);
statement; \ statement; \
} }
#define INIT_CHECK_ONLY_RETURN(ret, statement) \ #define INIT_CHECK(ret, statement) \
if (!(ret)) { \ if (!(ret)) { \
statement; \ statement; \
} }
#define INIT_CHECK_RETURN_VALUE(ret, result) \
if (!(ret)) { \
return result; \
}
#define INIT_CHECK_ONLY_RETURN(ret) \
if (!(ret)) { \
return; \
}
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
} }
......
...@@ -24,8 +24,8 @@ ...@@ -24,8 +24,8 @@
#include <unistd.h> #include <unistd.h>
#include "init_log.h" #include "init_log.h"
#define DEFAULT_RW_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IRGRP | S_IROTH | S_IWOTH #define DEFAULT_RW_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
#define DEFAULT_NO_AUTHORITY_MODE S_IWUSR | S_IRUSR #define DEFAULT_NO_AUTHORITY_MODE (S_IWUSR | S_IRUSR)
void MountBasicFs() void MountBasicFs()
{ {
......
此差异已折叠。
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
#include <stropts.h> #include <stropts.h>
#endif #endif
#include <sys/param.h> #include <sys/param.h>
#ifndef OHOS_LITE
#include <sys/resource.h>
#endif
#include <sys/stat.h> #include <sys/stat.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
...@@ -223,10 +226,16 @@ int ServiceStart(Service *service) ...@@ -223,10 +226,16 @@ int ServiceStart(Service *service)
INIT_LOGI("service->name is %s ", service->name); INIT_LOGI("service->name is %s ", service->name);
#ifndef OHOS_LITE #ifndef OHOS_LITE
// L2 Can not be reset env if (service->importance != 0) {
if (execv(service->pathArgs[0], service->pathArgs) != 0) { if (setpriority(PRIO_PROCESS, 0, service->importance) != 0) {
INIT_LOGE("setpriority failed for %s, importance = %d", service->name, service->importance);
_exit(0x7f); // 0x7f: user specified
}
}
// L2 Can not be reset env
if (execv(service->pathArgs[0], service->pathArgs) != 0) {
INIT_LOGE("service %s execve failed! err %d.", service->name, errno); INIT_LOGE("service %s execve failed! err %d.", service->name, errno);
} }
#else #else
char* env[] = {"LD_LIBRARY_PATH=/storage/app/libs", NULL}; char* env[] = {"LD_LIBRARY_PATH=/storage/app/libs", NULL};
if (execve(service->pathArgs[0], service->pathArgs, env) != 0) { if (execve(service->pathArgs[0], service->pathArgs, env) != 0) {
......
...@@ -34,6 +34,9 @@ ...@@ -34,6 +34,9 @@
#include "init_utils.h" #include "init_utils.h"
#include "securec.h" #include "securec.h"
#define MIN_IMPORTANT_LEVEL (-20)
#define MAX_IMPORTANT_LEVEL 19
// All serivce processes that init will fork+exec. // All serivce processes that init will fork+exec.
static Service* g_services = NULL; static Service* g_services = NULL;
static int g_servicesCnt = 0; static int g_servicesCnt = 0;
...@@ -362,6 +365,23 @@ static int GetServicePathAndArgs(const cJSON* curArrItem, Service* curServ) ...@@ -362,6 +365,23 @@ static int GetServicePathAndArgs(const cJSON* curArrItem, Service* curServ)
return SERVICE_SUCCESS; return SERVICE_SUCCESS;
} }
static int GetImportantValue(int value, Service *curServ)
{
#ifdef OHOS_LITE
if (value != 0) {
curServ->attribute |= SERVICE_ATTR_IMPORTANT;
}
#else
if (value >= MIN_IMPORTANT_LEVEL && value <= MAX_IMPORTANT_LEVEL) { // -20~19
curServ->importance = value;
} else {
INIT_LOGE("importance level = %d, is not between -20 and 19, error", value);
return SERVICE_FAILURE;
}
#endif
return SERVICE_SUCCESS;
}
static int GetServiceNumber(const cJSON* curArrItem, Service* curServ, const char* targetField) static int GetServiceNumber(const cJSON* curArrItem, Service* curServ, const char* targetField)
{ {
cJSON* filedJ = cJSON_GetObjectItem(curArrItem, targetField); cJSON* filedJ = cJSON_GetObjectItem(curArrItem, targetField);
...@@ -374,15 +394,15 @@ static int GetServiceNumber(const cJSON* curArrItem, Service* curServ, const cha ...@@ -374,15 +394,15 @@ static int GetServiceNumber(const cJSON* curArrItem, Service* curServ, const cha
} }
if (!cJSON_IsNumber(filedJ)) { if (!cJSON_IsNumber(filedJ)) {
INIT_LOGE("GetServiceNumber, %s is null or is not a number, error.", targetField); INIT_LOGE("%s is null or is not a number, error.service name is %s", targetField, curServ->name);
return SERVICE_FAILURE; return SERVICE_FAILURE;
} }
int value = (int)cJSON_GetNumberValue(filedJ); int value = (int)cJSON_GetNumberValue(filedJ);
// important value allow < 0 // importance value allow < 0
if (strncmp(targetField, IMPORTANT_STR_IN_CFG, strlen(IMPORTANT_STR_IN_CFG)) != 0) { if (strncmp(targetField, IMPORTANT_STR_IN_CFG, strlen(IMPORTANT_STR_IN_CFG)) != 0) {
if (value < 0) { if (value < 0) {
INIT_LOGE("GetServiceNumber, value = %d, error.", value); INIT_LOGE("value = %d, error.service name is %s", value, curServ->name);
return SERVICE_FAILURE; return SERVICE_FAILURE;
} }
} }
...@@ -392,9 +412,7 @@ static int GetServiceNumber(const cJSON* curArrItem, Service* curServ, const cha ...@@ -392,9 +412,7 @@ static int GetServiceNumber(const cJSON* curArrItem, Service* curServ, const cha
curServ->attribute |= SERVICE_ATTR_ONCE; curServ->attribute |= SERVICE_ATTR_ONCE;
} }
} else if (strncmp(targetField, IMPORTANT_STR_IN_CFG, strlen(IMPORTANT_STR_IN_CFG)) == 0) { } else if (strncmp(targetField, IMPORTANT_STR_IN_CFG, strlen(IMPORTANT_STR_IN_CFG)) == 0) {
if (value != 0) { INIT_CHECK_RETURN_VALUE(GetImportantValue(value, curServ) == SERVICE_SUCCESS, SERVICE_FAILURE);
curServ->attribute |= SERVICE_ATTR_IMPORTANT;
}
} else if (strncmp(targetField, CRITICAL_STR_IN_CFG, strlen(CRITICAL_STR_IN_CFG)) == 0) { // set critical } else if (strncmp(targetField, CRITICAL_STR_IN_CFG, strlen(CRITICAL_STR_IN_CFG)) == 0) { // set critical
curServ->attribute &= ~SERVICE_ATTR_CRITICAL; curServ->attribute &= ~SERVICE_ATTR_CRITICAL;
if (value == 1) { if (value == 1) {
...@@ -411,7 +429,7 @@ static int GetServiceNumber(const cJSON* curArrItem, Service* curServ, const cha ...@@ -411,7 +429,7 @@ static int GetServiceNumber(const cJSON* curArrItem, Service* curServ, const cha
curServ->attribute |= SERVICE_ATTR_CONSOLE; curServ->attribute |= SERVICE_ATTR_CONSOLE;
} }
} else { } else {
INIT_LOGE("GetServiceNumber, item = %s, not expected, error.", targetField); INIT_LOGE("item = %s, not expected, error.service name is %s", targetField, curServ->name);
return SERVICE_FAILURE; return SERVICE_FAILURE;
} }
return SERVICE_SUCCESS; return SERVICE_SUCCESS;
...@@ -644,7 +662,6 @@ void ParseAllServices(const cJSON* fileRoot) ...@@ -644,7 +662,6 @@ void ParseAllServices(const cJSON* fileRoot)
return; return;
} }
INIT_LOGI("servArrSize is %d ", servArrSize);
if (servArrSize > MAX_SERVICES_CNT_IN_FILE) { if (servArrSize > MAX_SERVICES_CNT_IN_FILE) {
INIT_LOGE("ParseAllServices, too many services[cnt %d] detected, should not exceed %d.", INIT_LOGE("ParseAllServices, too many services[cnt %d] detected, should not exceed %d.",
servArrSize, MAX_SERVICES_CNT_IN_FILE); servArrSize, MAX_SERVICES_CNT_IN_FILE);
......
...@@ -363,10 +363,10 @@ struct DevPermissionMapper { ...@@ -363,10 +363,10 @@ struct DevPermissionMapper {
struct DevPermissionMapper DEV_MAPPER[] = { struct DevPermissionMapper DEV_MAPPER[] = {
{"/dev/binder", 0666, 0, 0}, {"/dev/binder", 0666, 0, 0},
{"/dev/input/event0", 0660, 0, 1004}, {"/dev/input/event0", 0660, 0, 0},
{"/dev/input/event1", 0660, 0, 1004}, {"/dev/input/event1", 0660, 0, 1004},
{"/dev/input/mice", 0660, 0, 1004}, {"/dev/input/mice", 0660, 0, 1004},
{"/dev/input/mouse0", 0660, 0, 1004}, {"/dev/input/mouse0", 0660, 0, 0},
{"/dev/snd/timer", 0660, 1000, 1005}, {"/dev/snd/timer", 0660, 1000, 1005},
{"/dev/zero", 0666, 0, 0}, {"/dev/zero", 0666, 0, 0},
{"/dev/full", 0666, 0, 0}, {"/dev/full", 0666, 0, 0},
...@@ -375,7 +375,7 @@ struct DevPermissionMapper DEV_MAPPER[] = { ...@@ -375,7 +375,7 @@ struct DevPermissionMapper DEV_MAPPER[] = {
{"/dev/random", 0666, 0, 0}, {"/dev/random", 0666, 0, 0},
{"/dev/urandom", 0666, 0, 0}, {"/dev/urandom", 0666, 0, 0},
{"/dev/ashmem", 0666, 0, 0}, {"/dev/ashmem", 0666, 0, 0},
{"/dev/pmsg0", 0222, 0, 0}, {"/dev/pmsg0", 0222, 0, 1007},
{"/dev/jpeg", 0666, 1000, 1003}, {"/dev/jpeg", 0666, 1000, 1003},
{"/dev/vinput", 0660, 1000, 1004}, {"/dev/vinput", 0660, 1000, 1004},
{"/dev/mmz_userdev", 0644, 1000, 1005}, {"/dev/mmz_userdev", 0644, 1000, 1005},
...@@ -383,7 +383,7 @@ struct DevPermissionMapper DEV_MAPPER[] = { ...@@ -383,7 +383,7 @@ struct DevPermissionMapper DEV_MAPPER[] = {
{"/dev/mem", 0660, 1000, 1005}, {"/dev/mem", 0660, 1000, 1005},
{"/dev/ion", 0666, 1000, 1000}, {"/dev/ion", 0666, 1000, 1000},
{"/dev/btusb0", 0660, 1002, 1002}, {"/dev/btusb0", 0660, 1002, 1002},
{"/dev/uhid", 0660, 1002, 1002}, {"/dev/uhid", 0660, 3011, 3011},
{"/dev/tc_ns_client", 0660, 1000, 1005}, {"/dev/tc_ns_client", 0660, 1000, 1005},
{"/dev/rtk_btusb", 0660, 1002, 0}, {"/dev/rtk_btusb", 0660, 1002, 0},
{"/dev/sil9293", 0660, 1000, 1005}, {"/dev/sil9293", 0660, 1000, 1005},
...@@ -418,7 +418,10 @@ struct DevPermissionMapper DEV_MAPPER[] = { ...@@ -418,7 +418,10 @@ struct DevPermissionMapper DEV_MAPPER[] = {
{"/dev/dri/card0", 0666, 0, 1003}, {"/dev/dri/card0", 0666, 0, 1003},
{"/dev/dri/card0-DSI-1", 0666, 0, 1003}, {"/dev/dri/card0-DSI-1", 0666, 0, 1003},
{"/dev/dri/card0-HDMI-A-1", 0666, 0, 1003}, {"/dev/dri/card0-HDMI-A-1", 0666, 0, 1003},
{"/dev/dri/renderD128", 0666, 0, 1003} {"/dev/dri/renderD128", 0666, 0, 1003},
{"/dev/rtc0", 0640, 1000, 1000},
{"/dev/tty0", 0660, 0, 1000},
{"/dev/uinput", 0660, 3011, 3011}
}; };
static void AdjustDevicePermission(const char *devPath) static void AdjustDevicePermission(const char *devPath)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册