fs-util: make sure open_mkdir_at() does something roughly sensible when invoked with '/'

This commit is contained in:
Lennart Poettering
2023-04-25 18:38:00 +09:00
committed by Yu Watanabe
parent 3d008416d6
commit 797f6cc514
2 changed files with 24 additions and 13 deletions
+17
View File
@@ -548,6 +548,23 @@ TEST(parse_cifs_service) {
TEST(open_mkdir_at) {
_cleanup_close_ int fd = -EBADF, subdir_fd = -EBADF, subsubdir_fd = -EBADF;
_cleanup_(rm_rf_physical_and_freep) char *t = NULL;
struct stat sta, stb;
assert_se(open_mkdir_at(AT_FDCWD, "/", O_EXCL|O_CLOEXEC, 0) == -EEXIST);
assert_se(open_mkdir_at(AT_FDCWD, ".", O_EXCL|O_CLOEXEC, 0) == -EEXIST);
fd = open_mkdir_at(AT_FDCWD, "/", O_CLOEXEC, 0);
assert_se(fd >= 0);
assert_se(stat("/", &sta) >= 0);
assert_se(fstat(fd, &stb) >= 0);
assert_se(stat_inode_same(&sta, &stb));
fd = safe_close(fd);
fd = open_mkdir_at(AT_FDCWD, ".", O_CLOEXEC, 0);
assert_se(stat(".", &sta) >= 0);
assert_se(fstat(fd, &stb) >= 0);
assert_se(stat_inode_same(&sta, &stb));
fd = safe_close(fd);
assert_se(open_mkdir_at(AT_FDCWD, "/proc", O_EXCL|O_CLOEXEC, 0) == -EEXIST);