From aedcfbab7425ea09acbe96a7120d714289fa4a1a Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sat, 24 May 2025 13:02:48 +0100 Subject: [PATCH] testsuite/path: cache the old dlsym() results There is no need for us to repeatedly fetch the respective symbols. Based on the static storage of _fn, this must have been the goal since day 1. Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/355 Signed-off-by: Lucas De Marchi --- testsuite/path.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/testsuite/path.c b/testsuite/path.c index 06060b85..bf9ade1b 100644 --- a/testsuite/path.c +++ b/testsuite/path.c @@ -103,7 +103,8 @@ static void *get_libc_func(const char *f) \ if (!get_rootpath(__func__)) \ return failret; \ - _fn = get_libc_func(#name); \ + if (_fn == NULL) \ + _fn = get_libc_func(#name); \ p = trap_path(path, buf); \ if (p == NULL) \ return failret; \ @@ -120,7 +121,8 @@ static void *get_libc_func(const char *f) \ if (!get_rootpath(__func__)) \ return failret; \ - _fn = get_libc_func(#name); \ + if (_fn == NULL) \ + _fn = get_libc_func(#name); \ p = trap_path(path, buf); \ if (p == NULL) \ return failret; \ @@ -137,7 +139,8 @@ static void *get_libc_func(const char *f) \ if (!get_rootpath(__func__)) \ return -1; \ - _fn = get_libc_func("open" #suffix); \ + if (_fn == NULL) \ + _fn = get_libc_func("open" #suffix); \ p = trap_path(path, buf); \ if (p == NULL) \ return -1; \ @@ -162,7 +165,8 @@ static void *get_libc_func(const char *f) const char *p; \ char buf[PATH_MAX * 2]; \ static int (*_fn)(int ver, const char *path, struct stat##suffix *); \ - _fn = get_libc_func(#prefix "stat" #suffix); \ + if (_fn == NULL) \ + _fn = get_libc_func(#prefix "stat" #suffix); \ \ if (!get_rootpath(__func__)) \ return -1; \ -- 2.47.3