提交 a08f1db7 编写于 作者: 熊磊 提交者: Gitee

Merge branch 'master' of gitee.com:openharmony/startup_init_lite into init119_3

Signed-off-by: Nxionglei <xionglei6@huawei.com>
......@@ -297,7 +297,7 @@ int MountOneItem(FstabItem *item)
return -1;
}
if (FM_MANAGER_WAIT_ENABLED(item->fsManagerFlags)) {
WaitForFile(item->deviceName, WAIT_MAX_COUNT);
WaitForFile(item->deviceName, WAIT_MAX_SECOND);
}
if (strcmp(item->fsType, "f2fs") == 0 && strcmp(item->mountPoint, "/data") == 0) {
......
......@@ -33,16 +33,17 @@ typedef struct {
#define BINARY_BASE 2
#define OCTAL_BASE 8
#define DECIMAL_BASE 10
#define WAIT_MAX_COUNT 10
#define WAIT_MAX_SECOND 5
#define MAX_BUFFER_LEN 256
#define ARRAY_LENGTH(array) (sizeof((array)) / sizeof((array)[0]))
uid_t DecodeUid(const char *name);
char *ReadFileToBuf(const char *configFile);
int GetProcCmdlineValue(const char *name, const char *buffer, char *value, int length);
char *ReadFileData(const char *fileName);
int SplitString(char *srcPtr, const char *del, char **dstPtr, int maxNum);
void WaitForFile(const char *source, unsigned int maxCount);
void WaitForFile(const char *source, unsigned int maxSecond);
size_t WriteAll(int fd, const char *buffer, size_t size);
char *GetRealPath(const char *source);
int StringToInt(const char *str, int defaultValue);
......
......@@ -177,6 +177,23 @@ static void DoSleep(const struct CmdArgs *ctx)
sleep((unsigned int)sleepTime);
}
static void DoWait(const struct CmdArgs *ctx)
{
const int filePos = 0;
const int timePos = 1;
unsigned long waitSecond = WAIT_MAX_SECOND;
if (ctx->argc == timePos + 1) {
errno = 0;
waitSecond = strtoul(ctx->argv[timePos], NULL, DECIMAL_BASE);
INIT_ERROR_CHECK(errno == 0,
return, "cannot covert sleep time in command \" wait \"");
}
INIT_LOGI("Waiting %s %lu second(s)", ctx->argv[filePos], waitSecond);
WaitForFile(ctx->argv[filePos], waitSecond);
}
static void DoStart(const struct CmdArgs *ctx)
{
INIT_LOGV("DoStart %s", ctx->argv[0]);
......@@ -365,7 +382,7 @@ static int GetMountFlag(unsigned long *mountflag, const char *targetStr, const c
}
}
if (strncmp(targetStr, "wait", strlen("wait")) == 0) {
WaitForFile(source, WAIT_MAX_COUNT);
WaitForFile(source, WAIT_MAX_SECOND);
return 1;
}
return 0;
......@@ -504,6 +521,7 @@ static const struct CmdTable g_cmdTable[] = {
{ "reboot ", 1, 1, DoRebootCmd },
{ "setrlimit ", 3, 3, DoSetrlimit },
{ "sleep ", 1, 1, DoSleep },
{ "wait ", 1, 2, DoWait },
{ "hostname ", 1, 1, DoSetHostname },
{ "domainname ", 1, 1, DoSetDomainname }
};
......
......@@ -151,7 +151,7 @@ static void OpenConsole(void)
{
const int stdError = 2;
setsid();
WaitForFile("/dev/console", WAIT_MAX_COUNT);
WaitForFile("/dev/console", WAIT_MAX_SECOND);
int fd = open("/dev/console", O_RDWR);
if (fd >= 0) {
ioctl(fd, TIOCSCTTY, 0);
......
......@@ -259,19 +259,19 @@ char **SplitStringExt(char *buffer, const char *del, int *returnCount, int maxIt
return items;
}
void WaitForFile(const char *source, unsigned int maxCount)
void WaitForFile(const char *source, unsigned int maxSecond)
{
unsigned int maxCountTmp = maxCount;
INIT_ERROR_CHECK(maxCountTmp <= WAIT_MAX_COUNT, maxCountTmp = WAIT_MAX_COUNT, "WaitForFile max time is 5s");
INIT_ERROR_CHECK(maxSecond <= WAIT_MAX_SECOND, maxSecond = WAIT_MAX_SECOND, "WaitForFile max time is 5s");
struct stat sourceInfo = {};
const unsigned int waitTime = 500000;
unsigned int waitTime = 500000;
/* 500ms interval, check maxSecond*2 times total */
unsigned int maxCount = maxSecond * 2;
unsigned int count = 0;
do {
usleep(waitTime);
count++;
} while ((stat(source, &sourceInfo) < 0) && (errno == ENOENT) && (count < maxCountTmp));
float secTime = ConvertMicrosecondToSecond(waitTime);
INIT_CHECK_ONLY_ELOG(count != maxCountTmp, "wait for file:%s failed after %f.", source, maxCountTmp * secTime);
} while ((stat(source, &sourceInfo) < 0) && (errno == ENOENT) && (count < maxCount));
INIT_CHECK_ONLY_ELOG(count != maxCount, "wait for file:%s failed after %d second.", source, maxSecond);
return;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册