Skip to content
11 changes: 10 additions & 1 deletion src/switchroot/ostree-remount.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ maybe_mount_tmpfs_on_var (void)
int
main(int argc, char *argv[])
{
const char *remounts[] = { "/sysroot", "/etc", "/home", "/root", "/tmp", "/var", NULL };
const char *remounts[] = { "/sysroot", "/var", NULL };
struct stat stbuf;
int i;

Expand All @@ -84,6 +84,14 @@ main(int argc, char *argv[])
*/
if (S_ISLNK (stbuf.st_mode))
continue;
/* If not a mountpoint, skip it */
struct statvfs stvfsbuf;
if (statvfs (target, &stvfsbuf) == -1)
continue;
/* If no read-only flag, skip it */
if ((stvfsbuf.f_flag & ST_RDONLY) == 0)
continue;
/* It's a mounted, read-only fs; remount it */
if (mount (target, target, NULL, MS_REMOUNT | MS_SILENT, NULL) < 0)
{
/* Also ignore ENINVAL - if the target isn't a mountpoint
Expand All @@ -92,6 +100,7 @@ main(int argc, char *argv[])
if (errno != EINVAL)
err (EXIT_FAILURE, "failed to remount %s", target);
}
printf ("Remounted: %s\n", target);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe in the else instead, e.g.

if (mount (...) < 0)
  {
    ...
  }
else
  printf ("Remounted: %s\n", target);

?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We call err and abort the process if it fails.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it'll still print it if we get EINVAL, right? That can be misleading. (Heck, maybe we should even print a different msg in the EINVAL case).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, fixed. ⬇️

}

maybe_mount_tmpfs_on_var ();
Expand Down