ostree-remount: Check for / being *mounted* read-only, not necessarily writable

The previous S_IMMUTABLE commit broke ostree-remount; / is now not
actually writable.  All we really wanted to know though was whether it
was *mounted* writable, so check that via statvfs() which is cleaner
anyways (i.e. not via access() which kernel people hate).

https://bugzilla.gnome.org/show_bug.cgi?id=728006
This commit is contained in:
Colin Walters 2014-06-03 17:38:00 -04:00
parent f22fa92aef
commit cb43d2942f
1 changed files with 9 additions and 1 deletions

View File

@ -28,6 +28,7 @@
#include <stdint.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/statvfs.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
@ -42,8 +43,15 @@ main(int argc, char *argv[])
const char *remounts[] = { "/sysroot", "/etc", "/home", "/root", "/tmp", "/var", NULL };
struct stat stbuf;
int i;
struct statvfs stvfsbuf;
if (access ("/", W_OK) == -1)
if (statvfs ("/", &stvfsbuf) == -1)
{
perror ("statvfs(/): ");
exit (1);
}
if (stvfsbuf.f_flag & ST_RDONLY)
{
/* If / isn't writable, don't do any remounts; we don't want
* to clear the readonly flag in that case.