diff options
author | Igor Sysoev <igor@sysoev.ru> | 2017-01-17 20:00:00 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2017-01-17 20:00:00 +0300 |
commit | 16cbf3c076a0aca6d47adaf3f719493674cf2363 (patch) | |
tree | e6530480020f62a2bdbf249988ec3e2a751d3927 /src/nxt_dyld.c | |
download | unit-16cbf3c076a0aca6d47adaf3f719493674cf2363.tar.gz unit-16cbf3c076a0aca6d47adaf3f719493674cf2363.tar.bz2 |
Initial version.
Diffstat (limited to 'src/nxt_dyld.c')
-rw-r--r-- | src/nxt_dyld.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/nxt_dyld.c b/src/nxt_dyld.c new file mode 100644 index 00000000..63e6be14 --- /dev/null +++ b/src/nxt_dyld.c @@ -0,0 +1,86 @@ + +/* + * Copyright (C) Igor Sysoev + * Copyright (C) NGINX, Inc. + */ + +#include <nxt_main.h> + + +nxt_int_t +nxt_dyld_load(nxt_dyld_t *dyld) +{ + const char *err; + + dyld->handle = dlopen(dyld->name, RTLD_NOW | RTLD_GLOBAL); + + if (dyld->handle != NULL) { + nxt_thread_log_debug("dlopen(\"%s\")", dyld->name); + return NXT_OK; + } + + err = dlerror(); + if (err == NULL) { + err = "(null)"; + } + + nxt_thread_log_alert("dlopen(\"%s\") failed: %s", dyld->name, err); + + return NXT_ERROR; +} + + +void * +nxt_dyld_symbol(nxt_dyld_t *dyld, const char *symbol) +{ + void *handle, *s; + const char *name; + const char *err; + + if (dyld == NXT_DYLD_ANY) { + handle = RTLD_DEFAULT; + name = "RTLD_DEFAULT"; + + } else { + handle = dyld->handle; + name = dyld->name; + } + + s = dlsym(handle, symbol); + + if (s != NULL) { + nxt_thread_log_debug("dlsym(\"%s\", \"%s\")", name, symbol); + return s; + } + + err = dlerror(); + if (err == NULL) { + err = "(null)"; + } + + nxt_thread_log_alert("dlsym(\"%s\", \"%s\") failed: %s", name, symbol, err); + + return s; +} + + +nxt_int_t +nxt_dyld_unload(nxt_dyld_t *dyld) +{ + const char *err; + + if (dlclose(dyld->handle) == 0) { + nxt_thread_log_debug("dlclose(\"%s\")", dyld->name); + return NXT_OK; + } + + err = dlerror(); + + if (err == NULL) { + err = "(null)"; + } + + nxt_thread_log_alert("dlclose(\"%s\") failed: %s", dyld->name, err); + + return NXT_ERROR; +} |