Would this be something to add to APR ? Ability to do lazy/deferred loading as opposed to immediate bind.

I stumbled across this porting a small internal util which lets you load a single apache module; and lets you print the Magic Cookie, name and then the handle/command structure.

Dw.

Index: include/apr_dso.h
===================================================================
--- include/apr_dso.h   (revision 220266)
+++ include/apr_dso.h   (working copy)
@@ -53,13 +53,21 @@
  * @param res_handle Location to store new handle for the DSO.
  * @param path Path to the DSO library
  * @param ctx Pool to use.
- * @bug We aught to provide an alternative to RTLD_GLOBAL, which
- * is the only supported method of loading DSOs today.
  */
 APR_DECLARE(apr_status_t) apr_dso_load(apr_dso_handle_t **res_handle,
                                        const char *path, apr_pool_t *ctx);

+
 /**
+ * Load a DSO library without resolving the symbols (lazy)
+ * @param res_handle Location to store new handle for the DSO.
+ * @param path Path to the DSO library
+ * @param ctx Pool to use.
+ */
+APR_DECLARE(apr_status_t) apr_dso_load_lazy(apr_dso_handle_t **res_handle, + const char *path, apr_pool_t *ctx);
+
+/**
  * Close a DSO library.
  * @param handle handle to close.
  */
Index: dso/unix/dso.c
===================================================================
--- dso/unix/dso.c      (revision 355792)
+++ dso/unix/dso.c      (working copy)
@@ -18,6 +18,7 @@
 #include "apr_strings.h"
 #include "apr_portable.h"

+
 #if APR_HAS_DSO

 #if !defined(DSO_USE_DLFCN) && !defined(DSO_USE_SHL) && !defined(DSO_USE_DYLD)
@@ -38,6 +39,9 @@
 #define DYLD_LIBRARY_HANDLE (void *)-1
 #endif

+/* Not exposed on APR level */
+typedef enum { APR_DSO_LAZY, APR_DSO_NOW } apr_dso_loadtype;
+
 APR_DECLARE(apr_status_t) apr_os_dso_handle_put(apr_dso_handle_t **aprdso,
                                                 apr_os_dso_handle_t osdso,
                                                 apr_pool_t *pool)
@@ -77,11 +81,13 @@
     return APR_SUCCESS;
 }

-APR_DECLARE(apr_status_t) apr_dso_load(apr_dso_handle_t **res_handle, - const char *path, apr_pool_t *pool)
+
+static apr_status_t _dso_load(apr_dso_handle_t **res_handle, + const char *path, apr_pool_t *pool, apr, apr_dso_loadtype_t flag)
 {
 #if defined(DSO_USE_SHL)
-    shl_t os_handle = shl_load(path, BIND_IMMEDIATE, 0L);
+ shl_t os_handle = shl_load(path, + (flag == APR_DSO_LAZY) ? BIND_DEFERRED : BIND_IMMEDIATE, 0L);

 #elif defined(DSO_USE_DYLD)
     NSObjectFileImage image;
@@ -94,7 +100,7 @@
 #if defined(NSLINKMODULE_OPTION_RETURN_ON_ERROR) && 
defined(NSLINKMODULE_OPTION_NONE)
         os_handle = NSLinkModule(image, path,
                                  NSLINKMODULE_OPTION_RETURN_ON_ERROR |
-                                 NSLINKMODULE_OPTION_NONE);
+                                 (flag == APR_DSO_LAZY) ? 
NSLINKMODULE_OPTION_NONE : NSLINKMODULE_OPTION_BINDNOW);
         /* If something went wrong, get the errors... */
         if (!os_handle) {
             NSLinkEditErrors errors;
@@ -103,7 +109,7 @@
             NSLinkEditError(&errors, &errorNumber, &fileName, &err_msg);
         }
 #else
-        os_handle = NSLinkModule(image, path, FALSE);
+        os_handle = NSLinkModule(image, path, (flag == APR_DSO_NOW) ? FALSE : 
TRUE);
 #endif
         NSDestroyObjectFileImage(image);
     }
@@ -117,14 +123,19 @@
     }

 #elif defined(DSO_USE_DLFCN)
+    int flags = RTLD_GLOBAL;
+    void *os_handle;
+
+ if (flag == APR_DSO_LAZY) + flags |= RTLD_LAZY
+    else
+       flags |= RTLD_NOW;
+
 #if defined(OSF1) || defined(SEQUENT) || defined(SNI) ||\
     (defined(__FreeBSD_version) && (__FreeBSD_version >= 220000)) ||\
     defined(__DragonFly__)
-    void *os_handle = dlopen((char *)path, RTLD_NOW | RTLD_GLOBAL);
-
+    os_handle = dlopen((char *)path, flags);
 #else
-    int flags = RTLD_NOW | RTLD_GLOBAL;
-    void *os_handle;
 #ifdef _AIX
     if (strchr(path + 1, '(') && path[strlen(path) - 1] == ')')
     {
@@ -163,6 +174,18 @@

     return APR_SUCCESS;
 }
+
+APR_DECLARE(apr_status_t) apr_dso_lazy_load(apr_dso_handle_t **res_handle, + const char *path, apr_pool_t *pool)
+{
+       return _dso_load(res_handle, path, pool, APR_DSO_LAZY);
+}
+
+APR_DECLARE(apr_status_t) apr_dso_load(apr_dso_handle_t **res_handle, + const char *path, apr_pool_t *pool)
+{
+       return _dso_load(res_handle, path, pool, APR_DSO_NOW);
+}

 APR_DECLARE(apr_status_t) apr_dso_unload(apr_dso_handle_t *handle)
 {

Reply via email to