From: Emil Velikov Date: Sat, 24 May 2025 12:10:50 +0000 (+0100) Subject: testsuite/path: defer dlsym() until needed X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=90d010b7ea55e2a0ac0314328de0c51cf1b21ec2;p=thirdparty%2Fkmod.git testsuite/path: defer dlsym() until needed There is no point in fetching the symbol if we already know we don't need it. Defer the get_libc_func() after get_rootpath() and trap_path(). Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/355 Signed-off-by: Lucas De Marchi --- diff --git a/testsuite/path.c b/testsuite/path.c index bf9ade1b..e6a9ef36 100644 --- a/testsuite/path.c +++ b/testsuite/path.c @@ -103,11 +103,12 @@ static void *get_libc_func(const char *f) \ if (!get_rootpath(__func__)) \ return failret; \ - if (_fn == NULL) \ - _fn = get_libc_func(#name); \ p = trap_path(path, buf); \ if (p == NULL) \ return failret; \ + \ + if (_fn == NULL) \ + _fn = get_libc_func(#name); \ return (*_fn)(p); \ } @@ -121,11 +122,12 @@ static void *get_libc_func(const char *f) \ if (!get_rootpath(__func__)) \ return failret; \ - if (_fn == NULL) \ - _fn = get_libc_func(#name); \ p = trap_path(path, buf); \ if (p == NULL) \ return failret; \ + \ + if (_fn == NULL) \ + _fn = get_libc_func(#name); \ return (*_fn)(p, arg2); \ } @@ -139,12 +141,12 @@ static void *get_libc_func(const char *f) \ if (!get_rootpath(__func__)) \ return -1; \ - if (_fn == NULL) \ - _fn = get_libc_func("open" #suffix); \ p = trap_path(path, buf); \ if (p == NULL) \ return -1; \ \ + if (_fn == NULL) \ + _fn = get_libc_func("open" #suffix); \ if (flags & O_CREAT) { \ mode_t mode; \ va_list ap; \ @@ -165,8 +167,6 @@ 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 *); \ - if (_fn == NULL) \ - _fn = get_libc_func(#prefix "stat" #suffix); \ \ if (!get_rootpath(__func__)) \ return -1; \ @@ -174,6 +174,8 @@ static void *get_libc_func(const char *f) if (p == NULL) \ return -1; \ \ + if (_fn == NULL) \ + _fn = get_libc_func(#prefix "stat" #suffix); \ return _fn(ver, p, st); \ }