mountpoint-util: make path_get_mnt_id_at() work with a NULL path

This commit is contained in:
Lennart Poettering
2023-04-25 14:00:38 +02:00
parent 9203abf79f
commit c8ab89e569
2 changed files with 49 additions and 3 deletions
+47
View File
@@ -366,6 +366,53 @@ TEST(fstype_can_umask) {
assert_se(!fstype_can_umask("tmpfs"));
}
TEST(path_get_mnt_id_at_null) {
_cleanup_close_ int root_fd = -EBADF, run_fd = -EBADF;
int id1, id2;
assert_se(path_get_mnt_id_at(AT_FDCWD, "/run/", &id1) >= 0);
assert_se(id1 > 0);
assert_se(path_get_mnt_id_at(AT_FDCWD, "/run", &id2) >= 0);
assert_se(id1 == id2);
id2 = -1;
root_fd = open("/", O_DIRECTORY|O_CLOEXEC);
assert_se(root_fd >= 0);
assert_se(path_get_mnt_id_at(root_fd, "/run/", &id2) >= 0);
assert_se(id1 = id2);
id2 = -1;
assert_se(path_get_mnt_id_at(root_fd, "/run", &id2) >= 0);
assert_se(id1 = id2);
id2 = -1;
assert_se(path_get_mnt_id_at(root_fd, "run", &id2) >= 0);
assert_se(id1 = id2);
id2 = -1;
assert_se(path_get_mnt_id_at(root_fd, "run/", &id2) >= 0);
assert_se(id1 = id2);
id2 = -1;
run_fd = openat(root_fd, "run", O_DIRECTORY|O_CLOEXEC);
assert_se(run_fd >= 0);
id2 = -1;
assert_se(path_get_mnt_id_at(run_fd, "", &id2) >= 0);
assert_se(id1 = id2);
id2 = -1;
assert_se(path_get_mnt_id_at(run_fd, NULL, &id2) >= 0);
assert_se(id1 = id2);
id2 = -1;
assert_se(path_get_mnt_id_at(run_fd, ".", &id2) >= 0);
assert_se(id1 = id2);
id2 = -1;
}
static int intro(void) {
/* let's move into our own mount namespace with all propagation from the host turned off, so
* that /proc/self/mountinfo is static and constant for the whole time our test runs. */