#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/paths.h"
#include <dirent.h>
#include "asterisk/linkedlists.h"
#include "asterisk/module.h"
#include "asterisk/config.h"
#include "asterisk/channel.h"
#include "asterisk/term.h"
#include "asterisk/manager.h"
#include "asterisk/cdr.h"
#include "asterisk/enum.h"
#include "asterisk/http.h"
#include "asterisk/lock.h"
#include "asterisk/features.h"
#include "asterisk/dsp.h"
#include "asterisk/udptl.h"
#include "asterisk/heap.h"
#include "asterisk/app.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 | loadupdate |
| struct | module_list |
| struct | module_user_list |
| struct | reload_classes |
| struct | reload_queue |
| struct | reload_queue_item |
| struct | updaters |
Defines | |
| #define | RTLD_LOCAL 0 |
| #define | RTLD_NOW 0 |
Functions | |
| 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 | ast_load_resource (const char *resource_name) |
| Load a module. | |
| int | ast_loader_register (int(*v)(void)) |
| Add a procedure to be run when modules have been updated. | |
| int | ast_loader_unregister (int(*v)(void)) |
| Remove a procedure to be run when modules are updated. | |
| int | ast_module_check (const char *name) |
| Check if module exists. | |
| char * | ast_module_helper (const char *line, const char *word, int pos, int state, int rpos, int needsreload) |
| Match modules names for the Asterisk cli. | |
| const char * | ast_module_name (const struct ast_module *mod) |
| Get the name of a module. | |
| struct ast_module * | ast_module_ref (struct ast_module *mod) |
| void | ast_module_register (const struct ast_module_info *info) |
| int | ast_module_reload (const char *name) |
| Reload asterisk modules. | |
| void | ast_module_shutdown (void) |
| Run the unload() callback for all loaded modules. | |
| void | ast_module_unref (struct ast_module *mod) |
| void | ast_module_unregister (const struct ast_module_info *info) |
| void | ast_process_pending_reloads (void) |
| Process reload requests received during startup. | |
| int | ast_unload_resource (const char *resource_name, enum ast_module_unload_mode force) |
| Unload a module. | |
| int | ast_update_module_list (int(*modentry)(const char *module, const char *description, int usecnt, const char *like), const char *like) |
| Ask for a list of modules, descriptions, and use counts. | |
| void | ast_update_use_count (void) |
| Notify when usecount has been changed. | |
| static struct ast_module * | find_resource (const char *resource, int do_lock) |
| static unsigned int | inspect_module (const struct ast_module *mod) |
| static int | key_matches (const unsigned char *key1, const unsigned char *key2) |
| int | load_modules (unsigned int preload_only) |
| static enum ast_module_load_result | load_resource (const char *resource_name, unsigned int global_symbols_only, struct ast_heap *resource_heap, int required) |
| static int | load_resource_list (struct load_order *load_order, unsigned int global_symbols, int *mod_count) |
| static int | mod_load_cmp (void *a, void *b) |
| static int | printdigest (const unsigned char *d) |
| static void | queue_reload_request (const char *module) |
| static int | resource_name_match (const char *name1_in, const char *name2_in) |
| static enum ast_module_load_result | start_resource (struct ast_module *mod) |
| static int | verify_key (const unsigned char *key) |
Variables | |
| static char | buildopt_sum [33] = AST_BUILDOPT_SUM |
| static int | do_full_reload = 0 |
| static struct module_list | embedded_module_list |
| static unsigned int | embedding = 1 |
| static const unsigned char | expected_key [] |
| static ast_mutex_t | reloadlock = { PTHREAD_MUTEX_INITIALIZER , NULL, 1 } |
| static struct ast_module * | resource_being_loaded |
Definition in file loader.c.
| struct ast_module_user* __ast_module_user_add | ( | struct ast_module * | mod, | |
| struct ast_channel * | chan | |||
| ) | [read] |
Definition at line 204 of file loader.c.
References ast_atomic_fetchadd_int(), ast_calloc, AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_update_use_count(), ast_module_user::chan, ast_module::usecount, and ast_module::users.
Referenced by ast_func_read(), ast_func_read2(), ast_func_write(), and pbx_exec().
00206 { 00207 struct ast_module_user *u = ast_calloc(1, sizeof(*u)); 00208 00209 if (!u) 00210 return NULL; 00211 00212 u->chan = chan; 00213 00214 AST_LIST_LOCK(&mod->users); 00215 AST_LIST_INSERT_HEAD(&mod->users, u, entry); 00216 AST_LIST_UNLOCK(&mod->users); 00217 00218 ast_atomic_fetchadd_int(&mod->usecount, +1); 00219 00220 ast_update_use_count(); 00221 00222 return u; 00223 }
| void __ast_module_user_hangup_all | ( | struct ast_module * | mod | ) |
Definition at line 236 of file loader.c.
References ast_atomic_fetchadd_int(), ast_free, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_softhangup(), AST_SOFTHANGUP_APPUNLOAD, ast_update_use_count(), ast_module_user::chan, ast_module::usecount, and ast_module::users.
Referenced by ast_unload_resource().
00237 { 00238 struct ast_module_user *u; 00239 00240 AST_LIST_LOCK(&mod->users); 00241 while ((u = AST_LIST_REMOVE_HEAD(&mod->users, entry))) { 00242 ast_softhangup(u->chan, AST_SOFTHANGUP_APPUNLOAD); 00243 ast_atomic_fetchadd_int(&mod->usecount, -1); 00244 ast_free(u); 00245 } 00246 AST_LIST_UNLOCK(&mod->users); 00247 00248 ast_update_use_count(); 00249 }
| void __ast_module_user_remove | ( | struct ast_module * | mod, | |
| struct ast_module_user * | u | |||
| ) |
Definition at line 225 of file loader.c.
References ast_atomic_fetchadd_int(), ast_free, AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, ast_update_use_count(), ast_module::usecount, and ast_module::users.
Referenced by ast_func_read(), ast_func_read2(), ast_func_write(), and pbx_exec().
00226 { 00227 AST_LIST_LOCK(&mod->users); 00228 AST_LIST_REMOVE(&mod->users, u, entry); 00229 AST_LIST_UNLOCK(&mod->users); 00230 ast_atomic_fetchadd_int(&mod->usecount, -1); 00231 ast_free(u); 00232 00233 ast_update_use_count(); 00234 }
| static struct load_order_entry* add_to_load_order | ( | const char * | resource, | |
| struct load_order * | load_order, | |||
| int | required | |||
| ) | [static, read] |
Definition at line 909 of file loader.c.
References ast_calloc, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_strdup, load_order_entry::required, load_order_entry::resource, and resource_name_match().
Referenced by load_modules().
00910 { 00911 struct load_order_entry *order; 00912 00913 AST_LIST_TRAVERSE(load_order, order, entry) { 00914 if (!resource_name_match(order->resource, resource)) { 00915 /* Make sure we have the proper setting for the required field 00916 (we might have both load= and required= lines in modules.conf) */ 00917 order->required |= required; 00918 return NULL; 00919 } 00920 } 00921 00922 if (!(order = ast_calloc(1, sizeof(*order)))) 00923 return NULL; 00924 00925 order->resource = ast_strdup(resource); 00926 order->required = required; 00927 AST_LIST_INSERT_TAIL(load_order, order, entry); 00928 00929 return order; 00930 }
| int ast_load_resource | ( | const char * | resource_name | ) |
Load a module.
| resource_name | The name of the module to load. |
Definition at line 891 of file loader.c.
References AST_LIST_LOCK, AST_LIST_UNLOCK, and load_resource().
Referenced by handle_load(), load_module(), and manager_moduleload().
00892 { 00893 int res; 00894 AST_LIST_LOCK(&module_list); 00895 res = load_resource(resource_name, 0, NULL, 0); 00896 AST_LIST_UNLOCK(&module_list); 00897 00898 return res; 00899 }
| 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. |
| 0 | on success | |
| -1 | on failure. |
Definition at line 1207 of file loader.c.
References AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_malloc, and loadupdate::updater.
01208 { 01209 struct loadupdate *tmp; 01210 01211 if (!(tmp = ast_malloc(sizeof(*tmp)))) 01212 return -1; 01213 01214 tmp->updater = v; 01215 AST_LIST_LOCK(&updaters); 01216 AST_LIST_INSERT_HEAD(&updaters, tmp, entry); 01217 AST_LIST_UNLOCK(&updaters); 01218 01219 return 0; 01220 }
| int ast_loader_unregister | ( | int(*)(void) | updater | ) |
Remove a procedure to be run when modules are updated.
| updater | The updater function to unregister. |
| 0 | on success | |
| -1 | on failure. |
Definition at line 1222 of file loader.c.
References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, and loadupdate::updater.
01223 { 01224 struct loadupdate *cur; 01225 01226 AST_LIST_LOCK(&updaters); 01227 AST_LIST_TRAVERSE_SAFE_BEGIN(&updaters, cur, entry) { 01228 if (cur->updater == v) { 01229 AST_LIST_REMOVE_CURRENT(entry); 01230 break; 01231 } 01232 } 01233 AST_LIST_TRAVERSE_SAFE_END; 01234 AST_LIST_UNLOCK(&updaters); 01235 01236 return cur ? 0 : -1; 01237 }
| int ast_module_check | ( | const char * | name | ) |
Check if module exists.
Check if module with the name given is loaded.
Definition at line 1194 of file loader.c.
References ast_strlen_zero(), and find_resource().
Referenced by ifmodule_read(), load_module(), manager_modulecheck(), and unload_module().
01195 { 01196 struct ast_module *cur; 01197 01198 if (ast_strlen_zero(name)) 01199 return 0; /* FALSE */ 01200 01201 cur = find_resource(name, 1); 01202 01203 return (cur != NULL); 01204 }
| char* ast_module_helper | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state, | |||
| int | rpos, | |||
| int | needsreload | |||
| ) |
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. | |
| needsreload | This should be 1 if we need to reload this module and 0 otherwise. This function will only return modules that are reloadble if this is 1. |
| A | possible completion of the partial match. | |
| NULL | if no matches were found. |
Definition at line 574 of file loader.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strdup, ast_module::info, name, ast_module_info::reload, and ast_module::resource.
Referenced by conf_run(), confbridge_exec(), handle_modlist(), handle_reload(), handle_unload(), and load_module().
00575 { 00576 struct ast_module *cur; 00577 int i, which=0, l = strlen(word); 00578 char *ret = NULL; 00579 00580 if (pos != rpos) 00581 return NULL; 00582 00583 AST_LIST_LOCK(&module_list); 00584 AST_LIST_TRAVERSE(&module_list, cur, entry) { 00585 if (!strncasecmp(word, cur->resource, l) && 00586 (cur->info->reload || !needsreload) && 00587 ++which > state) { 00588 ret = ast_strdup(cur->resource); 00589 break; 00590 } 00591 } 00592 AST_LIST_UNLOCK(&module_list); 00593 00594 if (!ret) { 00595 for (i=0; !ret && reload_classes[i].name; i++) { 00596 if (!strncasecmp(word, reload_classes[i].name, l) && ++which > state) 00597 ret = ast_strdup(reload_classes[i].name); 00598 } 00599 } 00600 00601 return ret; 00602 }
| 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 99 of file loader.c.
Referenced by acf_retrieve_docs(), and ast_register_application2().
00100 { 00101 if (!mod || !mod->info) { 00102 return NULL; 00103 } 00104 00105 return mod->info->name; 00106 }
| struct ast_module* ast_module_ref | ( | struct ast_module * | mod | ) | [read] |
Definition at line 1239 of file loader.c.
References ast_atomic_fetchadd_int(), ast_update_use_count(), and ast_module::usecount.
Referenced by __oh323_new(), agi_handle_command(), alsa_new(), ast_agi_register(), ast_fax_tech_register(), ast_iax2_new(), ast_rtp_instance_new(), ast_srtp_create(), ast_timer_open(), dahdi_new(), data_result_generate_node(), fax_session_new(), fax_session_reserve(), find_best_technology(), fn_wrapper(), gtalk_new(), handle_cli_file_convert(), handle_orig(), load_module(), mgcp_new(), moh_alloc(), moh_files_alloc(), mute_add_audiohook(), newpvt(), oss_new(), phone_check_exception(), phone_new(), sip_handle_cc(), sip_new(), skinny_new(), smdi_load(), and usbradio_new().
01240 { 01241 if (!mod) { 01242 return NULL; 01243 } 01244 01245 ast_atomic_fetchadd_int(&mod->usecount, +1); 01246 ast_update_use_count(); 01247 01248 return mod; 01249 }
| void ast_module_register | ( | const struct ast_module_info * | info | ) |
Definition at line 142 of file loader.c.
References ast_calloc, AST_LIST_HEAD_INIT, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_UNLOCK, embedded_module_list, embedding, ast_module::info, ast_module::resource, and ast_module::users.
00143 { 00144 struct ast_module *mod; 00145 00146 if (embedding) { 00147 if (!(mod = ast_calloc(1, sizeof(*mod) + strlen(info->name) + 1))) 00148 return; 00149 strcpy(mod->resource, info->name); 00150 } else { 00151 mod = resource_being_loaded; 00152 } 00153 00154 mod->info = info; 00155 AST_LIST_HEAD_INIT(&mod->users); 00156 00157 /* during startup, before the loader has been initialized, 00158 there are no threads, so there is no need to take the lock 00159 on this list to manipulate it. it is also possible that it 00160 might be unsafe to use the list lock at that point... so 00161 let's avoid it altogether 00162 */ 00163 if (embedding) { 00164 AST_LIST_INSERT_TAIL(&embedded_module_list, mod, entry); 00165 } else { 00166 AST_LIST_LOCK(&module_list); 00167 /* it is paramount that the new entry be placed at the tail of 00168 the list, otherwise the code that uses dlopen() to load 00169 dynamic modules won't be able to find out if the module it 00170 just opened was registered or failed to load 00171 */ 00172 AST_LIST_INSERT_TAIL(&module_list, mod, entry); 00173 AST_LIST_UNLOCK(&module_list); 00174 } 00175 00176 /* give the module a copy of its own handle, for later use in registrations and the like */ 00177 *((struct ast_module **) &(info->self)) = mod; 00178 }
| int ast_module_reload | ( | const char * | name | ) |
Reload asterisk modules.
| name | the name of the module to reload |
| 1 | if the module was found but cannot be reloaded. | |
| -1 | if a reload operation is already in progress. | |
| 2 | if the specfied module was found and reloaded. |
Definition at line 669 of file loader.c.
References ast_config_AST_CONFIG_DIR, ast_fully_booted, ast_lastreloadtime, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_lock_path(), AST_LOCK_SUCCESS, AST_LOCK_TIMEOUT, ast_log(), ast_mutex_trylock, ast_mutex_unlock, ast_opt_lock_confdir, ast_tvnow(), ast_unlock_path(), ast_verb, ast_verbose, ast_module::declined, ast_module_info::description, ast_module::flags, ast_module::info, LOG_NOTICE, LOG_WARNING, queue_reload_request(), ast_module_info::reload, ast_module::resource, resource_name_match(), and ast_module::running.
Referenced by action_reload(), action_updateconfig(), ast_process_pending_reloads(), handle_core_reload(), handle_reload(), manager_moduleload(), and monitor_sig_flags().
00670 { 00671 struct ast_module *cur; 00672 int res = 0; /* return value. 0 = not found, others, see below */ 00673 int i; 00674 00675 /* If we aren't fully booted, we just pretend we reloaded but we queue this 00676 up to run once we are booted up. */ 00677 if (!ast_fully_booted) { 00678 queue_reload_request(name); 00679 return 0; 00680 } 00681 00682 if (ast_mutex_trylock(&reloadlock)) { 00683 ast_verbose("The previous reload command didn't finish yet\n"); 00684 return -1; /* reload already in progress */ 00685 } 00686 ast_lastreloadtime = ast_tvnow(); 00687 00688 if (ast_opt_lock_confdir) { 00689 int try; 00690 int res; 00691 for (try = 1, res = AST_LOCK_TIMEOUT; try < 6 && (res == AST_LOCK_TIMEOUT); try++) { 00692 res = ast_lock_path(ast_config_AST_CONFIG_DIR); 00693 if (res == AST_LOCK_TIMEOUT) { 00694 ast_log(LOG_WARNING, "Failed to grab lock on %s, try %d\n", ast_config_AST_CONFIG_DIR, try); 00695 } 00696 } 00697 if (res != AST_LOCK_SUCCESS) { 00698 ast_verbose("Cannot grab lock on %s\n", ast_config_AST_CONFIG_DIR); 00699 ast_mutex_unlock(&reloadlock); 00700 return -1; 00701 } 00702 } 00703 00704 /* Call "predefined" reload here first */ 00705 for (i = 0; reload_classes[i].name; i++) { 00706 if (!name || !strcasecmp(name, reload_classes[i].name)) { 00707 reload_classes[i].reload_fn(); /* XXX should check error ? */ 00708 res = 2; /* found and reloaded */ 00709 } 00710 } 00711 00712 if (name && res) { 00713 if (ast_opt_lock_confdir) { 00714 ast_unlock_path(ast_config_AST_CONFIG_DIR); 00715 } 00716 ast_mutex_unlock(&reloadlock); 00717 return res; 00718 } 00719 00720 AST_LIST_LOCK(&module_list); 00721 AST_LIST_TRAVERSE(&module_list, cur, entry) { 00722 const struct ast_module_info *info = cur->info; 00723 00724 if (name && resource_name_match(name, cur->resource)) 00725 continue; 00726 00727 if (!cur->flags.running || cur->flags.declined) { 00728 if (!name) 00729 continue; 00730 ast_log(LOG_NOTICE, "The module '%s' was not properly initialized. " 00731 "Before reloading the module, you must run \"module load %s\" " 00732 "and fix whatever is preventing the module from being initialized.\n", 00733 name, name); 00734 res = 2; /* Don't report that the module was not found */ 00735 break; 00736 } 00737 00738 if (!info->reload) { /* cannot be reloaded */ 00739 if (res < 1) /* store result if possible */ 00740 res = 1; /* 1 = no reload() method */ 00741 continue; 00742 } 00743 00744 res = 2; 00745 ast_verb(3, "Reloading module '%s' (%s)\n", cur->resource, info->description); 00746 info->reload(); 00747 } 00748 AST_LIST_UNLOCK(&module_list); 00749 00750 if (ast_opt_lock_confdir) { 00751 ast_unlock_path(ast_config_AST_CONFIG_DIR); 00752 } 00753 ast_mutex_unlock(&reloadlock); 00754 00755 return res; 00756 }
| void ast_module_shutdown | ( | void | ) |
Run the unload() callback for all loaded modules.
This function should be called when Asterisk is shutting down gracefully.
If we go through the entire list without changing anything, ignore the usecounts and unload, then exit.
Definition at line 474 of file loader.c.
References AST_LIST_HEAD_DESTROY, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_module::declined, ast_module::flags, free, ast_module::info, ast_module::running, ast_module_info::unload, ast_module::usecount, and ast_module::users.
Referenced by really_quit().
00475 { 00476 struct ast_module *mod; 00477 int somethingchanged = 1, final = 0; 00478 00479 AST_LIST_LOCK(&module_list); 00480 00481 /*!\note Some resources, like timers, are started up dynamically, and thus 00482 * may be still in use, even if all channels are dead. We must therefore 00483 * check the usecount before asking modules to unload. */ 00484 do { 00485 if (!somethingchanged) { 00486 /*!\note If we go through the entire list without changing 00487 * anything, ignore the usecounts and unload, then exit. */ 00488 final = 1; 00489 } 00490 00491 /* Reset flag before traversing the list */ 00492 somethingchanged = 0; 00493 00494 AST_LIST_TRAVERSE_SAFE_BEGIN(&module_list, mod, entry) { 00495 if (!final && mod->usecount) { 00496 continue; 00497 } 00498 AST_LIST_REMOVE_CURRENT(entry); 00499 if (mod->flags.running && !mod->flags.declined && mod->info->unload) { 00500 mod->info->unload(); 00501 } 00502 AST_LIST_HEAD_DESTROY(&mod->users); 00503 free(mod); 00504 somethingchanged = 1; 00505 } 00506 AST_LIST_TRAVERSE_SAFE_END; 00507 } while (somethingchanged && !final); 00508 00509 AST_LIST_UNLOCK(&module_list); 00510 }
| void ast_module_unref | ( | struct ast_module * | mod | ) |
Definition at line 1251 of file loader.c.
References ast_atomic_fetchadd_int(), ast_update_use_count(), and ast_module::usecount.
Referenced by agi_handle_command(), alsa_hangup(), ast_agi_unregister(), ast_bridge_check(), ast_fax_tech_unregister(), ast_rtp_instance_new(), ast_smdi_interface_destroy(), ast_srtp_destroy(), ast_timer_close(), dahdi_destroy_channel_bynum(), dahdi_hangup(), data_result_generate_node(), destroy(), destroy_bridge(), destroy_callback(), destroy_session(), filestream_destructor(), gtalk_hangup(), handle_cli_file_convert(), handle_orig(), iax2_predestroy(), instance_destructor(), local_ast_moh_cleanup(), mgcp_hangup(), oh323_hangup(), oss_hangup(), phone_check_exception(), phone_hangup(), sip_cc_monitor_destructor(), sip_hangup(), skinny_hangup(), smart_bridge_operation(), and usbradio_hangup().
01252 { 01253 if (!mod) { 01254 return; 01255 } 01256 01257 ast_atomic_fetchadd_int(&mod->usecount, -1); 01258 ast_update_use_count(); 01259 }
| void ast_module_unregister | ( | const struct ast_module_info * | info | ) |
Definition at line 180 of file loader.c.
References ast_free, AST_LIST_HEAD_DESTROY, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_module::info, and ast_module::users.
00181 { 00182 struct ast_module *mod = NULL; 00183 00184 /* it is assumed that the users list in the module structure 00185 will already be empty, or we cannot have gotten to this 00186 point 00187 */ 00188 AST_LIST_LOCK(&module_list); 00189 AST_LIST_TRAVERSE_SAFE_BEGIN(&module_list, mod, entry) { 00190 if (mod->info == info) { 00191 AST_LIST_REMOVE_CURRENT(entry); 00192 break; 00193 } 00194 } 00195 AST_LIST_TRAVERSE_SAFE_END; 00196 AST_LIST_UNLOCK(&module_list); 00197 00198 if (mod) { 00199 AST_LIST_HEAD_DESTROY(&mod->users); 00200 ast_free(mod); 00201 } 00202 }
| 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 604 of file loader.c.
References ast_free, ast_fully_booted, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, ast_log(), ast_module_reload(), do_full_reload, LOG_NOTICE, and reload_queue_item::module.
Referenced by main().
00605 { 00606 struct reload_queue_item *item; 00607 00608 if (!ast_fully_booted) { 00609 return; 00610 } 00611 00612 AST_LIST_LOCK(&reload_queue); 00613 00614 if (do_full_reload) { 00615 do_full_reload = 0; 00616 AST_LIST_UNLOCK(&reload_queue); 00617 ast_log(LOG_NOTICE, "Executing deferred reload request.\n"); 00618 ast_module_reload(NULL); 00619 return; 00620 } 00621 00622 while ((item = AST_LIST_REMOVE_HEAD(&reload_queue, entry))) { 00623 ast_log(LOG_NOTICE, "Executing deferred reload request for module '%s'.\n", item->module); 00624 ast_module_reload(item->module); 00625 ast_free(item); 00626 } 00627 00628 AST_LIST_UNLOCK(&reload_queue); 00629 }
| 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. |
| 0 | on success. | |
| -1 | on error. |
Definition at line 512 of file loader.c.
References __ast_module_user_hangup_all(), AST_FORCE_FIRM, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_log(), ast_update_use_count(), ast_module::declined, find_resource(), ast_module::flags, ast_module::info, ast_module::lib, LOG_WARNING, ast_module_info::restore_globals, ast_module::running, ast_module_info::unload, and ast_module::usecount.
Referenced by handle_unload(), manager_moduleload(), and unload_module().
00513 { 00514 struct ast_module *mod; 00515 int res = -1; 00516 int error = 0; 00517 00518 AST_LIST_LOCK(&module_list); 00519 00520 if (!(mod = find_resource(resource_name, 0))) { 00521 AST_LIST_UNLOCK(&module_list); 00522 ast_log(LOG_WARNING, "Unload failed, '%s' could not be found\n", resource_name); 00523 return -1; 00524 } 00525 00526 if (!mod->flags.running || mod->flags.declined) { 00527 ast_log(LOG_WARNING, "Unload failed, '%s' is not loaded.\n", resource_name); 00528 error = 1; 00529 } 00530 00531 if (!error && (mod->usecount > 0)) { 00532 if (force) 00533 ast_log(LOG_WARNING, "Warning: Forcing removal of module '%s' with use count %d\n", 00534 resource_name, mod->usecount); 00535 else { 00536 ast_log(LOG_WARNING, "Soft unload failed, '%s' has use count %d\n", resource_name, 00537 mod->usecount); 00538 error = 1; 00539 } 00540 } 00541 00542 if (!error) { 00543 __ast_module_user_hangup_all(mod); 00544 res = mod->info->unload(); 00545 00546 if (res) { 00547 ast_log(LOG_WARNING, "Firm unload failed for %s\n", resource_name); 00548 if (force <= AST_FORCE_FIRM) 00549 error = 1; 00550 else 00551 ast_log(LOG_WARNING, "** Dangerous **: Unloading resource anyway, at user request\n"); 00552 } 00553 } 00554 00555 if (!error) 00556 mod->flags.running = mod->flags.declined = 0; 00557 00558 AST_LIST_UNLOCK(&module_list); 00559 00560 if (!error && !mod->lib && mod->info && mod->info->restore_globals) 00561 mod->info->restore_globals(); 00562 00563 #ifdef LOADABLE_MODULES 00564 if (!error) 00565 unload_dynamic_module(mod); 00566 #endif 00567 00568 if (!error) 00569 ast_update_use_count(); 00570 00571 return res; 00572 }
| int ast_update_module_list | ( | int(*)(const char *module, const char *description, int usecnt, const char *like) | modentry, | |
| const char * | like | |||
| ) |
Ask for a list of modules, descriptions, and use counts.
| modentry | A callback to an updater function. | |
| like | For each of the modules loaded, modentry will be executed with the resource, description, and usecount values of each particular module. |
Definition at line 1173 of file loader.c.
References AST_LIST_TRAVERSE, AST_LIST_TRYLOCK, AST_LIST_UNLOCK, ast_module_info::description, ast_module::info, ast_module::resource, and ast_module::usecount.
Referenced by ast_var_Modules(), and handle_modlist().
01175 { 01176 struct ast_module *cur; 01177 int unlock = -1; 01178 int total_mod_loaded = 0; 01179 01180 if (AST_LIST_TRYLOCK(&module_list)) 01181 unlock = 0; 01182 01183 AST_LIST_TRAVERSE(&module_list, cur, entry) { 01184 total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount, like); 01185 } 01186 01187 if (unlock) 01188 AST_LIST_UNLOCK(&module_list); 01189 01190 return total_mod_loaded; 01191 }
| void ast_update_use_count | ( | void | ) |
Notify when usecount has been changed.
This function calulates use counts and notifies anyone trying to keep track of them. It should be called whenever your module's usecount changes.
Definition at line 1161 of file loader.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, and loadupdate::updater.
Referenced by __ast_module_user_add(), __ast_module_user_hangup_all(), __ast_module_user_remove(), ast_module_ref(), ast_module_unref(), ast_unload_resource(), handle_request_do(), oh323_request(), sip_request_call(), start_resource(), and unistim_new().
01162 { 01163 /* Notify any module monitors that the use count for a 01164 resource has changed */ 01165 struct loadupdate *m; 01166 01167 AST_LIST_LOCK(&updaters); 01168 AST_LIST_TRAVERSE(&updaters, m, entry) 01169 m->updater(); 01170 AST_LIST_UNLOCK(&updaters); 01171 }
| static struct ast_module* find_resource | ( | const char * | resource, | |
| int | do_lock | |||
| ) | [static, read] |
Definition at line 336 of file loader.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_module::resource, and resource_name_match().
Referenced by ast_module_check(), ast_unload_resource(), load_modules(), and load_resource().
00337 { 00338 struct ast_module *cur; 00339 00340 if (do_lock) 00341 AST_LIST_LOCK(&module_list); 00342 00343 AST_LIST_TRAVERSE(&module_list, cur, entry) { 00344 if (!resource_name_match(resource, cur->resource)) 00345 break; 00346 } 00347 00348 if (do_lock) 00349 AST_LIST_UNLOCK(&module_list); 00350 00351 return cur; 00352 }
| static unsigned int inspect_module | ( | const struct ast_module * | mod | ) | [static] |
Definition at line 758 of file loader.c.
References ast_log(), ast_strlen_zero(), buildopt_sum, ast_module_info::buildopt_sum, ast_module_info::description, ast_module::info, ast_module_info::key, LOG_WARNING, ast_module::resource, and verify_key().
Referenced by load_resource().
00759 { 00760 if (!mod->info->description) { 00761 ast_log(LOG_WARNING, "Module '%s' does not provide a description.\n", mod->resource); 00762 return 1; 00763 } 00764 00765 if (!mod->info->key) { 00766 ast_log(LOG_WARNING, "Module '%s' does not provide a license key.\n", mod->resource); 00767 return 1; 00768 } 00769 00770 if (verify_key((unsigned char *) mod->info->key)) { 00771 ast_log(LOG_WARNING, "Module '%s' did not provide a valid license key.\n", mod->resource); 00772 return 1; 00773 } 00774 00775 if (!ast_strlen_zero(mod->info->buildopt_sum) && 00776 strcmp(buildopt_sum, mod->info->buildopt_sum)) { 00777 ast_log(LOG_WARNING, "Module '%s' was not compiled with the same compile-time options as this version of Asterisk.\n", mod->resource); 00778 ast_log(LOG_WARNING, "Module '%s' will not be initialized as it may cause instability.\n", mod->resource); 00779 return 1; 00780 } 00781 00782 return 0; 00783 }
| static int key_matches | ( | const unsigned char * | key1, | |
| const unsigned char * | key2 | |||
| ) | [static] |
Definition at line 289 of file loader.c.
Referenced by verify_key().
00290 { 00291 int x; 00292 00293 for (x = 0; x < 16; x++) { 00294 if (key1[x] != key2[x]) 00295 return 0; 00296 } 00297 00298 return 1; 00299 }
| int load_modules | ( | unsigned | int | ) |
Provided by loader.c
Definition at line 1011 of file loader.c.
References add_to_load_order(), ast_config_AST_MODULE_DIR, ast_config_destroy(), ast_config_load2(), ast_debug, ast_free, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log(), AST_MODULE_CONFIG, ast_opt_quiet, ast_true(), ast_variable_browse(), ast_variable_retrieve(), ast_verb, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, embedded_module_list, embedding, EVENT_FLAG_SYSTEM, find_resource(), module_list::first, ast_module::flags, module_list::last, ast_module::lib, load_resource_list(), LOG_NOTICE, LOG_WARNING, manager_event, ast_variable::name, ast_variable::next, load_order_entry::resource, ast_module::resource, resource_name_match(), ast_module::running, and ast_variable::value.
Referenced by main().
01012 { 01013 struct ast_config *cfg; 01014 struct ast_module *mod; 01015 struct load_order_entry *order; 01016 struct ast_variable *v; 01017 unsigned int load_count; 01018 struct load_order load_order; 01019 int res = 0; 01020 struct ast_flags config_flags = { 0 }; 01021 int modulecount = 0; 01022 01023 #ifdef LOADABLE_MODULES 01024 struct dirent *dirent; 01025 DIR *dir; 01026 #endif 01027 01028 /* all embedded modules have registered themselves by now */ 01029 embedding = 0; 01030 01031 ast_verb(1, "Asterisk Dynamic Loader Starting:\n"); 01032 01033 AST_LIST_HEAD_INIT_NOLOCK(&load_order); 01034 01035 AST_LIST_LOCK(&module_list); 01036 01037 if (embedded_module_list.first) { 01038 module_list.first = embedded_module_list.first; 01039 module_list.last = embedded_module_list.last; 01040 embedded_module_list.first = NULL; 01041 } 01042 01043 cfg = ast_config_load2(AST_MODULE_CONFIG, "" /* core, can't reload */, config_flags); 01044 if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) { 01045 ast_log(LOG_WARNING, "No '%s' found, no modules will be loaded.\n", AST_MODULE_CONFIG); 01046 goto done; 01047 } 01048 01049 /* first, find all the modules we have been explicitly requested to load */ 01050 for (v = ast_variable_browse(cfg, "modules"); v; v = v->next) { 01051 if (!strcasecmp(v->name, preload_only ? "preload" : "load")) { 01052 add_to_load_order(v->value, &load_order, 0); 01053 } 01054 if (!strcasecmp(v->name, preload_only ? "preload-require" : "require")) { 01055 /* Add the module to the list and make sure it's required */ 01056 add_to_load_order(v->value, &load_order, 1); 01057 ast_debug(2, "Adding module to required list: %s (%s)\n", v->value, v->name); 01058 } 01059 01060 } 01061 01062 /* check if 'autoload' is on */ 01063 if (!preload_only && ast_true(ast_variable_retrieve(cfg, "modules", "autoload"))) { 01064 /* if so, first add all the embedded modules that are not already running to the load order */ 01065 AST_LIST_TRAVERSE(&module_list, mod, entry) { 01066 /* if it's not embedded, skip it */ 01067 if (mod->lib) 01068 continue; 01069 01070 if (mod->flags.running) 01071 continue; 01072 01073 order = add_to_load_order(mod->resource, &load_order, 0); 01074 } 01075 01076 #ifdef LOADABLE_MODULES 01077 /* if we are allowed to load dynamic modules, scan the directory for 01078 for all available modules and add them as well */ 01079 if ((dir = opendir(ast_config_AST_MODULE_DIR))) { 01080 while ((dirent = readdir(dir))) { 01081 int ld = strlen(dirent->d_name); 01082 01083 /* Must end in .so to load it. */ 01084 01085 if (ld < 4) 01086 continue; 01087 01088 if (strcasecmp(dirent->d_name + ld - 3, ".so")) 01089 continue; 01090 01091 /* if there is already a module by this name in the module_list, 01092 skip this file */ 01093 if (find_resource(dirent->d_name, 0)) 01094 continue; 01095 01096 add_to_load_order(dirent->d_name, &load_order, 0); 01097 } 01098 01099 closedir(dir); 01100 } else { 01101 if (!ast_opt_quiet) 01102 ast_log(LOG_WARNING, "Unable to open modules directory '%s'.\n", 01103 ast_config_AST_MODULE_DIR); 01104 } 01105 #endif 01106 } 01107 01108 /* now scan the config for any modules we are prohibited from loading and 01109 remove them from the load order */ 01110 for (v = ast_variable_browse(cfg, "modules"); v; v = v->next) { 01111 if (strcasecmp(v->name, "noload")) 01112 continue; 01113 01114 AST_LIST_TRAVERSE_SAFE_BEGIN(&load_order, order, entry) { 01115 if (!resource_name_match(order->resource, v->value)) { 01116 AST_LIST_REMOVE_CURRENT(entry); 01117 ast_free(order->resource); 01118 ast_free(order); 01119 } 01120 } 01121 AST_LIST_TRAVERSE_SAFE_END; 01122 } 01123 01124 /* we are done with the config now, all the information we need is in the 01125 load_order list */ 01126 ast_config_destroy(cfg); 01127 01128 load_count = 0; 01129 AST_LIST_TRAVERSE(&load_order, order, entry) 01130 load_count++; 01131 01132 if (load_count) 01133 ast_log(LOG_NOTICE, "%d modules will be loaded.\n", load_count); 01134 01135 /* first, load only modules that provide global symbols */ 01136 if ((res = load_resource_list(&load_order, 1, &modulecount)) < 0) { 01137 goto done; 01138 } 01139 01140 /* now load everything else */ 01141 if ((res = load_resource_list(&load_order, 0, &modulecount)) < 0) { 01142 goto done; 01143 } 01144 01145 done: 01146 while ((order = AST_LIST_REMOVE_HEAD(&load_order, entry))) { 01147 ast_free(order->resource); 01148 ast_free(order); 01149 } 01150 01151 AST_LIST_UNLOCK(&module_list); 01152 01153 /* Tell manager clients that are aggressive at logging in that we're done 01154 loading modules. If there's a DNS problem in chan_sip, we might not 01155 even reach this */ 01156 manager_event(EVENT_FLAG_SYSTEM, "ModuleLoadReport", "ModuleLoadStatus: Done\r\nModuleSelection: %s\r\nModuleCount: %d\r\n", preload_only ? "Preload" : "All", modulecount); 01157 01158 return res; 01159 }
| static enum ast_module_load_result load_resource | ( | const char * | resource_name, | |
| unsigned int | global_symbols_only, | |||
| struct ast_heap * | resource_heap, | |||
| int | required | |||
| ) | [static] |
loads a resource based upon resource_name. If global_symbols_only is set only modules with global symbols will be loaded.
If the ast_heap is provided (not NULL) the module is found and added to the heap without running the module's load() function. By doing this, modules added to the resource_heap can be initialized later in order by priority.
If the ast_heap is not provided, the module's load function will be executed immediately
Definition at line 831 of file loader.c.
References ast_heap_push(), AST_LIST_INSERT_SORTALPHA, AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, ast_log(), AST_MODFLAG_GLOBAL_SYMBOLS, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_PRIORITY, AST_MODULE_LOAD_SKIP, AST_MODULE_LOAD_SUCCESS, ast_test_flag, ast_module_info::backup_globals, ast_module::declined, find_resource(), ast_module::flags, ast_module::info, inspect_module(), ast_module::lib, LOG_WARNING, ast_module::resource, ast_module::running, and start_resource().
Referenced by ast_load_resource(), and load_resource_list().
00832 { 00833 struct ast_module *mod; 00834 enum ast_module_load_result res = AST_MODULE_LOAD_SUCCESS; 00835 00836 if ((mod = find_resource(resource_name, 0))) { 00837 if (mod->flags.running) { 00838 ast_log(LOG_WARNING, "Module '%s' already exists.\n", resource_name); 00839 return AST_MODULE_LOAD_DECLINE; 00840 } 00841 if (global_symbols_only && !ast_test_flag(mod->info, AST_MODFLAG_GLOBAL_SYMBOLS)) 00842 return AST_MODULE_LOAD_SKIP; 00843 } else { 00844 #ifdef LOADABLE_MODULES 00845 if (!(mod = load_dynamic_module(resource_name, global_symbols_only))) { 00846 /* don't generate a warning message during load_modules() */ 00847 if (!global_symbols_only) { 00848 ast_log(LOG_WARNING, "Module '%s' could not be loaded.\n", resource_name); 00849 return required ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_DECLINE; 00850 } else { 00851 return required ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SKIP; 00852 } 00853 } 00854 #else 00855 ast_log(LOG_WARNING, "Module support is not available. Module '%s' could not be loaded.\n", resource_name); 00856 return required ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_DECLINE; 00857 #endif 00858 } 00859 00860 if (inspect_module(mod)) { 00861 ast_log(LOG_WARNING, "Module '%s' could not be loaded.\n", resource_name); 00862 #ifdef LOADABLE_MODULES 00863 unload_dynamic_module(mod); 00864 #endif 00865 return required ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_DECLINE; 00866 } 00867 00868 if (!mod->lib && mod->info->backup_globals && mod->info->backup_globals()) { 00869 ast_log(LOG_WARNING, "Module '%s' was unable to backup its global data.\n", resource_name); 00870 return required ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_DECLINE; 00871 } 00872 00873 mod->flags.declined = 0; 00874 00875 if (resource_heap) { 00876 ast_heap_push(resource_heap, mod); 00877 res = AST_MODULE_LOAD_PRIORITY; 00878 } else { 00879 res = start_resource(mod); 00880 } 00881 00882 /* Now make sure that the list is sorted */ 00883 AST_LIST_LOCK(&module_list); 00884 AST_LIST_REMOVE(&module_list, mod, entry); 00885 AST_LIST_INSERT_SORTALPHA(&module_list, mod, entry, resource); 00886 AST_LIST_UNLOCK(&module_list); 00887 00888 return res; 00889 }
| static int load_resource_list | ( | struct load_order * | load_order, | |
| unsigned int | global_symbols, | |||
| int * | mod_count | |||
| ) | [static] |
loads modules in order by load_pri, updates mod_count
Definition at line 951 of file loader.c.
References ast_free, ast_heap_create(), ast_heap_destroy(), ast_heap_pop(), AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_PRIORITY, AST_MODULE_LOAD_SKIP, AST_MODULE_LOAD_SUCCESS, load_resource(), LOG_ERROR, mod_load_cmp(), load_order_entry::required, load_order_entry::resource, and start_resource().
Referenced by load_modules().
00952 { 00953 struct ast_heap *resource_heap; 00954 struct load_order_entry *order; 00955 struct ast_module *mod; 00956 int count = 0; 00957 int res = 0; 00958 00959 if(!(resource_heap = ast_heap_create(8, mod_load_cmp, -1))) { 00960 return -1; 00961 } 00962 00963 /* first, add find and add modules to heap */ 00964 AST_LIST_TRAVERSE_SAFE_BEGIN(load_order, order, entry) { 00965 switch (load_resource(order->resource, global_symbols, resource_heap, order->required)) { 00966 case AST_MODULE_LOAD_SUCCESS: 00967 case AST_MODULE_LOAD_DECLINE: 00968 AST_LIST_REMOVE_CURRENT(entry); 00969 ast_free(order->resource); 00970 ast_free(order); 00971 break; 00972 case AST_MODULE_LOAD_FAILURE: 00973 ast_log(LOG_ERROR, "*** Failed to load module %s - %s\n", order->resource, order->required ? "Required" : "Not required"); 00974 fprintf(stderr, "*** Failed to load module %s - %s\n", order->resource, order->required ? "Required" : "Not required"); 00975 res = order->required ? -2 : -1; 00976 goto done; 00977 case AST_MODULE_LOAD_SKIP: 00978 break; 00979 case AST_MODULE_LOAD_PRIORITY: 00980 AST_LIST_REMOVE_CURRENT(entry); 00981 break; 00982 } 00983 } 00984 AST_LIST_TRAVERSE_SAFE_END; 00985 00986 /* second remove modules from heap sorted by priority */ 00987 while ((mod = ast_heap_pop(resource_heap))) { 00988 switch (start_resource(mod)) { 00989 case AST_MODULE_LOAD_SUCCESS: 00990 count++; 00991 case AST_MODULE_LOAD_DECLINE: 00992 break; 00993 case AST_MODULE_LOAD_FAILURE: 00994 res = -1; 00995 goto done; 00996 case AST_MODULE_LOAD_SKIP: 00997 case AST_MODULE_LOAD_PRIORITY: 00998 break; 00999 } 01000 } 01001 01002 done: 01003 if (mod_count) { 01004 *mod_count += count; 01005 } 01006 ast_heap_destroy(resource_heap); 01007 01008 return res; 01009 }
| static int mod_load_cmp | ( | void * | a, | |
| void * | b | |||
| ) | [static] |
Definition at line 932 of file loader.c.
References AST_MODFLAG_LOAD_ORDER, ast_test_flag, ast_module::info, and ast_module_info::load_pri.
Referenced by load_resource_list().
00933 { 00934 struct ast_module *a_mod = (struct ast_module *) a; 00935 struct ast_module *b_mod = (struct ast_module *) b; 00936 int res = -1; 00937 /* if load_pri is not set, default is 128. Lower is better*/ 00938 unsigned char a_pri = ast_test_flag(a_mod->info, AST_MODFLAG_LOAD_ORDER) ? a_mod->info->load_pri : 128; 00939 unsigned char b_pri = ast_test_flag(b_mod->info, AST_MODFLAG_LOAD_ORDER) ? b_mod->info->load_pri : 128; 00940 if (a_pri == b_pri) { 00941 res = 0; 00942 } else if (a_pri < b_pri) { 00943 res = 1; 00944 } 00945 return res; 00946 }
| static int printdigest | ( | const unsigned char * | d | ) | [static] |
Definition at line 276 of file loader.c.
References ast_debug.
Referenced by verify_key().
00277 { 00278 int x, pos; 00279 char buf[256]; /* large enough so we don't have to worry */ 00280 00281 for (pos = 0, x = 0; x < 16; x++) 00282 pos += sprintf(buf + pos, " %02x", *d++); 00283 00284 ast_debug(1, "Unexpected signature:%s\n", buf); 00285 00286 return 0; 00287 }
| static void queue_reload_request | ( | const char * | module | ) | [static] |
Definition at line 631 of file loader.c.
References ast_calloc, ast_free, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_strlen_zero(), do_full_reload, LOG_ERROR, and reload_queue_item::module.
Referenced by ast_module_reload().
00632 { 00633 struct reload_queue_item *item; 00634 00635 AST_LIST_LOCK(&reload_queue); 00636 00637 if (do_full_reload) { 00638 AST_LIST_UNLOCK(&reload_queue); 00639 return; 00640 } 00641 00642 if (ast_strlen_zero(module)) { 00643 /* A full reload request (when module is NULL) wipes out any previous 00644 reload requests and causes the queue to ignore future ones */ 00645 while ((item = AST_LIST_REMOVE_HEAD(&reload_queue, entry))) { 00646 ast_free(item); 00647 } 00648 do_full_reload = 1; 00649 } else { 00650 /* No reason to add the same module twice */ 00651 AST_LIST_TRAVERSE(&reload_queue, item, entry) { 00652 if (!strcasecmp(item->module, module)) { 00653 AST_LIST_UNLOCK(&reload_queue); 00654 return; 00655 } 00656 } 00657 item = ast_calloc(1, sizeof(*item) + strlen(module) + 1); 00658 if (!item) { 00659 ast_log(LOG_ERROR, "Failed to allocate reload queue item.\n"); 00660 AST_LIST_UNLOCK(&reload_queue); 00661 return; 00662 } 00663 strcpy(item->module, module); 00664 AST_LIST_INSERT_TAIL(&reload_queue, item, entry); 00665 } 00666 AST_LIST_UNLOCK(&reload_queue); 00667 }
| static int resource_name_match | ( | const char * | name1_in, | |
| const char * | name2_in | |||
| ) | [static] |
Definition at line 318 of file loader.c.
References ast_strdupa.
Referenced by add_to_load_order(), ast_module_reload(), find_resource(), and load_modules().
00319 { 00320 char *name1 = (char *) name1_in; 00321 char *name2 = (char *) name2_in; 00322 00323 /* trim off any .so extensions */ 00324 if (!strcasecmp(name1 + strlen(name1) - 3, ".so")) { 00325 name1 = ast_strdupa(name1); 00326 name1[strlen(name1) - 3] = '\0'; 00327 } 00328 if (!strcasecmp(name2 + strlen(name2) - 3, ".so")) { 00329 name2 = ast_strdupa(name2); 00330 name2[strlen(name2) - 3] = '\0'; 00331 } 00332 00333 return strcasecmp(name1, name2); 00334 }
| static enum ast_module_load_result start_resource | ( | struct ast_module * | mod | ) | [static] |
Definition at line 785 of file loader.c.
References ast_fully_booted, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_PRIORITY, AST_MODULE_LOAD_SKIP, AST_MODULE_LOAD_SUCCESS, ast_opt_console, ast_update_use_count(), ast_verb, ast_verbose, COLOR_BLACK, COLOR_BROWN, ast_module::declined, ast_module_info::description, ast_module::flags, ast_module::info, ast_module_info::load, option_verbose, ast_module::resource, ast_module::running, and term_color().
Referenced by load_resource(), and load_resource_list().
00786 { 00787 char tmp[256]; 00788 enum ast_module_load_result res; 00789 00790 if (!mod->info->load) { 00791 return AST_MODULE_LOAD_FAILURE; 00792 } 00793 00794 res = mod->info->load(); 00795 00796 switch (res) { 00797 case AST_MODULE_LOAD_SUCCESS: 00798 if (!ast_fully_booted) { 00799 ast_verb(1, "%s => (%s)\n", mod->resource, term_color(tmp, mod->info->description, COLOR_BROWN, COLOR_BLACK, sizeof(tmp))); 00800 if (ast_opt_console && !option_verbose) 00801 ast_verbose( "."); 00802 } else { 00803 ast_verb(1, "Loaded %s => (%s)\n", mod->resource, mod->info->description); 00804 } 00805 00806 mod->flags.running = 1; 00807 00808 ast_update_use_count(); 00809 break; 00810 case AST_MODULE_LOAD_DECLINE: 00811 mod->flags.declined = 1; 00812 break; 00813 case AST_MODULE_LOAD_FAILURE: 00814 case AST_MODULE_LOAD_SKIP: /* modules should never return this value */ 00815 case AST_MODULE_LOAD_PRIORITY: 00816 break; 00817 } 00818 00819 return res; 00820 }
| static int verify_key | ( | const unsigned char * | key | ) | [static] |
Definition at line 301 of file loader.c.
References expected_key, key_matches(), MD5Final(), MD5Init(), MD5Update(), and printdigest().
Referenced by inspect_module().
00302 { 00303 struct MD5Context c; 00304 unsigned char digest[16]; 00305 00306 MD5Init(&c); 00307 MD5Update(&c, key, strlen((char *)key)); 00308 MD5Final(digest, &c); 00309 00310 if (key_matches(expected_key, digest)) 00311 return 0; 00312 00313 printdigest(digest); 00314 00315 return -1; 00316 }
char buildopt_sum[33] = AST_BUILDOPT_SUM [static] |
int do_full_reload = 0 [static] |
Definition at line 130 of file loader.c.
Referenced by ast_process_pending_reloads(), and queue_reload_request().
struct module_list embedded_module_list [static] |
unsigned int embedding = 1 [static] |
const unsigned char expected_key[] [static] |
Initial value:
{ 0x87, 0x76, 0x79, 0x35, 0x23, 0xea, 0x3a, 0xd3,
0x25, 0x2a, 0xbb, 0x35, 0x87, 0xe4, 0x22, 0x24 }
Definition at line 74 of file loader.c.
Referenced by verify_key().
ast_mutex_t reloadlock = { PTHREAD_MUTEX_INITIALIZER , NULL, 1 } [static] |
struct ast_module* resource_being_loaded [static] |
1.5.6