]> git.cworth.org Git - fips/commitdiff
dlwrap: Don't resolve libfips_handle on every call to dlopen.
authorCarl Worth <cworth@cworth.org>
Wed, 12 Jun 2013 23:16:51 +0000 (16:16 -0700)
committerCarl Worth <cworth@cworth.org>
Wed, 12 Jun 2013 23:27:42 +0000 (16:27 -0700)
Instead, call dladdr and the real dlopen on the first call to dlopen
then save the libfips_handle result for all future calls.

dlwrap.c

index aac06f6eda22a663643bd49a0397a4700862a993..9f623da549b3e74c2db2a261caddbe95e9e00081 100644 (file)
--- a/dlwrap.c
+++ b/dlwrap.c
@@ -46,17 +46,23 @@ dlopen (const char *filename, int flag)
        if (STRNCMP_LITERAL (filename, "libGL.so"))
                return dlwrap_real_dlopen (filename, flag);
 
-       /* Redirect all dlopens to libGL to our own wrapper library.
-        * We find our own filename by looking up this very function
-        * (that is, this "dlopen"), with dladdr).*/
-       if (dladdr (dlopen, &info)) {
-               libfips_handle = dlwrap_real_dlopen (info.dli_fname, flag);
+       /* Otherwise, for all libGL lookups we redirectl dlopens to
+        * our own library. If we've resolved libfips_handle before,
+        * our work is done. */
+       if (libfips_handle)
                return libfips_handle;
-       } else {
+
+       /* We find our own filename by looking up this very function
+        * (that is, this "dlopen"), with dladdr).*/
+       if (dladdr (dlopen, &info) == 0) {
                fprintf (stderr, "Error: Failed to redirect dlopen of %s:\n",
                         filename);
                exit (1);
        }
+
+       libfips_handle = dlwrap_real_dlopen (info.dli_fname, flag);
+
+       return libfips_handle;
 }
 
 void *