aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coreutils/test.c21
-rw-r--r--include/libbb.h1
-rw-r--r--shell/ash.c3
3 files changed, 19 insertions, 6 deletions
diff --git a/coreutils/test.c b/coreutils/test.c
index 96462d3a2..ad777953f 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -426,7 +426,7 @@ struct test_statics {
426 /* set only by check_operator(), either to bogus struct 426 /* set only by check_operator(), either to bogus struct
427 * or points to matching operator_t struct. Never NULL. */ 427 * or points to matching operator_t struct. Never NULL. */
428 const struct operator_t *last_operator; 428 const struct operator_t *last_operator;
429 struct cached_groupinfo groupinfo; 429 struct cached_groupinfo *groupinfo;
430#if BASH_TEST2 430#if BASH_TEST2
431 bool bash_test2; 431 bool bash_test2;
432#endif 432#endif
@@ -447,7 +447,6 @@ extern struct test_statics *BB_GLOBAL_CONST test_ptr_to_statics;
447 XZALLOC_CONST_PTR(&test_ptr_to_statics, sizeof(S)); \ 447 XZALLOC_CONST_PTR(&test_ptr_to_statics, sizeof(S)); \
448} while (0) 448} while (0)
449#define DEINIT_S() do { \ 449#define DEINIT_S() do { \
450 free(groupinfo.supplementary_array); \
451 free(test_ptr_to_statics); \ 450 free(test_ptr_to_statics); \
452} while (0) 451} while (0)
453 452
@@ -642,7 +641,7 @@ static int is_a_group_member(gid_t gid)
642 if (gid == getgid() || gid == getegid()) 641 if (gid == getgid() || gid == getegid())
643 return 1; 642 return 1;
644 643
645 return is_in_supplementary_groups(&groupinfo, gid); 644 return is_in_supplementary_groups(groupinfo, gid);
646} 645}
647 646
648/* 647/*
@@ -878,7 +877,7 @@ static number_t primary(enum token n)
878} 877}
879 878
880 879
881int test_main(int argc, char **argv) 880int FAST_FUNC test_main2(struct cached_groupinfo *pgroupinfo, int argc, char **argv)
882{ 881{
883 int res; 882 int res;
884 const char *arg0; 883 const char *arg0;
@@ -911,6 +910,7 @@ int test_main(int argc, char **argv)
911 910
912 /* We must do DEINIT_S() prior to returning */ 911 /* We must do DEINIT_S() prior to returning */
913 INIT_S(); 912 INIT_S();
913 groupinfo = pgroupinfo;
914 914
915#if BASH_TEST2 915#if BASH_TEST2
916 bash_test2 = bt2; 916 bash_test2 = bt2;
@@ -1013,3 +1013,16 @@ int test_main(int argc, char **argv)
1013 DEINIT_S(); 1013 DEINIT_S();
1014 return res; 1014 return res;
1015} 1015}
1016
1017int test_main(int argc, char **argv)
1018{
1019 struct cached_groupinfo info;
1020 int r;
1021
1022 info.ngroups = 0;
1023 info.supplementary_array = NULL;
1024 r = test_main2(&info, argc, argv);
1025 free(info.supplementary_array);
1026
1027 return r;
1028}
diff --git a/include/libbb.h b/include/libbb.h
index 99bbf623b..8748464ed 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1550,6 +1550,7 @@ int test_main(int argc, char **argv)
1550 MAIN_EXTERNALLY_VISIBLE 1550 MAIN_EXTERNALLY_VISIBLE
1551#endif 1551#endif
1552; 1552;
1553int FAST_FUNC test_main2(struct cached_groupinfo *pgroupinfo, int argc, char **argv);
1553int kill_main(int argc, char **argv) 1554int kill_main(int argc, char **argv)
1554#if ENABLE_KILL || ENABLE_KILLALL || ENABLE_KILLALL5 1555#if ENABLE_KILL || ENABLE_KILLALL || ENABLE_KILLALL5
1555 MAIN_EXTERNALLY_VISIBLE 1556 MAIN_EXTERNALLY_VISIBLE
diff --git a/shell/ash.c b/shell/ash.c
index fa57511a7..a6bb9894c 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -10175,8 +10175,7 @@ static int FAST_FUNC echocmd(int argc, char **argv) { return echo_main(argc, a
10175static int FAST_FUNC printfcmd(int argc, char **argv) { return printf_main(argc, argv); } 10175static int FAST_FUNC printfcmd(int argc, char **argv) { return printf_main(argc, argv); }
10176#endif 10176#endif
10177#if ENABLE_ASH_TEST || BASH_TEST2 10177#if ENABLE_ASH_TEST || BASH_TEST2
10178static int FAST_FUNC testcmd(int argc, char **argv) { return test_main(argc, argv); } 10178static int FAST_FUNC testcmd(int argc, char **argv) { return test_main2(&groupinfo, argc, argv); }
10179// TODO: pass &ngroups and &group_array addresses to test_main to use cached supplementary groups
10180#endif 10179#endif
10181#if ENABLE_ASH_SLEEP 10180#if ENABLE_ASH_SLEEP
10182static int FAST_FUNC sleepcmd(int argc, char **argv) { return sleep_main(argc, argv); } 10181static int FAST_FUNC sleepcmd(int argc, char **argv) { return sleep_main(argc, argv); }