]> git.kaiwu.me - nginx.git/commitdiff
Dynamic modules: dlopen() support.
authorMaxim Dounin <mdounin@mdounin.ru>
Thu, 4 Feb 2016 15:30:21 +0000 (18:30 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Thu, 4 Feb 2016 15:30:21 +0000 (18:30 +0300)
13 files changed:
auto/lib/openssl/conf
auto/sources
auto/unix
src/core/ngx_core.h
src/os/unix/ngx_darwin_config.h
src/os/unix/ngx_dlopen.c [new file with mode: 0644]
src/os/unix/ngx_dlopen.h [new file with mode: 0644]
src/os/unix/ngx_freebsd_config.h
src/os/unix/ngx_linux_config.h
src/os/unix/ngx_posix_config.h
src/os/unix/ngx_solaris_config.h
src/os/win32/ngx_dlopen.c [new file with mode: 0644]
src/os/win32/ngx_dlopen.h [new file with mode: 0644]

index 28a99b203eda51e1352b7b299463ce0b630847bd..2187e5c6c96ae85621fba530acc1f2b33ec5742d 100644 (file)
@@ -32,7 +32,6 @@ if [ $OPENSSL != NONE ]; then
             CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
             CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
             CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
-            CORE_LIBS="$CORE_LIBS $NGX_LIBDL"
 
             if [ "$NGX_PLATFORM" = win32 ]; then
                 CORE_LIBS="$CORE_LIBS -lgdi32 -lcrypt32 -lws2_32"
@@ -106,7 +105,7 @@ else
         if [ $ngx_found = yes ]; then
             have=NGX_SSL . auto/have
             CORE_INCS="$CORE_INCS $ngx_feature_path"
-            CORE_LIBS="$CORE_LIBS $ngx_feature_libs $NGX_LIBDL"
+            CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
             OPENSSL=YES
         fi
     fi
index d325ec3fd2ac5fd8d6a325f004e65ce09de8e464..9ea9e09ac65e03a5936a36e05e6a7ec78ed894a4 100644 (file)
@@ -152,6 +152,7 @@ UNIX_DEPS="$CORE_DEPS $EVENT_DEPS \
             src/os/unix/ngx_socket.h \
             src/os/unix/ngx_os.h \
             src/os/unix/ngx_user.h \
+            src/os/unix/ngx_dlopen.h \
             src/os/unix/ngx_process_cycle.h"
 
 # add to UNIX_DEPS
@@ -183,6 +184,7 @@ UNIX_SRCS="$CORE_SRCS $EVENT_SRCS \
             src/os/unix/ngx_setproctitle.c \
             src/os/unix/ngx_posix_init.c \
             src/os/unix/ngx_user.c \
+            src/os/unix/ngx_dlopen.c \
             src/os/unix/ngx_process_cycle.c"
 
 POSIX_DEPS=src/os/unix/ngx_posix_config.h
@@ -228,6 +230,7 @@ WIN32_DEPS="$CORE_DEPS $EVENT_DEPS \
             src/os/win32/ngx_socket.h \
             src/os/win32/ngx_os.h \
             src/os/win32/ngx_user.h \
+            src/os/win32/ngx_dlopen.h \
             src/os/win32/ngx_process_cycle.h"
 
 WIN32_CONFIG=src/os/win32/ngx_win32_config.h
@@ -248,6 +251,7 @@ WIN32_SRCS="$CORE_SRCS $EVENT_SRCS \
             src/os/win32/ngx_wsasend_chain.c \
             src/os/win32/ngx_win32_init.c \
             src/os/win32/ngx_user.c \
+            src/os/win32/ngx_dlopen.c \
             src/os/win32/ngx_event_log.c \
             src/os/win32/ngx_process_cycle.c \
             src/event/ngx_event_acceptex.c"
index 7bfca8f3af14092744dd300d4c50947441b274a3..6ca63a61da982a5a2c19edb9fbfe05a3d4ae0766 100755 (executable)
--- a/auto/unix
+++ b/auto/unix
@@ -255,7 +255,7 @@ ngx_feature_test="struct statvfs  fs;
 
 
 ngx_feature="dlopen()"
-ngx_feature_name=
+ngx_feature_name="NGX_HAVE_DLOPEN"
 ngx_feature_run=no
 ngx_feature_incs="#include <dlfcn.h>"
 ngx_feature_path=
@@ -271,7 +271,7 @@ if [ $ngx_found != yes ]; then
     . auto/feature
 
     if [ $ngx_found = yes ]; then
-        NGX_LIBDL="-ldl"
+        CORE_LIBS="$CORE_LIBS -ldl"
     fi
 fi
 
index 2855a59c1b611f4d326508c5f62a75bfa813c311..2819c1a7d876a2785294bd170e138c60f4f6f4be 100644 (file)
@@ -53,6 +53,7 @@ typedef void (*ngx_connection_handler_pt)(ngx_connection_t *c);
 #include <ngx_shmem.h>
 #include <ngx_process.h>
 #include <ngx_user.h>
+#include <ngx_dlopen.h>
 #include <ngx_parse.h>
 #include <ngx_parse_time.h>
 #include <ngx_log.h>
index bbad977cb6cb9125dca473002b293b5cd514c667..cfe3ce223803063f46350082207ef47795f151ad 100644 (file)
@@ -48,6 +48,8 @@
 #include <sys/sysctl.h>
 #include <xlocale.h>
 
+#include <dlfcn.h>
+
 
 #ifndef IOV_MAX
 #define IOV_MAX   64
diff --git a/src/os/unix/ngx_dlopen.c b/src/os/unix/ngx_dlopen.c
new file mode 100644 (file)
index 0000000..a0efc69
--- /dev/null
@@ -0,0 +1,28 @@
+
+/*
+ * Copyright (C) Maxim Dounin
+ * Copyright (C) Nginx, Inc.
+ */
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+#if (NGX_HAVE_DLOPEN)
+
+char *
+ngx_dlerror(void)
+{
+    char  *err;
+
+    err = (char *) dlerror();
+
+    if (err == NULL) {
+        return "";
+    }
+
+    return err;
+}
+
+#endif
diff --git a/src/os/unix/ngx_dlopen.h b/src/os/unix/ngx_dlopen.h
new file mode 100644 (file)
index 0000000..7a3159f
--- /dev/null
@@ -0,0 +1,31 @@
+
+/*
+ * Copyright (C) Maxim Dounin
+ * Copyright (C) Nginx, Inc.
+ */
+
+
+#ifndef _NGX_DLOPEN_H_INCLUDED_
+#define _NGX_DLOPEN_H_INCLUDED_
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+#define ngx_dlopen(path)           dlopen((char *) path, RTLD_NOW | RTLD_GLOBAL)
+#define ngx_dlopen_n               "dlopen()"
+
+#define ngx_dlsym(handle, symbol)  dlsym(handle, symbol)
+#define ngx_dlsym_n                "dlsym()"
+
+#define ngx_dlclose(handle)        dlclose(handle)
+#define ngx_dlclose_n              "dlclose()"
+
+
+#if (NGX_HAVE_DLOPEN)
+char *ngx_dlerror(void);
+#endif
+
+
+#endif /* _NGX_DLOPEN_H_INCLUDED_ */
index 9a25788750c578125e34ccfb17f0eeae83d669ba..b7da48cb10e1437473fcacb8589dc5386abacacb 100644 (file)
@@ -49,6 +49,8 @@
 #include <osreldate.h>
 #include <sys/sysctl.h>
 
+#include <dlfcn.h>
+
 
 #if __FreeBSD_version < 400017
 
index 162a992c990b33f9932a529c53c9312dd48ed41a..2f6129d8894e95b33371e28b7c4ee7ab8ed4a873 100644 (file)
@@ -55,6 +55,8 @@
 #include <crypt.h>
 #include <sys/utsname.h>        /* uname() */
 
+#include <dlfcn.h>
+
 
 #include <ngx_auto_config.h>
 
index 443c4b001261212c5f1a10bccbd42bb936119ec2..bf75997f629cc26a2ae01d92a1278a59bb392de8 100644 (file)
 #include <ngx_auto_config.h>
 
 
+#if (NGX_HAVE_DLOPEN)
+#include <dlfcn.h>
+#endif
+
+
 #if (NGX_HAVE_POSIX_SEM)
 #include <semaphore.h>
 #endif
index ddfd984577ea0bacdb9cc870566554c67b25ca2d..ffa01c8b72de28d4e472d029479ea2fb5e63e111 100644 (file)
@@ -55,6 +55,8 @@
 #include <inttypes.h>
 #include <crypt.h>
 
+#include <dlfcn.h>
+
 #define NGX_ALIGNMENT  _MAX_ALIGNMENT
 
 #include <ngx_auto_config.h>
diff --git a/src/os/win32/ngx_dlopen.c b/src/os/win32/ngx_dlopen.c
new file mode 100644 (file)
index 0000000..804f49d
--- /dev/null
@@ -0,0 +1,22 @@
+
+/*
+ * Copyright (C) Maxim Dounin
+ * Copyright (C) Nginx, Inc.
+ */
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+char *
+ngx_dlerror(void)
+{
+    u_char         *p;
+    static u_char   errstr[NGX_MAX_ERROR_STR];
+
+    p = ngx_strerror(ngx_errno, errstr, NGX_MAX_ERROR_STR);
+    *p = '\0';
+
+    return (char *) errstr;
+}
diff --git a/src/os/win32/ngx_dlopen.h b/src/os/win32/ngx_dlopen.h
new file mode 100644 (file)
index 0000000..0d6b405
--- /dev/null
@@ -0,0 +1,32 @@
+
+/*
+ * Copyright (C) Maxim Dounin
+ * Copyright (C) Nginx, Inc.
+ */
+
+
+#ifndef _NGX_DLOPEN_H_INCLUDED_
+#define _NGX_DLOPEN_H_INCLUDED_
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+#define NGX_HAVE_DLOPEN  1
+
+
+#define ngx_dlopen(path)           LoadLibrary((char *) path)
+#define ngx_dlopen_n               "LoadLibrary()"
+
+#define ngx_dlsym(handle, symbol)  (void *) GetProcAddress(handle, symbol)
+#define ngx_dlsym_n                "GetProcAddress()"
+
+#define ngx_dlclose(handle)        (FreeLibrary(handle) ? 0 : -1)
+#define ngx_dlclose_n              "FreeLibrary()"
+
+
+char *ngx_dlerror(void);
+
+
+#endif /* _NGX_DLOPEN_H_INCLUDED_ */