From 6e579a6b7aeef86a5f39e057f1f57616d1779b52 Mon Sep 17 00:00:00 2001 From: zhong_ning Date: Thu, 8 Jul 2021 22:20:16 +0800 Subject: [PATCH] fix bug Signed-off-by: zhong_ning --- services/etc/init.cfg | 7 +++++-- services/include/init_utils.h | 2 +- services/log/init_log.c | 2 +- services/src/init_capability.c | 16 ++++++++-------- services/src/init_reboot.c | 27 +++++++++++++++++---------- services/src/init_utils.c | 9 +++++++-- 6 files changed, 39 insertions(+), 24 deletions(-) diff --git a/services/etc/init.cfg b/services/etc/init.cfg index 67036a28..cf96169d 100755 --- a/services/etc/init.cfg +++ b/services/etc/init.cfg @@ -5,7 +5,10 @@ "/init.${ro.hardware}.cfg", "/init.Hi3516DV300.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" : [{ "name" : "pre-init", @@ -20,7 +23,7 @@ "mkdir /vendor", "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/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", diff --git a/services/include/init_utils.h b/services/include/init_utils.h index 3b2d3ee2..502cd34f 100644 --- a/services/include/init_utils.h +++ b/services/include/init_utils.h @@ -37,7 +37,7 @@ int DecodeUid(const char *name); void CheckAndCreateDir(const char *fileName); char* ReadFileToBuf(const char *configFile); 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 #if __cplusplus diff --git a/services/log/init_log.c b/services/log/init_log.c index 2d044610..4f8ec071 100644 --- a/services/log/init_log.c +++ b/services/log/init_log.c @@ -42,7 +42,7 @@ void InitLog(const char *tag, InitLogLevel logLevel, const char *fileName, int l if (logLevel < g_logLevel) { return; } - // ????stdout?????????? + // 可以替换stdout这个为对应的文件句柄 time_t logTime; time(&logTime); struct tm *t = gmtime(&logTime); diff --git a/services/src/init_capability.c b/services/src/init_capability.c index 4d47ebdf..59ba0edf 100644 --- a/services/src/init_capability.c +++ b/services/src/init_capability.c @@ -85,7 +85,7 @@ static int GetServiceStringCaps(const cJSON* filedJ, Service* curServ) for (; i < curServ->servPerm.capsCnt; ++i) { if (cJSON_GetArrayItem(filedJ, i) == NULL || !cJSON_GetStringValue(cJSON_GetArrayItem(filedJ, i)) || 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; } char* fieldStr = cJSON_GetStringValue(cJSON_GetArrayItem(filedJ, i)); @@ -99,12 +99,12 @@ static int GetServiceStringCaps(const cJSON* filedJ, Service* curServ) if (j < mapSize) { curServ->servPerm.caps[i] = g_capStrCapNum[j].CapNum; } 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; } if (curServ->servPerm.caps[i] > CAP_LAST_CAP && curServ->servPerm.caps[i] != FULL_CAP) { // 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; } } @@ -121,7 +121,7 @@ int GetServiceCaps(const cJSON* curArrItem, Service* curServ) return SERVICE_SUCCESS; } 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; } // caps array does not exist, means do not need any capability @@ -130,13 +130,13 @@ int GetServiceCaps(const cJSON* curArrItem, Service* curServ) return SERVICE_SUCCESS; } 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); return SERVICE_FAILURE; } curServ->servPerm.caps = (unsigned int*)malloc(sizeof(unsigned int) * capsCnt); 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; } curServ->servPerm.capsCnt = capsCnt; @@ -145,13 +145,13 @@ int GetServiceCaps(const cJSON* curArrItem, Service* curServ) cJSON* capJ = cJSON_GetArrayItem(filedJ, i); if (!cJSON_IsNumber(capJ) || cJSON_GetNumberValue(capJ) < 0) { // 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; } 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 // 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; } } diff --git a/services/src/init_reboot.c b/services/src/init_reboot.c index 4fcf9074..be0db3e0 100644 --- a/services/src/init_reboot.c +++ b/services/src/init_reboot.c @@ -80,7 +80,7 @@ static int GetMountStatusForMountPoint(const char *mountPoint) const char *mountFile = "/proc/mounts"; FILE *fp = fopen(mountFile, "r"); if (fp == NULL) { - INIT_LOGE("[init] DoReboot %s can't open.\n", mountPoint); + INIT_LOGE("DoReboot %s can't open.\n", mountPoint); return 1; } @@ -103,24 +103,32 @@ static int GetMountStatusForMountPoint(const char *mountPoint) void DoReboot(const char *value) { if (value == NULL) { - INIT_LOGE("[init] DoReboot value = NULL\n"); + INIT_LOGE("DoReboot value = NULL\n"); return; } - INIT_LOGI("[init] DoReboot value = %s\n", value); + INIT_LOGI("DoReboot value = %s\n", value); 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; } const char *valueData = NULL; 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; } else { 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 (umount("/vendor") != 0) { INIT_LOGE("DoReboot umount vendor failed! errno = %d.\n", errno); @@ -131,7 +139,6 @@ void DoReboot(const char *value) INIT_LOGE("DoReboot umount data failed! errno = %d.\n", errno); } } - StopAllServicesBeforeReboot(); // "shutdown" if (strncmp(valueData, "shutdown", strlen("shutdown")) == 0) { int ret = reboot(RB_POWER_OFF); @@ -145,7 +152,7 @@ void DoReboot(const char *value) struct RBMiscUpdateMessage msg; bool ret = RBMiscReadUpdaterMessage(miscFile, &msg); if(!ret) { - INIT_LOGE("[init] DoReboot RBMiscReadUpdaterMessage error.\n"); + INIT_LOGE("DoReboot RBMiscReadUpdaterMessage error.\n"); return; } const int commandSize = 12; @@ -155,13 +162,13 @@ void DoReboot(const char *value) if (strlen(valueData) > strlen("updater:") && strncmp(valueData, "updater:", strlen("updater:")) == 0) { const char *p = valueData + strlen("updater:"); 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; } msg.update[MAX_UPDATE_SIZE - 1] = 0; ret = RBMiscWriteUpdaterMessage(miscFile, &msg); if(true != ret) { - INIT_LOGE("[init] DoReboot updater: RBMiscWriteUpdaterMessage error\n"); + INIT_LOGE("DoReboot updater: RBMiscWriteUpdaterMessage error\n"); return; } ret = reboot(RB_AUTOBOOT); @@ -173,7 +180,7 @@ void DoReboot(const char *value) if (strlen(valueData) == strlen("updater") && strncmp(valueData, "updater", strlen("updater")) == 0) { ret = RBMiscWriteUpdaterMessage(miscFile, &msg); if(true != ret) { - INIT_LOGE("[init] DoReboot updater RBMiscWriteUpdaterMessage error\n"); + INIT_LOGE("DoReboot updater RBMiscWriteUpdaterMessage error\n"); return; } ret = reboot(RB_AUTOBOOT); diff --git a/services/src/init_utils.c b/services/src/init_utils.c index 489ed284..9c7abcfa 100644 --- a/services/src/init_utils.c +++ b/services/src/init_utils.c @@ -34,6 +34,7 @@ #include "init_utils.h" #include "securec.h" +#define WAIT_MAX_COUNT 10 #define MAX_BUF_SIZE 1024 #ifdef STARTUP_UT #define LOG_FILE_NAME "/media/sf_ubuntu/test/log.txt" @@ -179,11 +180,15 @@ int SplitString(char *srcPtr, char **dstPtr, int maxNum) 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; unsigned int waitTime = 500000; - int count = 0; + unsigned int count = 0; do { usleep(waitTime); count++; -- GitLab