mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-12-11 20:32:42 +03:00
path: make the check for unsupported name_to_handle_at symmetric
If child supports, but the parent does not, or when the child does not support, but the parent does, assume the child is a mount point. Only if neither supports use the fallback.
This commit is contained in:
@@ -462,6 +462,7 @@ int path_is_mount_point(const char *t, bool allow_symlink) {
|
|||||||
_cleanup_free_ char *parent = NULL;
|
_cleanup_free_ char *parent = NULL;
|
||||||
struct stat a, b;
|
struct stat a, b;
|
||||||
int r;
|
int r;
|
||||||
|
bool nosupp = false;
|
||||||
|
|
||||||
/* We are not actually interested in the file handles, but
|
/* We are not actually interested in the file handles, but
|
||||||
* name_to_handle_at() also passes us the mount ID, hence use
|
* name_to_handle_at() also passes us the mount ID, hence use
|
||||||
@@ -476,12 +477,11 @@ int path_is_mount_point(const char *t, bool allow_symlink) {
|
|||||||
/* This kernel or file system does not support
|
/* This kernel or file system does not support
|
||||||
* name_to_handle_at(), hence fallback to the
|
* name_to_handle_at(), hence fallback to the
|
||||||
* traditional stat() logic */
|
* traditional stat() logic */
|
||||||
goto fallback;
|
nosupp = true;
|
||||||
|
else if (errno == ENOENT)
|
||||||
if (errno == ENOENT)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
else
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = path_get_parent(t, &parent);
|
r = path_get_parent(t, &parent);
|
||||||
@@ -490,17 +490,22 @@ int path_is_mount_point(const char *t, bool allow_symlink) {
|
|||||||
|
|
||||||
h.handle.handle_bytes = MAX_HANDLE_SZ;
|
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(AT_FDCWD, parent, &h.handle, &mount_id_parent, AT_SYMLINK_FOLLOW);
|
||||||
if (r < 0) {
|
if (r < 0)
|
||||||
/* The parent can't do name_to_handle_at() but the
|
|
||||||
* directory we are interested in can? If so, it must
|
|
||||||
* be a mount point */
|
|
||||||
if (errno == EOPNOTSUPP)
|
if (errno == EOPNOTSUPP)
|
||||||
return 1;
|
if (nosupp)
|
||||||
|
/* Neither parent nor child do name_to_handle_at()?
|
||||||
return -errno;
|
We have no choice but to fall back. */
|
||||||
}
|
goto fallback;
|
||||||
|
else
|
||||||
return mount_id != mount_id_parent;
|
/* The parent can't do name_to_handle_at() but
|
||||||
|
* the directory we are interested in can?
|
||||||
|
* Or the other way around?
|
||||||
|
* If so, it must be a mount point. */
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return -errno;
|
||||||
|
else
|
||||||
|
return mount_id != mount_id_parent;
|
||||||
|
|
||||||
fallback:
|
fallback:
|
||||||
if (allow_symlink)
|
if (allow_symlink)
|
||||||
|
|||||||
Reference in New Issue
Block a user