From: Miklos Szeredi <miklos@szeredi.hu> Date: Thu, 10 Jul 2008 19:35:21 +0000 (+0000) Subject: Skip calling mount(8) if /etc/mtab doesn't exist... X-Git-Tag: fuse_2_8_0_pre2~12 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=5f28cd15ab43c741f6d116be4d3a9aa5d82ab385;p=qemu-gpiodev%2Flibfuse.git Skip calling mount(8) if /etc/mtab doesn't exist... --- diff --git a/ChangeLog b/ChangeLog index 638dd3c..4f56566 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,10 @@ * Fix handling of (no)suid and (no)dev options if filesystem is mounted from /etc/fstab or via mount(8). Reported by Jan Ondrej. + * Skip calling mount(8) if /etc/mtab doesn't exist or if it's on a + read-only filesystem. This works around issues with certain mount + implementations. Reported by Szabolcs Szakacsits. + 2008-06-16 Miklos Szeredi <miklos@szeredi.hu> * Remove fuse kernel module sources. Linux 2.6.27 will support diff --git a/lib/mount_util.c b/lib/mount_util.c index 7db8060..e78b482 100644 --- a/lib/mount_util.c +++ b/lib/mount_util.c @@ -22,6 +22,7 @@ static int mtab_needs_update(const char *mnt) { + int res; struct stat stbuf; /* If mtab is within new mount, don't touch it */ @@ -29,8 +30,25 @@ static int mtab_needs_update(const char *mnt) _PATH_MOUNTED[strlen(mnt)] == '/') return 0; - if (lstat(_PATH_MOUNTED, &stbuf) != -1 && S_ISLNK(stbuf.st_mode)) - return 0; + /* + * Skip mtab update if /etc/mtab: + * + * - doesn't exist, + * - is a symlink, + * - is on a read-only filesystem. + */ + res = lstat(_PATH_MOUNTED, &stbuf); + if (res == -1) { + if (errno == ENOENT) + return 0; + } else { + if (S_ISLNK(stbuf.st_mode)) + return 0; + + res = access(_PATH_MOUNTED, W_OK); + if (res == -1 && errno == EROFS) + return 0; + } return 1; }