Check result of fsck before attempting remounting / read-write

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2020-04-26 21:45:12 +02:00
1 parent 317fe7aceb
commit e02f8cf353
1 file changed
+8 -8
+8 -8
View File
@@ -90,8 +90,9 @@ static void banner(void)
*/ */
static int fsck(int pass) static int fsck(int pass)
{ {
// int save;
struct fstab *fs; struct fstab *fs;
// int save;
int rc = 0;
if (!setfsent()) { if (!setfsent()) {
_pe("Failed opening fstab"); _pe("Failed opening fstab");
@@ -122,14 +123,14 @@ static int fsck(int pass)
} }
snprintf(cmd, sizeof(cmd), "fsck -a %s", fs->fs_spec); snprintf(cmd, sizeof(cmd), "fsck -a %s", fs->fs_spec);
run_interactive(cmd, "Checking filesystem %.13s", fs->fs_spec); rc += run_interactive(cmd, "Checking filesystem %.13s", fs->fs_spec);
} }
// if (save) // if (save)
// log_debug(); // log_debug();
endfsent(); endfsent();
return 0; return rc;
} }
/* /*
@@ -371,15 +372,14 @@ int main(int argc, char *argv[])
banner(); banner();
/* /*
* Check file filesystems in /etc/fstab * Check file systems listed with pass > 0 in /etc/fstab
*/ */
rc = 0; rc = 0;
for (int pass = 1; pass < 10 && !rescue; pass++) { for (int pass = 1; pass < 10 && !rescue; pass++) {
if (fsck(pass)) { rc = fsck(pass);
rc++; if (rc)
break; break;
} }
}
/* /*
* Mount filesystems * Mount filesystems
@@ -398,7 +398,7 @@ int main(int argc, char *argv[])
continue; continue;
if (strcmp(fs->fs_type, "ro")) { if (strcmp(fs->fs_type, "ro")) {
if (!rc) if (rc)
print(1, "Cannot remount / as read-write, fsck failed before"); print(1, "Cannot remount / as read-write, fsck failed before");
else else
rc = run_interactive("mount -n -o remount,rw /", "Remounting / as read-write"); rc = run_interactive("mount -n -o remount,rw /", "Remounting / as read-write");