summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorMartin Pitt <martin.pitt@ubuntu.com>2015-06-09 16:16:56 +0200
committerMartin Pitt <martin.pitt@ubuntu.com>2015-06-09 16:16:56 +0200
commit36908eb87de06267c8cc824aa9dccb1b428419aa (patch)
tree1ad90486130d8d1a61025d17c88c1987a6d9ea04 /src/shared
parent4f7cd56ef270ec2614f2efc916551b5e3c5acc50 (diff)
path-util: Fix path_is_mount_point for parent mount points in symlink mode
When we have a structure like this: /bin -> /usr/bin /usr is a mount point Then path_is_mount_point("/bin", AT_SYMLINK_FOLLOW) needs to look at the pair /usr/bin and /usr, not at the pair / and /usr/bin, as the latter have different mount IDs. But we only want to consider the base name, not any parent. Thus we have to resolve the given path first to get the real parent when allowing symlinks. Bug: https://github.com/systemd/systemd/issues/61
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/path-util.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/shared/path-util.c b/src/shared/path-util.c
index be50a1865d..537705446a 100644
--- a/src/shared/path-util.c
+++ b/src/shared/path-util.c
@@ -640,7 +640,7 @@ fallback_fstat:
/* flags can be AT_SYMLINK_FOLLOW or 0 */
int path_is_mount_point(const char *t, int flags) {
_cleanup_close_ int fd = -1;
- _cleanup_free_ char *parent = NULL;
+ _cleanup_free_ char *canonical = NULL, *parent = NULL;
int r;
assert(t);
@@ -648,7 +648,17 @@ int path_is_mount_point(const char *t, int flags) {
if (path_equal(t, "/"))
return 1;
- r = path_get_parent(t, &parent);
+ /* we need to resolve symlinks manually, we can't just rely on
+ * fd_is_mount_point() to do that for us; if we have a structure like
+ * /bin -> /usr/bin/ and /usr is a mount point, then the parent that we
+ * look at needs to be /usr, not /. */
+ if (flags & AT_SYMLINK_FOLLOW) {
+ canonical = canonicalize_file_name(t);
+ if (!canonical)
+ return -errno;
+ }
+
+ r = path_get_parent(canonical ?: t, &parent);
if (r < 0)
return r;
@@ -656,7 +666,7 @@ int path_is_mount_point(const char *t, int flags) {
if (fd < 0)
return -errno;
- return fd_is_mount_point(fd, basename(t), flags);
+ return fd_is_mount_point(fd, basename(canonical ?: t), flags);
}
int path_is_read_only_fs(const char *path) {