]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/landlock: Share enforce_ruleset() helper
authorKonstantin Meskhidze <konstantin.meskhidze@huawei.com>
Thu, 26 Oct 2023 01:47:48 +0000 (09:47 +0800)
committerMickaël Salaün <mic@digikod.net>
Thu, 26 Oct 2023 19:07:15 +0000 (21:07 +0200)
Move enforce_ruleset() helper function to common.h so that it can be
used both by filesystem tests and network ones.

Signed-off-by: Konstantin Meskhidze <konstantin.meskhidze@huawei.com>
Link: https://lore.kernel.org/r/20231026014751.414649-10-konstantin.meskhidze@huawei.com
Signed-off-by: Mickaël Salaün <mic@digikod.net>
tools/testing/selftests/landlock/common.h
tools/testing/selftests/landlock/fs_test.c

index d7987ae8d7fc519da3deba0618a74218b1b2c8a4..0fd6c4cf5e6f5649eeb6ed9dba7bcc99ede17f02 100644 (file)
@@ -256,3 +256,13 @@ static int __maybe_unused send_fd(int usock, int fd_tx)
                return -errno;
        return 0;
 }
+
+static void __maybe_unused
+enforce_ruleset(struct __test_metadata *const _metadata, const int ruleset_fd)
+{
+       ASSERT_EQ(0, prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0));
+       ASSERT_EQ(0, landlock_restrict_self(ruleset_fd, 0))
+       {
+               TH_LOG("Failed to enforce ruleset: %s", strerror(errno));
+       }
+}
index 251594306d4090f719de9f6c2155a892d16da686..68b7a89cf65b82cb2a8325f59b682d3a79b0f0d7 100644 (file)
@@ -677,16 +677,6 @@ static int create_ruleset(struct __test_metadata *const _metadata,
        return ruleset_fd;
 }
 
-static void enforce_ruleset(struct __test_metadata *const _metadata,
-                           const int ruleset_fd)
-{
-       ASSERT_EQ(0, prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0));
-       ASSERT_EQ(0, landlock_restrict_self(ruleset_fd, 0))
-       {
-               TH_LOG("Failed to enforce ruleset: %s", strerror(errno));
-       }
-}
-
 TEST_F_FORK(layout0, proc_nsfs)
 {
        const struct rule rules[] = {