[PATCH 1/5] selftests/landlock: fix return condition on create_directory

Jeffrey Bencteux
2026-04-12T10:08:39Z

If path exists when calling create_directory() in tests, i-e. when
mkdir() return with EEXISTS, directory creation fails. This patch
fixes it by allowing create_directory to use eventual existing
directories.

Signed-off-by: Jeffrey Bencteux <jeff@bencteux.fr>
---
tools/testing/selftests/landlock/fs_test.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
index 968a91c927a4..e5898dc7e53e 100644
--- a/tools/testing/selftests/landlock/fs_test.c
+++ b/tools/testing/selftests/landlock/fs_test.c
@@ -218,8 +218,11 @@ static void mkdir_parents(struct __test_metadata *const _metadata,
static void create_directory(struct __test_metadata *const _metadata,
const char *const path)
{
+ int err;
+
mkdir_parents(_metadata, path);
- ASSERT_EQ(0, mkdir(path, 0700))
+ err = mkdir(path, 0700);
+ ASSERT_FALSE(err && errno != EEXIST)
{
TH_LOG("Failed to create directory \"%s\": %s", path,
strerror(errno));

base-commit: 82544d36b1729153c8aeb179e84750f0c085d3b1
--
2.53.0