switchroot/remount: Check mount status before remounting, be verbose
By checking the mount status, we avoid remounting things if we don't need to. And printing a single line per mount helps debugging when things go wrong. Closes: #859 Approved by: jlebon
This commit is contained in:
parent
f21f500e40
commit
d815ba2a81
|
|
@ -64,6 +64,14 @@ main(int argc, char *argv[])
|
||||||
*/
|
*/
|
||||||
if (S_ISLNK (stbuf.st_mode))
|
if (S_ISLNK (stbuf.st_mode))
|
||||||
continue;
|
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)
|
if (mount (target, target, NULL, MS_REMOUNT | MS_SILENT, NULL) < 0)
|
||||||
{
|
{
|
||||||
/* Also ignore ENINVAL - if the target isn't a mountpoint
|
/* Also ignore ENINVAL - if the target isn't a mountpoint
|
||||||
|
|
@ -72,6 +80,8 @@ main(int argc, char *argv[])
|
||||||
if (errno != EINVAL)
|
if (errno != EINVAL)
|
||||||
err (EXIT_FAILURE, "failed to remount %s", target);
|
err (EXIT_FAILURE, "failed to remount %s", target);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
printf ("Remounted: %s\n", target);
|
||||||
}
|
}
|
||||||
|
|
||||||
exit (EXIT_SUCCESS);
|
exit (EXIT_SUCCESS);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue