[LTP] [PATCH] setgroups03: Fix running more iterations (-i 2)
Zhao Gongyi
zhaogongyi@huawei.com
Sat Sep 25 19:47:03 CEST 2021
When run the test with option "-i 2", test will fail and
report "setgroups03.c:157: setgroups(65537) fails, Size
is > sysconf(_SC_NGROUPS_MAX), errno=1, expected errno=22".
Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
.../kernel/syscalls/setgroups/setgroups03.c | 24 ++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/testcases/kernel/syscalls/setgroups/setgroups03.c b/testcases/kernel/syscalls/setgroups/setgroups03.c
index 490b06996..3ddea5635 100644
--- a/testcases/kernel/syscalls/setgroups/setgroups03.c
+++ b/testcases/kernel/syscalls/setgroups/setgroups03.c
@@ -88,6 +88,7 @@ GID_T *groups_list; /* Array to hold gids for getgroups() */
int setup1(); /* setup function to test error EPERM */
void setup(); /* setup function for the test */
+void cleanup1(); /* cleanup function for setup1 */
void cleanup(); /* cleanup function for the test */
struct test_case_t { /* test case struct. to hold ref. test cond's */
@@ -156,6 +157,9 @@ int main(int ac, char **av)
gidsetsize, test_desc, TEST_ERRNO,
Test_cases[i].exp_errno);
}
+ if (Test_cases[i].setupfunc != NULL) {
+ cleanup1();
+ }
}
}
@@ -191,7 +195,7 @@ int setup1(void)
{
struct passwd *user_info; /* struct. to hold test user info */
-/* Switch to nobody user for correct error code collection */
+ /* Switch to nobody user for correct error code collection */
ltpuser = getpwnam(nobody_uid);
if (seteuid(ltpuser->pw_uid) == -1) {
tst_resm(TINFO, "setreuid failed to "
@@ -212,6 +216,24 @@ int setup1(void)
return 0;
}
+void cleanup1(void)
+{
+ struct passwd *user_info;
+ if (seteuid(0) < 0)
+ tst_brkm(TBROK, cleanup, "seteuid failed");
+
+ if ((user_info = getpwnam("root")) == NULL)
+ tst_brkm(TBROK, cleanup, "getpwnam(2) of root Failed");
+
+ if (!GID_SIZE_CHECK(user_info->pw_gid)) {
+ tst_brkm(TBROK,
+ cleanup,
+ "gid returned from getpwnam is too large for testing setgroups16");
+ }
+
+ groups_list[0] = user_info->pw_gid;
+}
+
/*
* cleanup() - performs all ONE TIME cleanup for this test at
* completion or premature exit.
--
2.17.1
More information about the ltp
mailing list