mirror of
https://gitee.com/openharmony/startup_init
synced 2024-11-23 16:20:00 +00:00
fix:modify wait time 10ms
Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: liveery <liangming712@huawei.com>
This commit is contained in:
parent
42c1b440b5
commit
63f671167b
@ -54,6 +54,11 @@ char *ReadFileToBuf(const char *configFile);
|
||||
int GetProcCmdlineValue(const char *name, const char *buffer, char *value, int length);
|
||||
char *ReadFileData(const char *fileName);
|
||||
|
||||
typedef struct INIT_TIMING_STAT {
|
||||
struct timespec startTime;
|
||||
struct timespec endTime;
|
||||
} INIT_TIMING_STAT;
|
||||
|
||||
typedef struct NameValuePair {
|
||||
const char *name;
|
||||
const char *nameEnd;
|
||||
@ -63,6 +68,7 @@ typedef struct NameValuePair {
|
||||
int IterateNameValuePairs(const char *src, void (*iterator)(const NAME_VALUE_PAIR *nv, void *context), void *context);
|
||||
|
||||
int SplitString(char *srcPtr, const char *del, char **dstPtr, int maxNum);
|
||||
long long InitDiffTime(INIT_TIMING_STAT *stat);
|
||||
void WaitForFile(const char *source, unsigned int maxSecond);
|
||||
size_t WriteAll(int fd, const char *buffer, size_t size);
|
||||
char *GetRealPath(const char *source);
|
||||
|
@ -73,11 +73,6 @@ struct CmdTable {
|
||||
void (*DoFuncion)(const struct CmdArgs *ctx);
|
||||
};
|
||||
|
||||
typedef struct INIT_TIMING_STAT {
|
||||
struct timespec startTime;
|
||||
struct timespec endTime;
|
||||
} INIT_TIMING_STAT;
|
||||
|
||||
typedef enum _initContextType {
|
||||
INIT_CONTEXT_CHIPSET,
|
||||
INIT_CONTEXT_MAIN,
|
||||
@ -103,7 +98,6 @@ void ExecCmd(const struct CmdTable *cmd, const char *cmdContent);
|
||||
int SetFileCryptPolicy(const char *dir);
|
||||
|
||||
void OpenHidebug(const char *name);
|
||||
long long InitDiffTime(INIT_TIMING_STAT *stat);
|
||||
|
||||
void StopSubInit(pid_t pid);
|
||||
int ExecuteCmdInSubInit(const ConfigContext *context, const char *name, const char *cmdContent);
|
||||
|
@ -737,17 +737,6 @@ int GetCmdLinesFromJson(const cJSON *root, CmdLines **cmdLines)
|
||||
return 0;
|
||||
}
|
||||
|
||||
long long InitDiffTime(INIT_TIMING_STAT *stat)
|
||||
{
|
||||
long long diff = (long long)((stat->endTime.tv_sec - stat->startTime.tv_sec) * 1000000); // 1000000 1000ms
|
||||
if (stat->endTime.tv_nsec > stat->startTime.tv_nsec) {
|
||||
diff += (stat->endTime.tv_nsec - stat->startTime.tv_nsec) / BASE_MS_UNIT;
|
||||
} else {
|
||||
diff -= (stat->startTime.tv_nsec - stat->endTime.tv_nsec) / BASE_MS_UNIT;
|
||||
}
|
||||
return diff;
|
||||
}
|
||||
|
||||
void DoCmdByIndex(int index, const char *cmdContent, const ConfigContext *context)
|
||||
{
|
||||
if (cmdContent == NULL) {
|
||||
|
@ -108,7 +108,6 @@ int SystemTraversalParameter(const char *prefix, TraversalParamPtr traversalPara
|
||||
workSpace = GetNextWorkSpace(workSpace);
|
||||
}
|
||||
while (workSpace != NULL) {
|
||||
PARAM_LOGV("SystemTraversalParameter prefix %s in space %s", context.prefix, workSpace->fileName);
|
||||
WorkSpace *next = GetNextWorkSpace(workSpace);
|
||||
ParamTrieNode *root = NULL;
|
||||
if (prefix != NULL && strlen(prefix) != 0) {
|
||||
|
@ -366,23 +366,36 @@ char **SplitStringExt(char *buffer, const char *del, int *returnCount, int maxIt
|
||||
return items;
|
||||
}
|
||||
|
||||
long long InitDiffTime(INIT_TIMING_STAT *stat)
|
||||
{
|
||||
long long diff = (long long)((stat->endTime.tv_sec - stat->startTime.tv_sec) * 1000000); // 1000000 1000ms
|
||||
if (stat->endTime.tv_nsec > stat->startTime.tv_nsec) {
|
||||
diff += (stat->endTime.tv_nsec - stat->startTime.tv_nsec) / BASE_MS_UNIT;
|
||||
} else {
|
||||
diff -= (stat->startTime.tv_nsec - stat->endTime.tv_nsec) / BASE_MS_UNIT;
|
||||
}
|
||||
return diff;
|
||||
}
|
||||
|
||||
void WaitForFile(const char *source, unsigned int maxSecond)
|
||||
{
|
||||
INIT_ERROR_CHECK(maxSecond <= WAIT_MAX_SECOND, maxSecond = WAIT_MAX_SECOND,
|
||||
"WaitForFile max time is %us", WAIT_MAX_SECOND);
|
||||
struct stat sourceInfo = {0};
|
||||
unsigned int waitTime = 500000;
|
||||
/* 500ms interval, check maxSecond*2 times total */
|
||||
unsigned int maxCount = maxSecond * 2;
|
||||
unsigned int waitTime = 10 * BASE_MS_UNIT; // 10ms
|
||||
long long maxDuration = maxSecond * BASE_MS_UNIT * BASE_MS_UNIT; // 5s
|
||||
#ifdef STARTUP_INIT_TEST
|
||||
maxCount = 0;
|
||||
maxDuration = 0;
|
||||
#endif
|
||||
unsigned int count = 0;
|
||||
while ((stat(source, &sourceInfo) < 0) && (errno == ENOENT) && (count < maxCount)) {
|
||||
long long duration = 0;
|
||||
INIT_TIMING_STAT cmdTimer;
|
||||
(void)clock_gettime(CLOCK_MONOTONIC, &cmdTimer.startTime);
|
||||
while ((stat(source, &sourceInfo) < 0) && (errno == ENOENT) && (duration < maxDuration)) {
|
||||
usleep(waitTime);
|
||||
count++;
|
||||
(void)clock_gettime(CLOCK_MONOTONIC, &cmdTimer.endTime);
|
||||
duration = InitDiffTime(&cmdTimer);
|
||||
}
|
||||
INIT_CHECK_ONLY_ELOG(count != maxCount, "wait for file:%s failed after %d second.", source, maxSecond);
|
||||
INIT_CHECK_ONLY_ELOG(duration < maxDuration, "wait for file:%s failed after %d second.", source, maxSecond);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user