Asterisk - The Open Source Telephony Project
21.4.1
|
Module Loader. More...
#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/paths.h"
#include <dirent.h>
#include "asterisk/dlinkedlists.h"
#include "asterisk/module.h"
#include "asterisk/config.h"
#include "asterisk/channel.h"
#include "asterisk/term.h"
#include "asterisk/manager.h"
#include "asterisk/io.h"
#include "asterisk/lock.h"
#include "asterisk/vector.h"
#include "asterisk/app.h"
#include "asterisk/test.h"
#include "asterisk/cli.h"
#include <dlfcn.h>
#include "asterisk/md5.h"
#include "asterisk/utils.h"
Go to the source code of this file.
Data Structures | |
struct | ast_module |
struct | ast_module_user |
struct | load_order |
struct | load_order_entry |
struct | load_results_map |
struct | load_retries |
struct | loadupdate |
struct | module_list |
struct | module_load_word |
struct | module_user_list |
struct | module_vector |
struct | reload_queue |
struct | reload_queue_item |
struct | updaters |
Macros | |
#define | AST_MODULE_LOAD_UNKNOWN_STRING "Unknown" /* Status string for unknown load status */ |
#define | key_matches(a, b) (memcmp((a), (b), 16) == 0) |
#define | RTLD_LOCAL 0 |
#define | RTLD_NOW 0 |
#define | STR_APPEND_TEXT(txt, str) |
Functions | |
struct ast_module * | __ast_module_ref (struct ast_module *mod, const char *file, int line, const char *func) |
struct ast_module * | __ast_module_running_ref (struct ast_module *mod, const char *file, int line, const char *func) |
void | __ast_module_shutdown_ref (struct ast_module *mod, const char *file, int line, const char *func) |
void | __ast_module_unref (struct ast_module *mod, const char *file, int line, const char *func) |
struct ast_module_user * | __ast_module_user_add (struct ast_module *mod, struct ast_channel *chan) |
void | __ast_module_user_hangup_all (struct ast_module *mod) |
void | __ast_module_user_remove (struct ast_module *mod, struct ast_module_user *u) |
static struct load_order_entry * | add_to_load_order (const char *resource, struct load_order *load_order, int required, int preload, int builtin) |
static int | alpha_module_list_create (struct module_vector *alpha_module_list) |
enum ast_module_load_result | ast_load_resource (const char *resource_name) |
Load a module. More... | |
int | ast_loader_register (int(*v)(void)) |
Add a procedure to be run when modules have been updated. More... | |
int | ast_loader_unregister (int(*v)(void)) |
Remove a procedure to be run when modules are updated. More... | |
int | ast_module_check (const char *name) |
Check if module exists. More... | |
char * | ast_module_helper (const char *line, const char *word, int pos, int state, int rpos, enum ast_module_helper_type type) |
Match modules names for the Asterisk cli. More... | |
const char * | ast_module_name (const struct ast_module *mod) |
Get the name of a module. More... | |
void | ast_module_register (const struct ast_module_info *info) |
enum ast_module_reload_result | ast_module_reload (const char *name) |
Reload asterisk modules. More... | |
const char * | ast_module_support_level_to_string (enum ast_module_support_level support_level) |
void | ast_module_unregister (const struct ast_module_info *info) |
void | ast_process_pending_reloads (void) |
Process reload requests received during startup. More... | |
int | ast_refresh_resource (const char *resource_name, enum ast_module_unload_mode force, int recursive) |
Unload and load a module again. More... | |
int | ast_unload_resource (const char *resource_name, enum ast_module_unload_mode force) |
Unload a module. More... | |
int | ast_update_module_list (int(*modentry)(const char *module, const char *description, int usecnt, const char *status, const char *like, enum ast_module_support_level support_level), const char *like) |
int | ast_update_module_list_condition (int(*modentry)(const char *module, const char *description, int usecnt, const char *status, const char *like, enum ast_module_support_level support_level, void *data, const char *condition), const char *like, void *data, const char *condition) |
int | ast_update_module_list_data (int(*modentry)(const char *module, const char *description, int usecnt, const char *status, const char *like, enum ast_module_support_level support_level, void *data), const char *like, void *data) |
Ask for a list of modules, descriptions, use counts and status. More... | |
void | ast_update_use_count (void) |
Notify when usecount has been changed. More... | |
static int | auto_unload_resource (const char *resource_name, enum ast_module_unload_mode force, int recursive, struct ast_vector_const_string *dependents) |
Unload a resource. More... | |
static struct ast_module * | find_resource (const char *resource, int do_lock) |
static char * | get_name_from_resource (const char *resource) |
static int | graceful_unload_possible (struct ast_module *target, struct ast_vector_const_string *dependents) |
Whether or not this module should be able to be unloaded successfully, if we recursively unload any modules that are dependent on it. More... | |
static unsigned int | inspect_module (const struct ast_module *mod) |
static int | is_module_loaded (const char *resource_name) |
Check to see if the given resource is loaded. More... | |
static struct ast_module * | load_dlopen (const char *resource_in, const char *so_ext, const char *filename, int flags, unsigned int suppress_logging) |
static int | load_dlopen_missing (struct ast_str **list, struct ast_vector_string *deps) |
static struct ast_module * | load_dynamic_module (const char *resource_in, unsigned int suppress_logging) |
int | load_modules (void) |
static enum ast_module_load_result | load_resource (const char *resource_name, unsigned int suppress_logging, struct module_vector *module_priorities, int required, int preload) |
static int | load_resource_list (struct load_order *load_order, int *mod_count) |
static int | loader_builtin_init (struct load_order *load_order) |
static int | loader_config_init (struct load_order *load_order) |
static const char * | loadresult2str (enum ast_module_load_result result) |
static void | logged_dlclose (const char *name, void *lib) |
dlclose(), with failure logging. | |
static int | module_deps_missing_recursive (struct ast_module *mod, struct module_vector *missingdeps) |
Recursively find required dependencies that are not running. More... | |
static int | module_deps_process_reqlist (struct ast_module *mod, struct ast_vector_string *vec, struct ast_vector_const_string *missing, int ref_enhancers, int isoptional) |
static int | module_deps_reference (struct ast_module *mod, struct ast_vector_const_string *missing) |
static void | module_destroy (struct ast_module *mod) |
static void | module_load_error (const char *fmt,...) |
static void | module_load_helper (const char *word) |
static int | module_load_helper_on_file (const char *dir_name, const char *filename, void *obj) |
static int | module_matches_helper_type (struct ast_module *mod, enum ast_module_helper_type type) |
static int | module_post_register (struct ast_module *mod) |
static int | module_reffed_deps_add (struct ast_module *mod, struct ast_module *dep, struct ast_vector_const_string *missing) |
static int | module_reffed_deps_add_dep_enhancers (struct ast_module *mod, struct ast_module *dep, struct ast_vector_const_string *missing) |
static int | module_vector_cmp (struct ast_module *a, struct ast_module *b) |
static int | module_vector_strcasecmp (struct ast_module *a, struct ast_module *b) |
int | modules_shutdown (void) |
static int | printdigest (const unsigned char *d) |
static void | publish_load_message (const char *name, enum ast_module_load_result result) |
static void | publish_load_message_type (const char *type, const char *name, const char *status) |
static void | publish_reload_message (const char *name, enum ast_module_reload_result result) |
static void | publish_unload_message (const char *name, const char *status) |
static void | queue_reload_request (const char *module) |
static int | resource_list_recursive_decline (struct module_vector *resources, struct ast_module *mod, struct ast_str **printmissing) |
static size_t | resource_name_baselen (const char *name) |
static int | resource_name_match (const char *name1, size_t baselen1, const char *name2) |
static enum ast_module_load_result | start_resource (struct ast_module *mod) |
static enum ast_module_load_result | start_resource_attempt (struct ast_module *mod, int *count) |
static int | start_resource_list (struct module_vector *resources, int *mod_count) |
static void | unload_dynamic_module (struct ast_module *mod) |
static int | verify_key (const unsigned char *key) |
Variables | |
static char | buildopt_sum [33] = AST_BUILDOPT_SUM |
static struct module_list | builtin_module_list |
static int | do_full_reload = 0 |
static const unsigned char | expected_key [] |
static const struct load_results_map | load_results [] |
static unsigned int | loader_ready |
static struct module_list | module_list = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , } |
static int | modules_loaded |
Internal flag to indicate all modules have been initially loaded. | |
static struct reload_queue | reload_queue = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , } |
static ast_mutex_t | reloadlock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } |
static struct ast_module *volatile | resource_being_loaded |
static struct ast_str * | startup_error_builder |
static struct ast_vector_string | startup_errors |
const char * | support_level_map [] |
static struct updaters | updaters = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , } |
Module Loader.
Definition in file loader.c.
#define STR_APPEND_TEXT | ( | txt, | |
str | |||
) |
Used with AST_VECTOR_CALLBACK_VOID to create a comma separated list of module names for error messages.
enum ast_module_load_result ast_load_resource | ( | const char * | resource_name | ) |
Load a module.
resource_name | The name of the module to load. |
This function is run by the PBX to load the modules. It performs all loading and initialization tasks. Basically, to load a module, just give it the name of the module and it will do the rest.
Definition at line 1978 of file loader.c.
References ast_debug, AST_DLLIST_LOCK, AST_DLLIST_UNLOCK, ast_test_suite_event_notify, ast_unload_resource(), ast_module::declined, and load_resource().
Referenced by ast_ari_asterisk_load_module(), ast_refresh_resource(), and auto_unload_resource().
int ast_loader_register | ( | int(*)(void) | updater | ) |
Add a procedure to be run when modules have been updated.
updater | The function to run when modules have been updated. |
This function adds the given function to a linked list of functions to be run when the modules are updated.
0 | on success |
-1 | on failure. |
Definition at line 2836 of file loader.c.
References AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, and ast_malloc.
int ast_loader_unregister | ( | int(*)(void) | updater | ) |
Remove a procedure to be run when modules are updated.
updater | The updater function to unregister. |
This removes the given function from the updater list.
0 | on success |
-1 | on failure. |
Definition at line 2851 of file loader.c.
References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, and AST_LIST_UNLOCK.
int ast_module_check | ( | const char * | name | ) |
Check if module exists.
Check if module with the name given is loaded.
Definition at line 2823 of file loader.c.
Referenced by ast_ari_asterisk_get_module(), ast_ari_asterisk_load_module(), ast_ari_asterisk_reload_module(), ast_ari_asterisk_unload_module(), and manager_modulecheck().
char* ast_module_helper | ( | const char * | line, |
const char * | word, | ||
int | pos, | ||
int | state, | ||
int | rpos, | ||
enum ast_module_helper_type | type | ||
) |
Match modules names for the Asterisk cli.
line | Unused by this function, but this should be the line we are matching. |
word | The partial name to match. |
pos | The position the word we are completing is in. |
state | The possible match to return. |
rpos | The position we should be matching. This should be the same as pos. |
type | The type of action that will be performed by CLI. |
A | possible completion of the partial match. |
NULL | if no matches were found or Asterisk is not yet fully booted. |
Definition at line 1528 of file loader.c.
References AST_DLLIST_LOCK, AST_DLLIST_TRAVERSE, AST_DLLIST_UNLOCK, AST_MODULE_HELPER_LOAD, AST_OPT_FLAG_FULLY_BOOTED, and ast_strdup.
const char* ast_module_name | ( | const struct ast_module * | mod | ) |
Get the name of a module.
mod | A pointer to the module. |
NULL | if mod or mod->info is NULL |
Definition at line 615 of file loader.c.
References ast_module_info::name.
Referenced by ast_register_application2(), and graceful_unload_possible().
enum ast_module_reload_result ast_module_reload | ( | const char * | name | ) |
Reload asterisk modules.
name | the name of the module to reload |
This function reloads the specified module, or if no modules are specified, it will reload all loaded modules.
The | ast_module_reload_result status of the module load request |
Definition at line 1721 of file loader.c.
References AST_DLLIST_LOCK, AST_DLLIST_TRAVERSE, AST_DLLIST_UNLOCK, ast_lock_path(), AST_MODULE_LOAD_SUCCESS, AST_MODULE_RELOAD_ERROR, AST_MODULE_RELOAD_IN_PROGRESS, AST_MODULE_RELOAD_NOT_FOUND, AST_MODULE_RELOAD_NOT_IMPLEMENTED, AST_MODULE_RELOAD_QUEUED, AST_MODULE_RELOAD_SUCCESS, AST_MODULE_RELOAD_UNINITIALIZED, ast_sd_notify(), ast_tvnow(), ast_unlock_path(), ast_module::declined, ast_module_info::description, publish_reload_message(), ast_module_info::reload, and ast_module::running.
Referenced by action_reload(), ast_ari_asterisk_reload_module(), and ast_process_pending_reloads().
void ast_process_pending_reloads | ( | void | ) |
Process reload requests received during startup.
This function requests that the loader execute the pending reload requests that were queued during server startup.
Definition at line 1566 of file loader.c.
References AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, and ast_module_reload().
int ast_refresh_resource | ( | const char * | resource_name, |
enum ast_module_unload_mode | force, | ||
int | recursive | ||
) |
Unload and load a module again.
resource_name | The name of the module to unload. |
ast_module_unload_mode | The force flag. This should be set using one of the AST_FORCE flags. |
recursive | Attempt to recursively unload any dependents of this module if that will allow the module to unload, and load them back again afterwards. |
0 | on success. |
1 | on error unloading modules. |
-1 | on error loading modules back. |
Definition at line 1407 of file loader.c.
References ast_load_resource(), ast_unload_resource(), AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_INIT, AST_VECTOR_SIZE, and auto_unload_resource().
int ast_unload_resource | ( | const char * | resource_name, |
enum | ast_module_unload_mode | ||
) |
Unload a module.
resource_name | The name of the module to unload. |
ast_module_unload_mode | The force flag. This should be set using one of the AST_FORCE flags. |
This function unloads a module. It will only unload modules that are not in use (usecount not zero), unless AST_FORCE_FIRM or AST_FORCE_HARD is specified. Setting AST_FORCE_FIRM or AST_FORCE_HARD will unload the module regardless of consequences (NOT RECOMMENDED).
0 | on success. |
-1 | on error. |
Definition at line 1448 of file loader.c.
References auto_unload_resource().
Referenced by ast_ari_asterisk_unload_module(), ast_load_resource(), ast_refresh_resource(), and auto_unload_resource().
int ast_update_module_list_data | ( | int(*)(const char *module, const char *description, int usecnt, const char *status, const char *like, enum ast_module_support_level support_level, void *data) | modentry, |
const char * | like, | ||
void * | data | ||
) |
Ask for a list of modules, descriptions, use counts and status.
modentry | A callback to an updater function |
like | |
data | Data passed into the callback for manipulation |
For each of the modules loaded, modentry will be executed with the resource, description, and usecount values of each particular module.
Definition at line 2764 of file loader.c.
References AST_DLLIST_LOCK, AST_DLLIST_UNLOCK, AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_module_info::description, ast_module::running, ast_module_info::support_level, and ast_module::usecount.
Referenced by ast_ari_asterisk_list_modules().
void ast_update_use_count | ( | void | ) |
Notify when usecount has been changed.
This function calculates use counts and notifies anyone trying to keep track of them. It should be called whenever your module's usecount changes.
Definition at line 2698 of file loader.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, and AST_LIST_UNLOCK.
Referenced by auto_unload_resource(), and unistim_new().
|
static |
Unload a resource.
resource_name | Module name |
force | |
recursive | Whether to attempt to recursively unload dependents of this module and load them again afterwards |
dependents. | Can be NULL if autounload is 0. |
0 | on success, -1 on failure |
Definition at line 1285 of file loader.c.
References ast_debug, AST_DLLIST_LOCK, AST_DLLIST_UNLOCK, AST_FORCE_FIRM, ast_load_resource(), ast_test_suite_event_notify, ast_unload_resource(), ast_update_use_count(), AST_VECTOR_GET, AST_VECTOR_SIZE, ast_module::declined, ESS, graceful_unload_possible(), ast_module::running, ast_module_info::unload, and ast_module::usecount.
Referenced by ast_refresh_resource(), and ast_unload_resource().
|
static |
Whether or not this module should be able to be unloaded successfully, if we recursively unload any modules that are dependent on it.
0 | if not, 1 if likely possible |
Definition at line 1225 of file loader.c.
References ast_debug, AST_DLLIST_TRAVERSE, ast_module_name(), ast_strdup, AST_VECTOR_ELEM_DEFAULT_CMP, AST_VECTOR_GET_CMP, AST_VECTOR_INSERT_AT, ast_module::reffed_deps, and ast_module::usecount.
Referenced by auto_unload_resource().
|
static |
Check to see if the given resource is loaded.
resource_name | Name of the resource, including .so suffix. |
Definition at line 981 of file loader.c.
References ast_module::lib, and logged_dlclose().
int load_modules | ( | void | ) |
Provided by loader.c
Definition at line 2508 of file loader.c.
References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_container_alloc_list, ast_copy_string(), ast_debug, AST_DLLIST_LOCK, AST_DLLIST_TRAVERSE, AST_DLLIST_UNLOCK, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE, ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_reset(), ast_str_strlen(), ast_tvdiff_us(), ast_tvnow(), AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_INIT, AST_VECTOR_SIZE, ast_xml_find_element(), ast_xml_get_text(), ast_xml_node_get_children(), ast_xml_xpath_get_first_result(), ast_xml_xpath_results_free(), ast_xmldoc_query(), ast_module::declined, load_resource_list(), ast_module::running, startup_errors, and ast_module_info::support_level.
|
static |
loads a resource based upon resource_name. If global_symbols_only is set only modules with global symbols will be loaded.
If the module_vector is provided (not NULL) the module is found and added to the vector without running the module's load() function. By doing this, modules can be initialized later in order by priority and dependencies.
If the module_vector is not provided, the module's load function will be executed immediately
Definition at line 1922 of file loader.c.
References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_shutdown_final(), AST_VECTOR_ADD_SORTED, ast_module::declined, ast_module::preload, ast_module::required, and ast_module::running.
Referenced by ast_load_resource(), and load_resource_list().
|
static |
loads modules in order by load_pri, updates mod_count
Definition at line 2271 of file loader.c.
References ast_debug, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, AST_VECTOR_FREE, AST_VECTOR_INIT, and load_resource().
Referenced by load_modules().
|
static |
Recursively find required dependencies that are not running.
mod | Module to scan for dependencies. |
missingdeps | Vector listing modules that must be started first. |
0 | All dependencies resolved. |
-1 | Failed to resolve some dependencies. |
An error from this function usually means a required module is not even loaded. This function is safe from infinite recursion, but dependency loops are not reported as an error from here. On success missingdeps will contain a list of every module that needs to be running before this module can start. missingdeps is sorted by load priority so any missing dependencies can be started if needed.
Definition at line 566 of file loader.c.
References AST_VECTOR_ADD_SORTED, AST_VECTOR_ELEM_DEFAULT_CMP, AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_GET_CMP, AST_VECTOR_INIT, AST_VECTOR_REMOVE, and AST_VECTOR_SIZE.
int modules_shutdown | ( | void | ) |
Provided by loader.c
Definition at line 1172 of file loader.c.
References ast_debug, AST_DLLIST_EMPTY, AST_DLLIST_LOCK, AST_DLLIST_REMOVE_CURRENT, AST_DLLIST_TRAVERSE, AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN, AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END, AST_DLLIST_UNLOCK, ast_module_unref, ast_module::declined, ast_module::keepuntilshutdown, ast_module::running, ast_module_info::unload, and ast_module::usecount.
Referenced by really_quit().
|
static |
Definition at line 1634 of file loader.c.
References ast_json_pack(), ast_json_payload_create(), ast_json_ref(), ast_json_unref(), ast_manager_get_generic_type(), ast_manager_get_topic(), RAII_VAR, stasis_message_create(), and stasis_publish().
Referenced by publish_reload_message().
|
static |
Definition at line 1713 of file loader.c.
References publish_load_message_type(), and S_OR.
Referenced by ast_module_reload().
|
static |
|
static |
String container for deferring output of startup errors.
Definition at line 153 of file loader.c.
Referenced by load_modules().