[systemd-devel] [PATCH] path-util.c: fix path_is_mount_point() for symlinks

harald at redhat.com harald at redhat.com
Fri Feb 20 01:32:59 PST 2015


From: Harald Hoyer <harald at redhat.com>

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 /
---
 src/shared/path-util.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/shared/path-util.c b/src/shared/path-util.c
index b9db7f1..acc7569 100644
--- a/src/shared/path-util.c
+++ b/src/shared/path-util.c
@@ -485,7 +485,17 @@ int path_is_mount_point(const char *t, bool allow_symlink) {
                         return -errno;
         }
 
-        r = path_get_parent(t, &parent);
+        if (allow_symlink) {
+                char *real;
+                real = realpath(t, NULL);
+                if (!real)
+                        return -errno;
+                r = path_get_parent(real, &parent);
+                free(real);
+        } else {
+                r = path_get_parent(t, &parent);
+        }
+
         if (r < 0)
                 return r;
 
-- 
2.3.0



More information about the systemd-devel mailing list