Skip to content

Commit a3f1629

Browse files
committed
selftests/landlock: Clean up error logs related to capabilities
It doesn't help to call TH_LOG() for every cap_*() error. Let's only log errors returned by the kernel, not by libcap specificities. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mickaël Salaün <[email protected]>
1 parent d9818b3 commit a3f1629

File tree

1 file changed

+9
-30
lines changed
  • tools/testing/selftests/landlock

1 file changed

+9
-30
lines changed

tools/testing/selftests/landlock/common.h

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -128,31 +128,19 @@ static void _init_caps(struct __test_metadata *const _metadata, bool drop_all)
128128
EXPECT_EQ(0, cap_set_secbits(noroot));
129129

130130
cap_p = cap_get_proc();
131-
EXPECT_NE(NULL, cap_p)
132-
{
133-
TH_LOG("Failed to cap_get_proc: %s", strerror(errno));
134-
}
135-
EXPECT_NE(-1, cap_clear(cap_p))
136-
{
137-
TH_LOG("Failed to cap_clear: %s", strerror(errno));
138-
}
131+
EXPECT_NE(NULL, cap_p);
132+
EXPECT_NE(-1, cap_clear(cap_p));
139133
if (!drop_all) {
140134
EXPECT_NE(-1, cap_set_flag(cap_p, CAP_PERMITTED,
141-
ARRAY_SIZE(caps), caps, CAP_SET))
142-
{
143-
TH_LOG("Failed to cap_set_flag: %s", strerror(errno));
144-
}
135+
ARRAY_SIZE(caps), caps, CAP_SET));
145136
}
146137

147138
/* Automatically resets ambient capabilities. */
148139
EXPECT_NE(-1, cap_set_proc(cap_p))
149140
{
150-
TH_LOG("Failed to cap_set_proc: %s", strerror(errno));
151-
}
152-
EXPECT_NE(-1, cap_free(cap_p))
153-
{
154-
TH_LOG("Failed to cap_free: %s", strerror(errno));
141+
TH_LOG("Failed to set capabilities: %s", strerror(errno));
155142
}
143+
EXPECT_NE(-1, cap_free(cap_p));
156144

157145
/* Quickly checks that ambient capabilities are cleared. */
158146
EXPECT_NE(-1, cap_get_ambient(caps[0]));
@@ -176,22 +164,13 @@ static void _change_cap(struct __test_metadata *const _metadata,
176164
cap_t cap_p;
177165

178166
cap_p = cap_get_proc();
179-
EXPECT_NE(NULL, cap_p)
180-
{
181-
TH_LOG("Failed to cap_get_proc: %s", strerror(errno));
182-
}
183-
EXPECT_NE(-1, cap_set_flag(cap_p, flag, 1, &cap, value))
184-
{
185-
TH_LOG("Failed to cap_set_flag: %s", strerror(errno));
186-
}
167+
EXPECT_NE(NULL, cap_p);
168+
EXPECT_NE(-1, cap_set_flag(cap_p, flag, 1, &cap, value));
187169
EXPECT_NE(-1, cap_set_proc(cap_p))
188170
{
189-
TH_LOG("Failed to cap_set_proc: %s", strerror(errno));
190-
}
191-
EXPECT_NE(-1, cap_free(cap_p))
192-
{
193-
TH_LOG("Failed to cap_free: %s", strerror(errno));
171+
TH_LOG("Failed to set capability %d: %s", cap, strerror(errno));
194172
}
173+
EXPECT_NE(-1, cap_free(cap_p));
195174
}
196175

197176
static void __maybe_unused set_cap(struct __test_metadata *const _metadata,

0 commit comments

Comments
 (0)