Dynamic modules: dlopen() support.

This commit is contained in:
Maxim Dounin
2016-02-04 18:30:21 +03:00
parent 0f67d6355c
commit 86cc342a26
13 changed files with 134 additions and 4 deletions

View File

@@ -48,6 +48,8 @@
#include <sys/sysctl.h>
#include <xlocale.h>
#include <dlfcn.h>
#ifndef IOV_MAX
#define IOV_MAX 64

28
src/os/unix/ngx_dlopen.c Normal file
View File

@@ -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

31
src/os/unix/ngx_dlopen.h Normal file
View File

@@ -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_ */

View File

@@ -49,6 +49,8 @@
#include <osreldate.h>
#include <sys/sysctl.h>
#include <dlfcn.h>
#if __FreeBSD_version < 400017

View File

@@ -55,6 +55,8 @@
#include <crypt.h>
#include <sys/utsname.h> /* uname() */
#include <dlfcn.h>
#include <ngx_auto_config.h>

View File

@@ -108,6 +108,11 @@
#include <ngx_auto_config.h>
#if (NGX_HAVE_DLOPEN)
#include <dlfcn.h>
#endif
#if (NGX_HAVE_POSIX_SEM)
#include <semaphore.h>
#endif

View File

@@ -55,6 +55,8 @@
#include <inttypes.h>
#include <crypt.h>
#include <dlfcn.h>
#define NGX_ALIGNMENT _MAX_ALIGNMENT
#include <ngx_auto_config.h>

22
src/os/win32/ngx_dlopen.c Normal file
View File

@@ -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;
}

32
src/os/win32/ngx_dlopen.h Normal file
View File

@@ -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_ */