From d26e9587252fdf4774a05e351b86d3a18c46384e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 7 Oct 2024 07:14:27 +0200 Subject: ash: make "test -x" use cached groupinfo function old new delta test_main2 - 407 +407 testcmd 10 23 +13 test_main 418 56 -362 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/1 up/down: 420/-362) Total: 58 bytes Signed-off-by: Denys Vlasenko --- coreutils/test.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'coreutils/test.c') 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 { /* set only by check_operator(), either to bogus struct * or points to matching operator_t struct. Never NULL. */ const struct operator_t *last_operator; - struct cached_groupinfo groupinfo; + struct cached_groupinfo *groupinfo; #if BASH_TEST2 bool bash_test2; #endif @@ -447,7 +447,6 @@ extern struct test_statics *BB_GLOBAL_CONST test_ptr_to_statics; XZALLOC_CONST_PTR(&test_ptr_to_statics, sizeof(S)); \ } while (0) #define DEINIT_S() do { \ - free(groupinfo.supplementary_array); \ free(test_ptr_to_statics); \ } while (0) @@ -642,7 +641,7 @@ static int is_a_group_member(gid_t gid) if (gid == getgid() || gid == getegid()) return 1; - return is_in_supplementary_groups(&groupinfo, gid); + return is_in_supplementary_groups(groupinfo, gid); } /* @@ -878,7 +877,7 @@ static number_t primary(enum token n) } -int test_main(int argc, char **argv) +int FAST_FUNC test_main2(struct cached_groupinfo *pgroupinfo, int argc, char **argv) { int res; const char *arg0; @@ -911,6 +910,7 @@ int test_main(int argc, char **argv) /* We must do DEINIT_S() prior to returning */ INIT_S(); + groupinfo = pgroupinfo; #if BASH_TEST2 bash_test2 = bt2; @@ -1013,3 +1013,16 @@ int test_main(int argc, char **argv) DEINIT_S(); return res; } + +int test_main(int argc, char **argv) +{ + struct cached_groupinfo info; + int r; + + info.ngroups = 0; + info.supplementary_array = NULL; + r = test_main2(&info, argc, argv); + free(info.supplementary_array); + + return r; +} -- cgit v1.2.3-55-g6feb