1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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;
}
|