summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-04-20 18:44:21 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-04-25 11:38:00 +0200
commit797f6cc514b86097f0a51286b9f3ce568c03bf76 (patch)
tree232a760f3c6474700a7370af97bd7163215c6fc3 /src/test
parentMerge pull request #27380 from poettering/bpf-meson-tweaks (diff)
downloadsystemd-797f6cc514b86097f0a51286b9f3ce568c03bf76.tar.xz
systemd-797f6cc514b86097f0a51286b9f3ce568c03bf76.zip
fs-util: make sure open_mkdir_at() does something roughly sensible when invoked with '/'
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-fs-util.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c
index 9e3fbdd28f..fa33b807b2 100644
--- a/src/test/test-fs-util.c
+++ b/src/test/test-fs-util.c
@@ -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);