提交 6e579a6b 编写于 作者: Z zhong_ning

fix bug

Signed-off-by: Nzhong_ning <zhong_ning@hoperun.com>
上级 c0f5a512
...@@ -5,7 +5,10 @@ ...@@ -5,7 +5,10 @@
"/init.${ro.hardware}.cfg", "/init.${ro.hardware}.cfg",
"/init.Hi3516DV300.cfg", "/init.Hi3516DV300.cfg",
"/init.usb.configfs.cfg", "/init.usb.configfs.cfg",
"/init.${ro.zygote}.cfg" "/init.${ro.zygote}.cfg",
"/init.Hi3516DV300.usb.cfg",
"/init.usb.configfs.cfg",
"/init.usb.cfg"
], ],
"jobs" : [{ "jobs" : [{
"name" : "pre-init", "name" : "pre-init",
...@@ -20,7 +23,7 @@ ...@@ -20,7 +23,7 @@
"mkdir /vendor", "mkdir /vendor",
"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=o rdered,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"
] ]
}, { }, {
"name" : "init", "name" : "init",
......
...@@ -37,7 +37,7 @@ int DecodeUid(const char *name); ...@@ -37,7 +37,7 @@ int DecodeUid(const char *name);
void CheckAndCreateDir(const char *fileName); void CheckAndCreateDir(const char *fileName);
char* ReadFileToBuf(const char *configFile); char* ReadFileToBuf(const char *configFile);
int SplitString(char *srcPtr, char **dstPtr, int maxNum); int SplitString(char *srcPtr, char **dstPtr, int maxNum);
void WaitForFile(const char *source, int maxCount); void WaitForFile(const char *source, unsigned int maxCount);
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
......
...@@ -42,7 +42,7 @@ void InitLog(const char *tag, InitLogLevel logLevel, const char *fileName, int l ...@@ -42,7 +42,7 @@ void InitLog(const char *tag, InitLogLevel logLevel, const char *fileName, int l
if (logLevel < g_logLevel) { if (logLevel < g_logLevel) {
return; return;
} }
// ????stdout?????????? // 可以替换stdout这个为对应的文件句柄
time_t logTime; time_t logTime;
time(&logTime); time(&logTime);
struct tm *t = gmtime(&logTime); struct tm *t = gmtime(&logTime);
......
...@@ -85,7 +85,7 @@ static int GetServiceStringCaps(const cJSON* filedJ, Service* curServ) ...@@ -85,7 +85,7 @@ static int GetServiceStringCaps(const cJSON* filedJ, Service* curServ)
for (; i < curServ->servPerm.capsCnt; ++i) { for (; i < curServ->servPerm.capsCnt; ++i) {
if (cJSON_GetArrayItem(filedJ, i) == NULL || !cJSON_GetStringValue(cJSON_GetArrayItem(filedJ, i)) if (cJSON_GetArrayItem(filedJ, i) == NULL || !cJSON_GetStringValue(cJSON_GetArrayItem(filedJ, i))
|| strlen(cJSON_GetStringValue(cJSON_GetArrayItem(filedJ, i))) <= 0) { // check all errors || strlen(cJSON_GetStringValue(cJSON_GetArrayItem(filedJ, i))) <= 0) { // check all errors
INIT_LOGE("[init] service=%s, parse item[%d] as string, error.\n", curServ->name, i); INIT_LOGE("service=%s, parse item[%d] as string, error.\n", curServ->name, i);
break; break;
} }
char* fieldStr = cJSON_GetStringValue(cJSON_GetArrayItem(filedJ, i)); char* fieldStr = cJSON_GetStringValue(cJSON_GetArrayItem(filedJ, i));
...@@ -99,12 +99,12 @@ static int GetServiceStringCaps(const cJSON* filedJ, Service* curServ) ...@@ -99,12 +99,12 @@ static int GetServiceStringCaps(const cJSON* filedJ, Service* curServ)
if (j < mapSize) { if (j < mapSize) {
curServ->servPerm.caps[i] = g_capStrCapNum[j].CapNum; curServ->servPerm.caps[i] = g_capStrCapNum[j].CapNum;
} else { } else {
INIT_LOGE("[init] service=%s, CapbilityName=%s, error.\n", curServ->name, fieldStr); INIT_LOGE("service=%s, CapbilityName=%s, error.\n", curServ->name, fieldStr);
break; break;
} }
if (curServ->servPerm.caps[i] > CAP_LAST_CAP && curServ->servPerm.caps[i] != FULL_CAP) { if (curServ->servPerm.caps[i] > CAP_LAST_CAP && curServ->servPerm.caps[i] != FULL_CAP) {
// resources will be released by function: ReleaseServiceMem // resources will be released by function: ReleaseServiceMem
INIT_LOGE("[init] service=%s, cap = %d, error.\n", curServ->name, curServ->servPerm.caps[i]); INIT_LOGE("service=%s, cap = %d, error.\n", curServ->name, curServ->servPerm.caps[i]);
return SERVICE_FAILURE; return SERVICE_FAILURE;
} }
} }
...@@ -121,7 +121,7 @@ int GetServiceCaps(const cJSON* curArrItem, Service* curServ) ...@@ -121,7 +121,7 @@ int GetServiceCaps(const cJSON* curArrItem, Service* curServ)
return SERVICE_SUCCESS; return SERVICE_SUCCESS;
} }
if (!cJSON_IsArray(filedJ)) { if (!cJSON_IsArray(filedJ)) {
INIT_LOGE("[init] service=%s, caps is not a list, error.\n", curServ->name); INIT_LOGE("service=%s, caps is not a list, error.\n", curServ->name);
return SERVICE_FAILURE; return SERVICE_FAILURE;
} }
// caps array does not exist, means do not need any capability // caps array does not exist, means do not need any capability
...@@ -130,13 +130,13 @@ int GetServiceCaps(const cJSON* curArrItem, Service* curServ) ...@@ -130,13 +130,13 @@ int GetServiceCaps(const cJSON* curArrItem, Service* curServ)
return SERVICE_SUCCESS; return SERVICE_SUCCESS;
} }
if (capsCnt > MAX_CAPS_CNT_FOR_ONE_SERVICE) { if (capsCnt > MAX_CAPS_CNT_FOR_ONE_SERVICE) {
INIT_LOGE("[init], service=%s, too many caps[cnt %d] for one service, max is %d.\n", INIT_LOGE("service=%s, too many caps[cnt %d] for one service, max is %d.\n",
curServ->name, capsCnt, MAX_CAPS_CNT_FOR_ONE_SERVICE); curServ->name, capsCnt, MAX_CAPS_CNT_FOR_ONE_SERVICE);
return SERVICE_FAILURE; return SERVICE_FAILURE;
} }
curServ->servPerm.caps = (unsigned int*)malloc(sizeof(unsigned int) * capsCnt); curServ->servPerm.caps = (unsigned int*)malloc(sizeof(unsigned int) * capsCnt);
if (curServ->servPerm.caps == NULL) { if (curServ->servPerm.caps == NULL) {
INIT_LOGE("[init] GetServiceCaps, service=%s, malloc error.\n", curServ->name); INIT_LOGE("GetServiceCaps, service=%s, malloc error.\n", curServ->name);
return SERVICE_FAILURE; return SERVICE_FAILURE;
} }
curServ->servPerm.capsCnt = capsCnt; curServ->servPerm.capsCnt = capsCnt;
...@@ -145,13 +145,13 @@ int GetServiceCaps(const cJSON* curArrItem, Service* curServ) ...@@ -145,13 +145,13 @@ int GetServiceCaps(const cJSON* curArrItem, Service* curServ)
cJSON* capJ = cJSON_GetArrayItem(filedJ, i); cJSON* capJ = cJSON_GetArrayItem(filedJ, i);
if (!cJSON_IsNumber(capJ) || cJSON_GetNumberValue(capJ) < 0) { if (!cJSON_IsNumber(capJ) || cJSON_GetNumberValue(capJ) < 0) {
// resources will be released by function: ReleaseServiceMem // resources will be released by function: ReleaseServiceMem
INIT_LOGI("[init], service=%s, Capbility is not a number or < 0, error.\n", curServ->name); INIT_LOGI("service=%s, Capbility is not a number or < 0, error.\n", curServ->name);
break; break;
} }
curServ->servPerm.caps[i] = (unsigned int)cJSON_GetNumberValue(capJ); curServ->servPerm.caps[i] = (unsigned int)cJSON_GetNumberValue(capJ);
if (curServ->servPerm.caps[i] > CAP_LAST_CAP && curServ->servPerm.caps[i] != FULL_CAP) { // CAP_LAST_CAP = 37 if (curServ->servPerm.caps[i] > CAP_LAST_CAP && curServ->servPerm.caps[i] != FULL_CAP) { // CAP_LAST_CAP = 37
// resources will be released by function: ReleaseServiceMem // resources will be released by function: ReleaseServiceMem
INIT_LOGE("[init] service=%s, caps = %d, error.\n", curServ->name, curServ->servPerm.caps[i]); INIT_LOGE("service=%s, caps = %d, error.\n", curServ->name, curServ->servPerm.caps[i]);
return SERVICE_FAILURE; return SERVICE_FAILURE;
} }
} }
......
...@@ -80,7 +80,7 @@ static int GetMountStatusForMountPoint(const char *mountPoint) ...@@ -80,7 +80,7 @@ static int GetMountStatusForMountPoint(const char *mountPoint)
const char *mountFile = "/proc/mounts"; const char *mountFile = "/proc/mounts";
FILE *fp = fopen(mountFile, "r"); FILE *fp = fopen(mountFile, "r");
if (fp == NULL) { if (fp == NULL) {
INIT_LOGE("[init] DoReboot %s can't open.\n", mountPoint); INIT_LOGE("DoReboot %s can't open.\n", mountPoint);
return 1; return 1;
} }
...@@ -103,24 +103,32 @@ static int GetMountStatusForMountPoint(const char *mountPoint) ...@@ -103,24 +103,32 @@ static int GetMountStatusForMountPoint(const char *mountPoint)
void DoReboot(const char *value) void DoReboot(const char *value)
{ {
if (value == NULL) { if (value == NULL) {
INIT_LOGE("[init] DoReboot value = NULL\n"); INIT_LOGE("DoReboot value = NULL\n");
return; return;
} }
INIT_LOGI("[init] DoReboot value = %s\n", value); INIT_LOGI("DoReboot value = %s\n", value);
if (strlen(value) > MAX_VALUE_LENGTH) { if (strlen(value) > MAX_VALUE_LENGTH) {
INIT_LOGE("[init] DoReboot reboot value error, value = %s.\n", value); INIT_LOGE("DoReboot reboot value error, value = %s.\n", value);
return; return;
} }
const char *valueData = NULL; const char *valueData = NULL;
if (strncmp(value, "reboot,", strlen("reboot,")) != 0) { if (strncmp(value, "reboot,", strlen("reboot,")) != 0) {
INIT_LOGE("[init] DoReboot reboot value = %s, must started with reboot ,error.\n", value); INIT_LOGE("DoReboot reboot value = %s, must started with reboot ,error.\n", value);
return; return;
} else { } else {
valueData = value + strlen("reboot,"); valueData = value + strlen("reboot,");
} }
if (strncmp(valueData, "shutdown", strlen("shutdown")) != 0
&& strncmp(valueData, "updater:", strlen("updater:")) != 0
&& strncmp(valueData, "updater", strlen("updater")) != 0
&& strncmp(valueData, "NoArgument", strlen("NoArgument")) != 0) {
INIT_LOGE("DoReboot value = %s, parameters error.\n", value);
return;
}
StopAllServicesBeforeReboot();
if (GetMountStatusForMountPoint("/vendor")) { if (GetMountStatusForMountPoint("/vendor")) {
if (umount("/vendor") != 0) { if (umount("/vendor") != 0) {
INIT_LOGE("DoReboot umount vendor failed! errno = %d.\n", errno); INIT_LOGE("DoReboot umount vendor failed! errno = %d.\n", errno);
...@@ -131,7 +139,6 @@ void DoReboot(const char *value) ...@@ -131,7 +139,6 @@ void DoReboot(const char *value)
INIT_LOGE("DoReboot umount data failed! errno = %d.\n", errno); INIT_LOGE("DoReboot umount data failed! errno = %d.\n", errno);
} }
} }
StopAllServicesBeforeReboot();
// "shutdown" // "shutdown"
if (strncmp(valueData, "shutdown", strlen("shutdown")) == 0) { if (strncmp(valueData, "shutdown", strlen("shutdown")) == 0) {
int ret = reboot(RB_POWER_OFF); int ret = reboot(RB_POWER_OFF);
...@@ -145,7 +152,7 @@ void DoReboot(const char *value) ...@@ -145,7 +152,7 @@ void DoReboot(const char *value)
struct RBMiscUpdateMessage msg; struct RBMiscUpdateMessage msg;
bool ret = RBMiscReadUpdaterMessage(miscFile, &msg); bool ret = RBMiscReadUpdaterMessage(miscFile, &msg);
if(!ret) { if(!ret) {
INIT_LOGE("[init] DoReboot RBMiscReadUpdaterMessage error.\n"); INIT_LOGE("DoReboot RBMiscReadUpdaterMessage error.\n");
return; return;
} }
const int commandSize = 12; const int commandSize = 12;
...@@ -155,13 +162,13 @@ void DoReboot(const char *value) ...@@ -155,13 +162,13 @@ void DoReboot(const char *value)
if (strlen(valueData) > strlen("updater:") && strncmp(valueData, "updater:", strlen("updater:")) == 0) { if (strlen(valueData) > strlen("updater:") && strncmp(valueData, "updater:", strlen("updater:")) == 0) {
const char *p = valueData + strlen("updater:"); const char *p = valueData + strlen("updater:");
if (snprintf(msg.update, MAX_UPDATE_SIZE, "%s", p) > MAX_UPDATE_SIZE) { if (snprintf(msg.update, MAX_UPDATE_SIZE, "%s", p) > MAX_UPDATE_SIZE) {
INIT_LOGE("[init] DoReboot updater: RBMiscWriteUpdaterMessage error\n"); INIT_LOGE("DoReboot updater: RBMiscWriteUpdaterMessage error\n");
return; return;
} }
msg.update[MAX_UPDATE_SIZE - 1] = 0; msg.update[MAX_UPDATE_SIZE - 1] = 0;
ret = RBMiscWriteUpdaterMessage(miscFile, &msg); ret = RBMiscWriteUpdaterMessage(miscFile, &msg);
if(true != ret) { if(true != ret) {
INIT_LOGE("[init] DoReboot updater: RBMiscWriteUpdaterMessage error\n"); INIT_LOGE("DoReboot updater: RBMiscWriteUpdaterMessage error\n");
return; return;
} }
ret = reboot(RB_AUTOBOOT); ret = reboot(RB_AUTOBOOT);
...@@ -173,7 +180,7 @@ void DoReboot(const char *value) ...@@ -173,7 +180,7 @@ void DoReboot(const char *value)
if (strlen(valueData) == strlen("updater") && strncmp(valueData, "updater", strlen("updater")) == 0) { if (strlen(valueData) == strlen("updater") && strncmp(valueData, "updater", strlen("updater")) == 0) {
ret = RBMiscWriteUpdaterMessage(miscFile, &msg); ret = RBMiscWriteUpdaterMessage(miscFile, &msg);
if(true != ret) { if(true != ret) {
INIT_LOGE("[init] DoReboot updater RBMiscWriteUpdaterMessage error\n"); INIT_LOGE("DoReboot updater RBMiscWriteUpdaterMessage error\n");
return; return;
} }
ret = reboot(RB_AUTOBOOT); ret = reboot(RB_AUTOBOOT);
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "init_utils.h" #include "init_utils.h"
#include "securec.h" #include "securec.h"
#define WAIT_MAX_COUNT 10
#define MAX_BUF_SIZE 1024 #define MAX_BUF_SIZE 1024
#ifdef STARTUP_UT #ifdef STARTUP_UT
#define LOG_FILE_NAME "/media/sf_ubuntu/test/log.txt" #define LOG_FILE_NAME "/media/sf_ubuntu/test/log.txt"
...@@ -179,11 +180,15 @@ int SplitString(char *srcPtr, char **dstPtr, int maxNum) ...@@ -179,11 +180,15 @@ int SplitString(char *srcPtr, char **dstPtr, int maxNum)
return num; return num;
} }
void WaitForFile(const char *source, int maxCount) void WaitForFile(const char *source, unsigned int maxCount)
{ {
if (maxCount > WAIT_MAX_COUNT ) {
INIT_LOGE("WaitForFile max time is 50ms");
return;
}
struct stat sourceInfo; struct stat sourceInfo;
unsigned int waitTime = 500000; unsigned int waitTime = 500000;
int count = 0; unsigned int count = 0;
do { do {
usleep(waitTime); usleep(waitTime);
count++; count++;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册