summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-04-05 11:12:16 +0200
committerAnthony G. Basile <blueness@gentoo.org>2015-04-12 18:58:57 -0400
commitea18efb8e7b71efb5929e568e087ad27290fce20 (patch)
tree5f2d3f98cb538ea7354170beac7a178959c502c8 /src
parentdf768a72b5e6b114b596a1779476f033a6947eb3 (diff)
path-util: make sure fd_is_mount_point() returns true for root directory
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src')
-rw-r--r--src/shared/path-util.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/shared/path-util.c b/src/shared/path-util.c
index 8678ef516b..6855937a10 100644
--- a/src/shared/path-util.c
+++ b/src/shared/path-util.c
@@ -331,12 +331,14 @@ bool path_equal(const char *a, const char *b) {
}
int fd_is_mount_point(int fd) {
- union file_handle_union h = FILE_HANDLE_INIT;
+ union file_handle_union h = FILE_HANDLE_INIT, h_parent = FILE_HANDLE_INIT;
int mount_id = -1, mount_id_parent = -1;
bool nosupp = false;
struct stat a, b;
int r;
+ assert(fd >= 0);
+
/* We are not actually interested in the file handles, but
* name_to_handle_at() also passes us the mount ID, hence use
* it but throw the handle away */
@@ -360,8 +362,7 @@ int fd_is_mount_point(int fd) {
return -errno;
}
- h.handle.handle_bytes = MAX_HANDLE_SZ;
- r = name_to_handle_at(fd, "..", &h.handle, &mount_id_parent, 0);
+ r = name_to_handle_at(fd, "..", &h_parent.handle, &mount_id_parent, 0);
if (r < 0) {
if (errno == EOPNOTSUPP) {
if (nosupp)
@@ -380,8 +381,19 @@ int fd_is_mount_point(int fd) {
* directory we are interested in can't? If so, it
* must be a mount point. */
return 1;
- else
+ else {
+ /* If the file handle for the directory we are
+ * interested in and its parent are identical, we
+ * assume this is the root directory, which is a mount
+ * point. */
+
+ if (h.handle.handle_bytes == h_parent.handle.handle_bytes &&
+ h.handle.handle_type == h_parent.handle.handle_type &&
+ memcmp(h.handle.f_handle, h_parent.handle.f_handle, h.handle.handle_bytes) == 0)
+ return 1;
+
return mount_id != mount_id_parent;
+ }
fallback:
r = fstatat(fd, "", &a, AT_EMPTY_PATH);
@@ -396,6 +408,12 @@ fallback:
if (r < 0)
return -errno;
+ /* A directory with same device and inode as its parent? Must
+ * be the root directory */
+ if (a.st_dev == b.st_dev &&
+ a.st_ino == b.st_ino)
+ return 1;
+
return a.st_dev != b.st_dev;
}