]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
testsuite/path: defer dlsym() until needed
authorEmil Velikov <emil.l.velikov@gmail.com>
Sat, 24 May 2025 12:10:50 +0000 (13:10 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 29 May 2025 22:30:13 +0000 (17:30 -0500)
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 <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/355
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
testsuite/path.c

index bf9ade1b6d4e6555df7b92150bb2323c59d4c848..e6a9ef36e2bdaf634b5b6d5b9aca979317c71733 100644 (file)
@@ -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);                                              \
        }