summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorHarald Hoyer <harald@redhat.com>2015-02-20 13:25:42 +0100
committerAnthony G. Basile <blueness@gentoo.org>2015-03-18 20:51:19 -0400
commit35ef251e168ba03f395d04394b88fdb2fa437ea9 (patch)
treefc7d530829d836eb865755feece52da81b1dc73c /src/shared
parent16ded2181496dbacd26229441abd59c224b2ba7a (diff)
path-util: fix path_is_mount_point() for symlinks
path_is_mount_point() compares the mount_id of a directory and the mount_id of the parent directory. When following symlinks, the function to get the parent directory does not take the symlink into account. /bin -> /usr/bin with /usr being a mountpoint: mount_id of /bin with AT_SYMLINK_FOLLOW != mount_id of / Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/path-util.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/shared/path-util.c b/src/shared/path-util.c
index 152fef9b24..92e3a8777e 100644
--- a/src/shared/path-util.c
+++ b/src/shared/path-util.c
@@ -317,9 +317,9 @@ int path_is_mount_point(const char *t, bool allow_symlink) {
union file_handle_union h = FILE_HANDLE_INIT;
int mount_id = -1, mount_id_parent = -1;
- _cleanup_free_ char *parent = NULL;
struct stat a, b;
int r;
+ _cleanup_close_ int fd = -1;
bool nosupp = false;
/* We are not actually interested in the file handles, but
@@ -329,7 +329,15 @@ int path_is_mount_point(const char *t, bool allow_symlink) {
if (path_equal(t, "/"))
return 1;
- r = name_to_handle_at(AT_FDCWD, t, &h.handle, &mount_id, allow_symlink ? AT_SYMLINK_FOLLOW : 0);
+ fd = openat(AT_FDCWD, t, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|(allow_symlink ? 0 : O_PATH));
+ if (fd < 0) {
+ if (errno == ENOENT)
+ return 0;
+
+ return -errno;
+ }
+
+ r = name_to_handle_at(fd, "", &h.handle, &mount_id, AT_EMPTY_PATH);
if (r < 0) {
if (errno == ENOSYS)
/* This kernel does not support name_to_handle_at()
@@ -346,12 +354,9 @@ int path_is_mount_point(const char *t, bool allow_symlink) {
return -errno;
}
- r = path_get_parent(t, &parent);
- if (r < 0)
- return r;
h.handle.handle_bytes = MAX_HANDLE_SZ;
- r = name_to_handle_at(AT_FDCWD, parent, &h.handle, &mount_id_parent, AT_SYMLINK_FOLLOW);
+ r = name_to_handle_at(fd, "..", &h.handle, &mount_id_parent, 0);
if (r < 0)
if (errno == EOPNOTSUPP)
if (nosupp)
@@ -370,10 +375,7 @@ int path_is_mount_point(const char *t, bool allow_symlink) {
return mount_id != mount_id_parent;
fallback:
- if (allow_symlink)
- r = stat(t, &a);
- else
- r = lstat(t, &a);
+ r = fstatat(fd, "", &a, AT_EMPTY_PATH);
if (r < 0) {
if (errno == ENOENT)
@@ -382,14 +384,8 @@ fallback:
return -errno;
}
- free(parent);
- parent = NULL;
-
- r = path_get_parent(t, &parent);
- if (r < 0)
- return r;
- r = stat(parent, &b);
+ r = fstatat(fd, "..", &b, 0);
if (r < 0)
return -errno;