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