The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Wrappers around dlopen to manage loading modules at runtime. More...
#include <freeradius-devel/server/dl_module.h>
#include <freeradius-devel/server/log.h>
#include <freeradius-devel/server/global_lib.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/dl.h>
#include <freeradius-devel/util/syserror.h>
#include <pthread.h>
#include <ctype.h>
#include <unistd.h>
Go to the source code of this file.
Data Structures | |
struct | dl_module_loader_s |
Wrapper struct around dl_loader_t. More... | |
Macros | |
#define | _DL_MODULE_PRIVATE 1 |
#define | DL_INIT_CHECK fr_assert(dl_module_loader) |
Functions | |
static int | _dl_module_free (dl_module_t *dl_module) |
Decrement the reference count of the dl, eventually freeing it. More... | |
static int | _dl_module_loader_free (dl_module_loader_t *dl_module_l) |
static int | dl_dict_attr_autoload (dl_t const *module, void *symbol, void *user_ctx) |
Wrapper to log errors. More... | |
static int | dl_dict_autoload (dl_t const *module, void *symbol, void *user_ctx) |
Wrapper to log errors. More... | |
static int | dl_dict_enum_autoload (dl_t const *module, void *symbol, void *user_ctx) |
Wrapper to log errors. More... | |
dl_loader_t * | dl_loader_from_module_loader (dl_module_loader_t *dl_module_l) |
dl_module_t * | dl_module_alloc (dl_module_t const *parent, char const *name, dl_module_type_t type) |
Load a module library using dlopen() or return a previously loaded module from the cache. More... | |
static int8_t | dl_module_cmp (void const *one, void const *two) |
int | dl_module_free (dl_module_t *dl_module) |
Free a dl_module (when there are no more references to it) More... | |
dl_module_loader_t * | dl_module_loader_init (char const *lib_dir) |
Initialise structures needed by the dynamic linker. More... | |
static int | dl_module_magic_verify (dl_module_common_t const *module) |
Check if the magic number in the module matches the one in the library. More... | |
static int | dl_module_onload_func (dl_t const *dl, UNUSED void *symbol, UNUSED void *ctx) |
Call the load() function in a module's exported structure. More... | |
static dl_module_t const * | dl_module_root (dl_module_t const *child) |
Find the module's shallowest parent, or the child if no parents are found. More... | |
static char const * | dl_module_root_prefix_str (dl_module_t const *module) |
Return the prefix string for the deepest module. More... | |
char const * | dl_module_search_path (void) |
static void | dl_module_unload_func (dl_t const *dl, UNUSED void *symbol, UNUSED void *ctx) |
Call the unload() function in a module's exported structure. More... | |
Variables | |
static dl_module_loader_t * | dl_module_loader |
fr_table_num_sorted_t const | dl_module_type_prefix [] |
Name prefixes matching the types of loadable module. More... | |
size_t | dl_module_type_prefix_len = NUM_ELEMENTS(dl_module_type_prefix) |
Wrappers around dlopen to manage loading modules at runtime.
Definition in file dl_module.c.
struct dl_module_loader_s |
Wrapper struct around dl_loader_t.
Provides space to store instance data.
Definition at line 47 of file dl_module.c.
Data Fields | ||
---|---|---|
dl_loader_t * | dl_loader | A list of loaded libraries, and symbol to callback mappings. |
pthread_mutex_t | lock | Protects the module tree when multiple threads are loading modules simultaneously. |
fr_rb_tree_t * | module_tree | Module's dl handles. |
#define _DL_MODULE_PRIVATE 1 |
Definition at line 27 of file dl_module.c.
#define DL_INIT_CHECK fr_assert(dl_module_loader) |
Definition at line 41 of file dl_module.c.
|
static |
Decrement the reference count of the dl, eventually freeing it.
Definition at line 226 of file dl_module.c.
|
static |
Definition at line 432 of file dl_module.c.
|
static |
Wrapper to log errors.
Definition at line 507 of file dl_module.c.
|
static |
Wrapper to log errors.
Definition at line 519 of file dl_module.c.
|
static |
Wrapper to log errors.
Definition at line 495 of file dl_module.c.
dl_loader_t* dl_loader_from_module_loader | ( | dl_module_loader_t * | dl_module_l | ) |
Definition at line 488 of file dl_module.c.
dl_module_t* dl_module_alloc | ( | dl_module_t const * | parent, |
char const * | name, | ||
dl_module_type_t | type | ||
) |
Load a module library using dlopen() or return a previously loaded module from the cache.
When the dl_module_t is no longer used, talloc_free() may be used to free it.
When all references to the original dlhandle are freed, dlclose() will be called on the dlhandle to unload the module.
[in] | parent | The dl_module_t of the parent module, e.g. rlm_sql for rlm_sql_postgresql. |
[in] | name | of the module e.g. sql for rlm_sql. |
[in] | type | Used to determine module name prefixes. Must be one of:
|
Definition at line 315 of file dl_module.c.
|
static |
Definition at line 65 of file dl_module.c.
int dl_module_free | ( | dl_module_t * | dl_module | ) |
Free a dl_module (when there are no more references to it)
Decrement the reference count for a module, freeing it and unloading the module if there are no more references.
Definition at line 281 of file dl_module.c.
dl_module_loader_t* dl_module_loader_init | ( | char const * | lib_dir | ) |
Initialise structures needed by the dynamic linker.
Definition at line 532 of file dl_module.c.
|
static |
Check if the magic number in the module matches the one in the library.
This is used to detect potential ABI issues caused by running with modules which were built for a different version of the server.
[in] | module | Common fields from module's exported interface struct. |
Definition at line 180 of file dl_module.c.
|
static |
Call the load() function in a module's exported structure.
[in] | dl | to call the load function for. |
[in] | symbol | UNUSED. |
[in] | ctx | UNUSED. |
Definition at line 124 of file dl_module.c.
|
static |
Find the module's shallowest parent, or the child if no parents are found.
[in] | child | to locate the root for. |
Definition at line 84 of file dl_module.c.
|
inlinestatic |
Return the prefix string for the deepest module.
This is useful for submodules which don't have a prefix of their own. In this case we need to use the prefix of the shallowest module, which will be a proto or rlm module.
[in] | module | to get the prefix for. |
Definition at line 108 of file dl_module.c.
char const* dl_module_search_path | ( | void | ) |
Definition at line 483 of file dl_module.c.
|
static |
Call the unload() function in a module's exported structure.
[in] | dl | to call the unload function for. |
[in] | symbol | UNUSED. |
[in] | ctx | UNUSED. |
Definition at line 157 of file dl_module.c.
|
static |
Definition at line 53 of file dl_module.c.
fr_table_num_sorted_t const dl_module_type_prefix[] |
Name prefixes matching the types of loadable module.
Definition at line 57 of file dl_module.c.
size_t dl_module_type_prefix_len = NUM_ELEMENTS(dl_module_type_prefix) |
Definition at line 63 of file dl_module.c.