diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2024-10-07 07:14:27 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2024-10-07 07:14:27 +0200 |
commit | d26e9587252fdf4774a05e351b86d3a18c46384e (patch) | |
tree | 9ac2ac9a1c1b642f4bcf9899339f9072b78a0b32 /coreutils/test.c | |
parent | 4c1d645c86f4e7a380d96f9ba962f8b270f595dc (diff) | |
download | busybox-w32-d26e9587252fdf4774a05e351b86d3a18c46384e.tar.gz busybox-w32-d26e9587252fdf4774a05e351b86d3a18c46384e.tar.bz2 busybox-w32-d26e9587252fdf4774a05e351b86d3a18c46384e.zip |
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 <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils/test.c')
-rw-r--r-- | coreutils/test.c | 21 |
1 files changed, 17 insertions, 4 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 | ||
881 | int test_main(int argc, char **argv) | 880 | int 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 | |||
1017 | int 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 | } | ||