|
Zbigniew Jędrzejewski-Szmek |
436654 |
From 117a45829a6be1ef728616c3c90fc8c6f9eda318 Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
From: Martin Pitt <martin.pitt@ubuntu.com>
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
Date: Wed, 27 May 2015 09:56:03 +0200
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
Subject: [PATCH] path-util: Fix path_is_mount_point for files
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
MIME-Version: 1.0
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
Content-Type: text/plain; charset=UTF-8
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
Content-Transfer-Encoding: 8bit
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
Commits 27cc6f166 and f25afeb broke path_is_mount_point() for files (such as
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
/etc/machine-id → /run/machine-id bind mounts) as with the factorization of
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
fd_is_mount_point() we lost the parent directory. We cannot determine that from
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
an fd only as openat(fd, "..") only works for directory fds.
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
Change fd_is_mount_point() to behave like openat(): It now takes a file
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
descriptor of the containing directory, a file name in it, and flags (which can
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
be 0 or AT_SYMLINK_FOLLOW). Unlike name_to_handle_at() or openat(), fstatat()
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
only accepts the inverse flag AT_SYMLINK_NOFOLLOW and complains with EINVAL
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
about AT_SYMLINK_FOLLOW; so we need to transform the flags for that fallback.
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
Adjust rm_rf_children() accordingly (only other caller of fd_is_mount_point()
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
aside from path_is_mount_point()).
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
Add test cases for files, links, and file bind mounts (the latter will only
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
work when running as root). Split out a new test_path_is_mount_point() test
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
case function as it got significantly larger now.
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
(cherry picked from commit 5d409034017e9f9f8c4392157d95511fc2e05d87)
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
---
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
src/shared/path-util.c | 31 +++++++++++++------
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
src/shared/path-util.h | 2 +-
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
src/shared/rm-rf.c | 2 +-
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
src/test/test-path-util.c | 76 +++++++++++++++++++++++++++++++++++++++--------
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
4 files changed, 87 insertions(+), 24 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
diff --git a/src/shared/path-util.c b/src/shared/path-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
index 7090989fcb..8be479cd7f 100644
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
--- a/src/shared/path-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+++ b/src/shared/path-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
@@ -509,7 +509,7 @@ static int fd_fdinfo_mnt_id(int fd, const char *filename, int flags, int *mnt_id
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
return safe_atoi(p, mnt_id);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
-int fd_is_mount_point(int fd) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+int fd_is_mount_point(int fd, const char *filename, int flags) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
union file_handle_union h = FILE_HANDLE_INIT, h_parent = FILE_HANDLE_INIT;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
int mount_id = -1, mount_id_parent = -1;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
bool nosupp = false, check_st_dev = true;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
@@ -517,6 +517,7 @@ int fd_is_mount_point(int fd) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
int r;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
assert(fd >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert(filename);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
/* First we will try the name_to_handle_at() syscall, which
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
* tells us the mount id and an opaque file "handle". It is
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
@@ -541,7 +542,7 @@ int fd_is_mount_point(int fd) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
* subvolumes have different st_dev, even though they aren't
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
* real mounts of their own. */
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
- r = name_to_handle_at(fd, "", &h.handle, &mount_id, AT_EMPTY_PATH);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ r = name_to_handle_at(fd, filename, &h.handle, &mount_id, flags);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
if (r < 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
if (errno == ENOSYS)
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
/* This kernel does not support name_to_handle_at()
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
@@ -558,7 +559,7 @@ int fd_is_mount_point(int fd) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
return -errno;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
- r = name_to_handle_at(fd, "..", &h_parent.handle, &mount_id_parent, 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ r = name_to_handle_at(fd, "", &h_parent.handle, &mount_id_parent, AT_EMPTY_PATH);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
if (r < 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
if (errno == EOPNOTSUPP) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
if (nosupp)
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
@@ -593,13 +594,13 @@ int fd_is_mount_point(int fd) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
return mount_id != mount_id_parent;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
fallback_fdinfo:
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
- r = fd_fdinfo_mnt_id(fd, "", AT_EMPTY_PATH, &mount_id);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ r = fd_fdinfo_mnt_id(fd, filename, flags, &mount_id);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
if (r == -EOPNOTSUPP)
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
goto fallback_fstat;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
return r;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
- r = fd_fdinfo_mnt_id(fd, "..", 0, &mount_id_parent);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ r = fd_fdinfo_mnt_id(fd, "", AT_EMPTY_PATH, &mount_id_parent);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
return r;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
@@ -615,10 +616,16 @@ fallback_fdinfo:
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
check_st_dev = false;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
fallback_fstat:
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
- if (fstatat(fd, "", &a, AT_EMPTY_PATH) < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ /* yay for fstatat() taking a different set of flags than the other
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ * _at() above */
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ if (flags & AT_SYMLINK_FOLLOW)
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ flags &= ~AT_SYMLINK_FOLLOW;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ else
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ flags |= AT_SYMLINK_NOFOLLOW;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ if (fstatat(fd, filename, &a, flags) < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
return -errno;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
- if (fstatat(fd, "..", &b, 0) < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ if (fstatat(fd, "", &b, AT_EMPTY_PATH) < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
return -errno;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
/* A directory with same device and inode as its parent? Must
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
@@ -632,17 +639,23 @@ fallback_fstat:
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
int path_is_mount_point(const char *t, bool allow_symlink) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
_cleanup_close_ int fd = -1;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ _cleanup_free_ char *parent = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ int r;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
assert(t);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
if (path_equal(t, "/"))
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
return 1;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
- fd = openat(AT_FDCWD, t, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|(allow_symlink ? 0 : O_PATH));
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ r = path_get_parent(t, &parent);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ if (r < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ return r;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ fd = openat(AT_FDCWD, parent, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_PATH);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
if (fd < 0)
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
return -errno;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
- return fd_is_mount_point(fd);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ return fd_is_mount_point(fd, basename(t), (allow_symlink ? AT_SYMLINK_FOLLOW : 0));
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
int path_is_read_only_fs(const char *path) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
diff --git a/src/shared/path-util.h b/src/shared/path-util.h
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
index 4f45cfd2b7..38ad799ba0 100644
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
--- a/src/shared/path-util.h
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+++ b/src/shared/path-util.h
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
@@ -53,7 +53,7 @@ char** path_strv_make_absolute_cwd(char **l);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
char** path_strv_resolve(char **l, const char *prefix);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
char** path_strv_resolve_uniq(char **l, const char *prefix);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
-int fd_is_mount_point(int fd);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+int fd_is_mount_point(int fd, const char *filename, int flags);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
int path_is_mount_point(const char *path, bool allow_symlink);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
int path_is_read_only_fs(const char *path);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
int path_is_os_tree(const char *path);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
diff --git a/src/shared/rm-rf.c b/src/shared/rm-rf.c
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
index a89e8afc2a..bafd483be2 100644
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
--- a/src/shared/rm-rf.c
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+++ b/src/shared/rm-rf.c
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
@@ -103,7 +103,7 @@ int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
/* Stop at mount points */
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
- r = fd_is_mount_point(subdir_fd);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ r = fd_is_mount_point(fd, de->d_name, 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
if (r < 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
if (ret == 0 && r != -ENOENT)
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
ret = r;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
index 09f0f2f89e..80782ff902 100644
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
--- a/src/test/test-path-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+++ b/src/test/test-path-util.c
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
@@ -21,6 +21,7 @@
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
#include <stdio.h>
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
#include <unistd.h>
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+#include <sys/mount.h>
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
#include "path-util.h"
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
#include "util.h"
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
@@ -88,21 +89,9 @@ static void test_path(void) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
test_parent("/aa///file...", "/aa///");
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
test_parent("file.../", NULL);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
- assert_se(path_is_mount_point("/", true) > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
- assert_se(path_is_mount_point("/", false) > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
fd = open("/", O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOCTTY);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
assert_se(fd >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
- assert_se(fd_is_mount_point(fd) > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
- assert_se(path_is_mount_point("/proc", true) > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
- assert_se(path_is_mount_point("/proc", false) > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
- assert_se(path_is_mount_point("/proc/1", true) == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
- assert_se(path_is_mount_point("/proc/1", false) == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
-
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
- assert_se(path_is_mount_point("/sys", true) > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
- assert_se(path_is_mount_point("/sys", false) > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(fd_is_mount_point(fd, "/", 0) > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
{
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
char p1[] = "aaa/bbb////ccc";
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
@@ -322,6 +311,66 @@ static void test_prefix_root(void) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
test_prefix_root_one("/foo///", "//bar", "/foo/bar");
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
}
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+static void test_path_is_mount_point(void) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ int fd, rt, rf, rlt, rlf;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ char tmp_dir[] = "/tmp/test-path-is-mount-point-XXXXXX";
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ _cleanup_free_ char *file1 = NULL, *file2 = NULL, *link1 = NULL, *link2 = NULL;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(path_is_mount_point("/", true) > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(path_is_mount_point("/", false) > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(path_is_mount_point("/proc", true) > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(path_is_mount_point("/proc", false) > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(path_is_mount_point("/proc/1", true) == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(path_is_mount_point("/proc/1", false) == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(path_is_mount_point("/sys", true) > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(path_is_mount_point("/sys", false) > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ /* file mountpoints */
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(mkdtemp(tmp_dir) != NULL);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ file1 = path_join(NULL, tmp_dir, "file1");
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(file1);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ file2 = path_join(NULL, tmp_dir, "file2");
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(file2);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ fd = open(file1, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0664);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(fd > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ close(fd);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ fd = open(file2, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0664);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(fd > 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ close(fd);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ link1 = path_join(NULL, tmp_dir, "link1");
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(link1);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(symlink("file1", link1) == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ link2 = path_join(NULL, tmp_dir, "link2");
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(link1);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(symlink("file2", link2) == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(path_is_mount_point(file1, true) == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(path_is_mount_point(file1, false) == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(path_is_mount_point(link1, true) == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(path_is_mount_point(link1, false) == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ /* this test will only work as root */
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ if (mount(file1, file2, NULL, MS_BIND, NULL) >= 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ rf = path_is_mount_point(file2, false);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ rt = path_is_mount_point(file2, true);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ rlf = path_is_mount_point(link2, false);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ rlt = path_is_mount_point(link2, true);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(umount(file2) == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(rf == 1);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(rt == 1);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(rlf == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(rlt == 1);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ } else
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ printf("Skipping bind mount file test: %m\n");
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ assert_se(rm_rf(tmp_dir, REMOVE_ROOT|REMOVE_PHYSICAL) == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+}
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
int main(int argc, char **argv) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
test_path();
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
test_find_binary(argv[0], true);
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
@@ -333,6 +382,7 @@ int main(int argc, char **argv) {
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
test_strv_resolve();
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
test_path_startswith();
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
test_prefix_root();
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
+ test_path_is_mount_point();
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
return 0;
|
|
Zbigniew Jędrzejewski-Szmek |
436654 |
}
|