Skip to content

Commit

Permalink
Use /proc/self/mounts instead of /etc/mtab
Browse files Browse the repository at this point in the history
According to glibc documentation one should use `_PATH_MOUNTED`, which
by default should point to `/etc/mtab`. This file is maintained by
`mount` and `umount` programs.

This is wrong if we are running in a sandboxed everinment, e.g. Linux
containers (OpenVZ, Docker, Rocket, LXC/LXD) or chroot/proot. Then this
files comes from alternative rootfs and does not reflect actual mount
points.

On modern systems (incl. CentOS 7 and Fedora) `/etc/mtab` points to
`/proc/self/mounts`.

The patch by default reads `/proc/self/mounts` on Linux systems.

By default Docker will create a `/etc/mtab` as symlink to `/proc/mounts`
(which points to `/proc/self/mounts`) on any container.

OpenVZ documentation also request chaging `/etc/mtab` to a symlink.

Same in Linux From Scratch guide. Also reminds that `/` could be mounted
as read-only, thus `/etc/mtab` could be stale.

Signed-off-by: David Abdurachmanov <David.Abdurachmanov@cern.ch>
Reported-by: Sébastien Brochet <sebastien.brochet@cern.ch>
  • Loading branch information
David Abdurachmanov authored and David Abdurachmanov committed Jun 10, 2015
1 parent 6e90284 commit 30aa2a7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Utilities/StorageFactory/src/LocalFileSystem.cc
Expand Up @@ -230,13 +230,14 @@ LocalFileSystem::initFSList(void)

free(mtab);
#else
const char * const _PATH_MOUNTED_LINUX = "/proc/self/mounts";
struct mntent *m;
FILE *mtab = setmntent(_PATH_MOUNTED, "r");
FILE *mtab = setmntent(_PATH_MOUNTED_LINUX, "r");
if (! mtab)
{
int nerr = errno;
edm::LogWarning("LocalFileSystem::initFSList()")
<< "Cannot read '" << _PATH_MOUNTED << "': "
<< "Cannot read '" << _PATH_MOUNTED_LINUX << "': "
<< strerror(nerr) << " (error " << nerr << ")";
return -1;
}
Expand Down

0 comments on commit 30aa2a7

Please sign in to comment.