summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-11-07 19:56:46 +0100
committerLennart Poettering <lennart@poettering.net>2024-11-08 13:25:17 +0100
commit5261c521e3a98932241f36e91cf6f7823c578aca (patch)
tree8ae2fd5cc093fe60cd1fd08de9fb5d7be24b3855 /src/test
parenttest: install integration-test-setup.sh in testdata/ (diff)
downloadsystemd-5261c521e3a98932241f36e91cf6f7823c578aca.tar.xz
systemd-5261c521e3a98932241f36e91cf6f7823c578aca.zip
mount-util: make path_get_mount_info() work arbitrary inode
Follow-up for d49d95df0a260aaca9a3fdd1e6ce535592a53bca. Replaces 9a032ec55a9820a0424309670fe551c99203e5f1. Fixes #35075.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-mount-util.c50
1 files changed, 47 insertions, 3 deletions
diff --git a/src/test/test-mount-util.c b/src/test/test-mount-util.c
index 469aa35913..4ac8f869d6 100644
--- a/src/test/test-mount-util.c
+++ b/src/test/test-mount-util.c
@@ -538,9 +538,53 @@ TEST(bind_mount_submounts) {
}
TEST(path_is_network_fs_harder) {
- ASSERT_OK_ZERO(path_is_network_fs_harder("/dev"));
- ASSERT_OK_ZERO(path_is_network_fs_harder("/sys"));
- ASSERT_OK_ZERO(path_is_network_fs_harder("/run"));
+ _cleanup_close_ int dir_fd = -EBADF;
+ int r;
+
+ ASSERT_OK(dir_fd = open("/", O_PATH | O_CLOEXEC));
+ FOREACH_STRING(s,
+ "/", "/dev/", "/proc/", "/run/", "/sys/", "/tmp/", "/usr/", "/var/tmp/",
+ "", ".", "../../../", "/this/path/should/not/exist/for/test-mount-util/") {
+
+ r = path_is_network_fs_harder(s);
+ log_debug("path_is_network_fs_harder(%s) → %i: %s", s, r, r < 0 ? STRERROR(r) : yes_no(r));
+
+ const char *q = path_startswith(s, "/") ?: s;
+ r = path_is_network_fs_harder_at(dir_fd, q);
+ log_debug("path_is_network_fs_harder_at(root, %s) → %i: %s", q, r, r < 0 ? STRERROR(r) : yes_no(r));
+ }
+
+ if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) {
+ (void) log_tests_skipped("not running privileged");
+ return;
+ }
+
+ _cleanup_(rm_rf_physical_and_freep) char *t = NULL;
+ assert_se(mkdtemp_malloc("/tmp/test-mount-util.path_is_network_fs_harder.XXXXXXX", &t) >= 0);
+
+ r = safe_fork("(make_mount-point)",
+ FORK_RESET_SIGNALS |
+ FORK_CLOSE_ALL_FDS |
+ FORK_DEATHSIG_SIGTERM |
+ FORK_WAIT |
+ FORK_REOPEN_LOG |
+ FORK_LOG |
+ FORK_NEW_MOUNTNS |
+ FORK_MOUNTNS_SLAVE,
+ NULL);
+ ASSERT_OK(r);
+
+ if (r == 0) {
+ ASSERT_OK(mount_nofollow_verbose(LOG_INFO, "tmpfs", t, "tmpfs", 0, NULL));
+ ASSERT_OK_ZERO(path_is_network_fs_harder(t));
+ ASSERT_OK_ERRNO(umount(t));
+
+ ASSERT_OK(mount_nofollow_verbose(LOG_INFO, "tmpfs", t, "tmpfs", 0, "x-systemd-growfs,x-systemd-automount"));
+ ASSERT_OK_ZERO(path_is_network_fs_harder(t));
+ ASSERT_OK_ERRNO(umount(t));
+
+ _exit(EXIT_SUCCESS);
+ }
}
DEFINE_TEST_MAIN(LOG_DEBUG);