未验证 提交 cfa0307a 编写于 作者: O openharmony_ci 提交者: Gitee

!1593 do not stop if required fstab file not exists

Merge pull request !1593 from 许云通/excludecfg
......@@ -175,9 +175,8 @@ static int StartUeventd(char **requiredDevices, int num)
static void StartInitSecondStage(void)
{
int requiredNum = 0;
Fstab* fstab = LoadRequiredFstab();
INIT_ERROR_CHECK(fstab != NULL, abort(), "Failed to load required fstab");
char **devices = GetRequiredDevices(*fstab, &requiredNum);
Fstab *fstab = LoadRequiredFstab();
char **devices = (fstab != NULL) ? GetRequiredDevices(*fstab, &requiredNum) : NULL;
if (devices != NULL && requiredNum > 0) {
int ret = StartUeventd(devices, requiredNum);
if (ret == 0) {
......@@ -200,6 +199,10 @@ static void StartInitSecondStage(void)
}
}
if (fstab != NULL) {
ReleaseFstab(fstab);
fstab = NULL;
}
// It will panic if close stdio before execv("/bin/sh", NULL)
CloseStdio();
......
......@@ -32,7 +32,7 @@ int MountRequriedPartitions(const Fstab *fstab)
return rc;
}
Fstab* LoadRequiredFstab(void)
Fstab *LoadRequiredFstab(void)
{
Fstab *fstab = NULL;
fstab = LoadFstabFromCommandLine();
......@@ -40,7 +40,7 @@ Fstab* LoadRequiredFstab(void)
INIT_LOGI("Cannot load fstab from command line, try read from fstab.required");
const char *fstabFile = STARTUP_INIT_UT_PATH"/etc/fstab.required";
INIT_CHECK(access(fstabFile, F_OK) == 0, fstabFile = "/system/etc/fstab.required");
INIT_ERROR_CHECK(access(fstabFile, F_OK) == 0, abort(), "Failed get fstab.required");
INIT_ERROR_CHECK(access(fstabFile, F_OK) == 0, return NULL, "Failed get fstab.required");
fstab = ReadFstabFromFile(fstabFile, false);
}
return fstab;
......
......@@ -23,7 +23,7 @@
extern "C" {
#endif
#endif
Fstab* LoadRequiredFstab(void);
Fstab *LoadRequiredFstab(void);
int MountRequriedPartitions(const Fstab *fstab);
#ifdef __cplusplus
#if __cplusplus
......
......@@ -154,37 +154,31 @@ int SwitchRoot(const char *newRoot)
struct stat newRootStat = {};
if (stat(newRoot, &newRootStat) != 0) {
INIT_LOGE("Failed to get new root \" %s \" stat", newRoot);
FreeRootDir(oldRoot, oldRootStat.st_dev);
return -1;
}
if (oldRootStat.st_dev == newRootStat.st_dev) {
INIT_LOGW("Try to switch root in same device, skip switching root");
FreeRootDir(oldRoot, oldRootStat.st_dev);
return 0;
}
if (MountToNewTarget(newRoot) < 0) {
INIT_LOGE("Failed to move mount to new root \" %s \" stat", newRoot);
FreeRootDir(oldRoot, oldRootStat.st_dev);
return -1;
}
// OK, we've done move mount.
// Now mount new root.
if (chdir(newRoot) < 0) {
INIT_LOGE("Failed to change directory to %s, err = %d", newRoot, errno);
FreeRootDir(oldRoot, oldRootStat.st_dev);
return -1;
}
if (mount(newRoot, "/", NULL, MS_MOVE, NULL) < 0) {
INIT_LOGE("Failed to mount moving %s to %s, err = %d", newRoot, "/", errno);
FreeRootDir(oldRoot, oldRootStat.st_dev);
return -1;
}
if (chroot(".") < 0) {
INIT_LOGE("Failed to change root directory");
FreeRootDir(oldRoot, oldRootStat.st_dev);
return -1;
}
FreeRootDir(oldRoot, oldRootStat.st_dev);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册