chiark / gitweb /
path-util: Fix path_is_mount_point for files
authorMartin Pitt <martin.pitt@ubuntu.com>
Wed, 27 May 2015 07:56:03 +0000 (09:56 +0200)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 09:00:52 +0000 (10:00 +0100)
commit07db2f78ec6a39bdd05a8481578a641efbab3a2c
treeb92e5c52dad1fe7e7a65b816077ad306cea4457c
parent73feab10082362f460519d4c38379ca365f432df
path-util: Fix path_is_mount_point for files

Commits 27cc6f166 and f25afeb broke path_is_mount_point() for files (such as
/etc/machine-id → /run/machine-id bind mounts) as with the factorization of
fd_is_mount_point() we lost the parent directory. We cannot determine that from
an fd only as openat(fd, "..") only works for directory fds.

Change fd_is_mount_point() to behave like openat(): It now takes a file
descriptor of the containing directory, a file name in it, and flags (which can
be 0 or AT_SYMLINK_FOLLOW). Unlike name_to_handle_at() or openat(), fstatat()
only accepts the inverse flag AT_SYMLINK_NOFOLLOW and complains with EINVAL
about AT_SYMLINK_FOLLOW; so we need to transform the flags for that fallback.

Adjust rm_rf_children() accordingly (only other caller of fd_is_mount_point()
aside from path_is_mount_point()).

Add test cases for files, links, and file bind mounts (the latter will only
work when running as root). Split out a new test_path_is_mount_point() test
case function as it got significantly larger now.
src/shared/path-util.c
src/shared/path-util.h
src/shared/rm-rf.c