Version 0.1.8 from FTP
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@281 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
parent
801db5a7ba
commit
0c0a2993e4
|
@ -27,7 +27,7 @@ int usecount(void); /* How many channels provided by this module are in use? *
|
||||||
char *description(void); /* Description of this module */
|
char *description(void); /* Description of this module */
|
||||||
char *key(void); /* Return the below mentioned key, unmodified */
|
char *key(void); /* Return the below mentioned key, unmodified */
|
||||||
|
|
||||||
int reload(void);
|
int reload(void); /* reload configs */
|
||||||
|
|
||||||
#define ASTERISK_GPL_KEY \
|
#define ASTERISK_GPL_KEY \
|
||||||
"This paragraph is Copyright (C) 2000, Linux Support Services, Inc. \
|
"This paragraph is Copyright (C) 2000, Linux Support Services, Inc. \
|
||||||
|
@ -61,6 +61,9 @@ int ast_loader_register(int (*updater)(void));
|
||||||
/* No longer run me when modules are updated */
|
/* No longer run me when modules are updated */
|
||||||
int ast_loader_unregister(int (*updater)(void));
|
int ast_loader_unregister(int (*updater)(void));
|
||||||
|
|
||||||
|
/* Reload all modules */
|
||||||
|
void ast_module_reload(void);
|
||||||
|
|
||||||
/* Local user routines keep track of which channels are using a given module resource.
|
/* Local user routines keep track of which channels are using a given module resource.
|
||||||
They can help make removing modules safer, particularly if they're in use at the time
|
They can help make removing modules safer, particularly if they're in use at the time
|
||||||
they have been requested to be removed */
|
they have been requested to be removed */
|
||||||
|
|
55
loader.c
55
loader.c
|
@ -20,6 +20,7 @@
|
||||||
#include <asterisk/options.h>
|
#include <asterisk/options.h>
|
||||||
#include <asterisk/config.h>
|
#include <asterisk/config.h>
|
||||||
#include <asterisk/logger.h>
|
#include <asterisk/logger.h>
|
||||||
|
#include <asterisk/channel.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <asterisk/md5.h>
|
#include <asterisk/md5.h>
|
||||||
#define __USE_GNU
|
#define __USE_GNU
|
||||||
|
@ -93,7 +94,7 @@ int ast_unload_resource(char *resource_name, int force)
|
||||||
{
|
{
|
||||||
struct module *m, *ml = NULL;
|
struct module *m, *ml = NULL;
|
||||||
int res = -1;
|
int res = -1;
|
||||||
if (pthread_mutex_lock(&modlock))
|
if (ast_pthread_mutex_lock(&modlock))
|
||||||
ast_log(LOG_WARNING, "Failed to lock\n");
|
ast_log(LOG_WARNING, "Failed to lock\n");
|
||||||
m = module_list;
|
m = module_list;
|
||||||
while(m) {
|
while(m) {
|
||||||
|
@ -103,7 +104,7 @@ int ast_unload_resource(char *resource_name, int force)
|
||||||
ast_log(LOG_WARNING, "Warning: Forcing removal of module %s with use count %d\n", resource_name, res);
|
ast_log(LOG_WARNING, "Warning: Forcing removal of module %s with use count %d\n", resource_name, res);
|
||||||
else {
|
else {
|
||||||
ast_log(LOG_WARNING, "Soft unload failed, '%s' has use count %d\n", resource_name, res);
|
ast_log(LOG_WARNING, "Soft unload failed, '%s' has use count %d\n", resource_name, res);
|
||||||
pthread_mutex_unlock(&modlock);
|
ast_pthread_mutex_unlock(&modlock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +112,7 @@ int ast_unload_resource(char *resource_name, int force)
|
||||||
if (res) {
|
if (res) {
|
||||||
ast_log(LOG_WARNING, "Firm unload failed for %s\n", resource_name);
|
ast_log(LOG_WARNING, "Firm unload failed for %s\n", resource_name);
|
||||||
if (force <= AST_FORCE_FIRM) {
|
if (force <= AST_FORCE_FIRM) {
|
||||||
pthread_mutex_unlock(&modlock);
|
ast_pthread_mutex_unlock(&modlock);
|
||||||
return -1;
|
return -1;
|
||||||
} else
|
} else
|
||||||
ast_log(LOG_WARNING, "** Dangerous **: Unloading resource anyway, at user request\n");
|
ast_log(LOG_WARNING, "** Dangerous **: Unloading resource anyway, at user request\n");
|
||||||
|
@ -126,11 +127,27 @@ int ast_unload_resource(char *resource_name, int force)
|
||||||
ml = m;
|
ml = m;
|
||||||
m = m->next;
|
m = m->next;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&modlock);
|
ast_pthread_mutex_unlock(&modlock);
|
||||||
ast_update_use_count();
|
ast_update_use_count();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ast_module_reload(void)
|
||||||
|
{
|
||||||
|
struct module *m;
|
||||||
|
ast_pthread_mutex_lock(&modlock);
|
||||||
|
m = module_list;
|
||||||
|
while(m) {
|
||||||
|
if (m->reload) {
|
||||||
|
if (option_verbose > 2)
|
||||||
|
ast_verbose(VERBOSE_PREFIX_3 "Reloading module '%s' (%s)\n", m->resource, m->description());
|
||||||
|
m->reload();
|
||||||
|
}
|
||||||
|
m = m->next;
|
||||||
|
}
|
||||||
|
ast_pthread_mutex_unlock(&modlock);
|
||||||
|
}
|
||||||
|
|
||||||
int ast_load_resource(char *resource_name)
|
int ast_load_resource(char *resource_name)
|
||||||
{
|
{
|
||||||
static char fn[256];
|
static char fn[256];
|
||||||
|
@ -154,13 +171,13 @@ int ast_load_resource(char *resource_name)
|
||||||
ast_destroy(cfg);
|
ast_destroy(cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pthread_mutex_lock(&modlock))
|
if (ast_pthread_mutex_lock(&modlock))
|
||||||
ast_log(LOG_WARNING, "Failed to lock\n");
|
ast_log(LOG_WARNING, "Failed to lock\n");
|
||||||
m = module_list;
|
m = module_list;
|
||||||
while(m) {
|
while(m) {
|
||||||
if (!strcasecmp(m->resource, resource_name)) {
|
if (!strcasecmp(m->resource, resource_name)) {
|
||||||
ast_log(LOG_WARNING, "Module '%s' already exists\n", resource_name);
|
ast_log(LOG_WARNING, "Module '%s' already exists\n", resource_name);
|
||||||
pthread_mutex_unlock(&modlock);
|
ast_pthread_mutex_unlock(&modlock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
m = m->next;
|
m = m->next;
|
||||||
|
@ -168,7 +185,7 @@ int ast_load_resource(char *resource_name)
|
||||||
m = malloc(sizeof(struct module));
|
m = malloc(sizeof(struct module));
|
||||||
if (!m) {
|
if (!m) {
|
||||||
ast_log(LOG_WARNING, "Out of memory\n");
|
ast_log(LOG_WARNING, "Out of memory\n");
|
||||||
pthread_mutex_unlock(&modlock);
|
ast_pthread_mutex_unlock(&modlock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
strncpy(m->resource, resource_name, sizeof(m->resource));
|
strncpy(m->resource, resource_name, sizeof(m->resource));
|
||||||
|
@ -181,7 +198,7 @@ int ast_load_resource(char *resource_name)
|
||||||
if (!m->lib) {
|
if (!m->lib) {
|
||||||
ast_log(LOG_WARNING, "%s\n", dlerror());
|
ast_log(LOG_WARNING, "%s\n", dlerror());
|
||||||
free(m);
|
free(m);
|
||||||
pthread_mutex_unlock(&modlock);
|
ast_pthread_mutex_unlock(&modlock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
m->load_module = dlsym(m->lib, "load_module");
|
m->load_module = dlsym(m->lib, "load_module");
|
||||||
|
@ -223,7 +240,7 @@ int ast_load_resource(char *resource_name)
|
||||||
ast_log(LOG_WARNING, "%d error(s) loading module %s, aborted\n", errors, fn);
|
ast_log(LOG_WARNING, "%d error(s) loading module %s, aborted\n", errors, fn);
|
||||||
dlclose(m->lib);
|
dlclose(m->lib);
|
||||||
free(m);
|
free(m);
|
||||||
pthread_mutex_unlock(&modlock);
|
ast_pthread_mutex_unlock(&modlock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!fully_booted) {
|
if (!fully_booted) {
|
||||||
|
@ -238,7 +255,7 @@ int ast_load_resource(char *resource_name)
|
||||||
m->next = module_list;
|
m->next = module_list;
|
||||||
|
|
||||||
module_list = m;
|
module_list = m;
|
||||||
pthread_mutex_unlock(&modlock);
|
ast_pthread_mutex_unlock(&modlock);
|
||||||
if ((res = m->load_module())) {
|
if ((res = m->load_module())) {
|
||||||
ast_log(LOG_WARNING, "%s: load_module failed, returning %d\n", m->resource, res);
|
ast_log(LOG_WARNING, "%s: load_module failed, returning %d\n", m->resource, res);
|
||||||
ast_unload_resource(resource_name, 0);
|
ast_unload_resource(resource_name, 0);
|
||||||
|
@ -251,7 +268,7 @@ int ast_load_resource(char *resource_name)
|
||||||
static int ast_resource_exists(char *resource)
|
static int ast_resource_exists(char *resource)
|
||||||
{
|
{
|
||||||
struct module *m;
|
struct module *m;
|
||||||
if (pthread_mutex_lock(&modlock))
|
if (ast_pthread_mutex_lock(&modlock))
|
||||||
ast_log(LOG_WARNING, "Failed to lock\n");
|
ast_log(LOG_WARNING, "Failed to lock\n");
|
||||||
m = module_list;
|
m = module_list;
|
||||||
while(m) {
|
while(m) {
|
||||||
|
@ -259,7 +276,7 @@ static int ast_resource_exists(char *resource)
|
||||||
break;
|
break;
|
||||||
m = m->next;
|
m = m->next;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&modlock);
|
ast_pthread_mutex_unlock(&modlock);
|
||||||
if (m)
|
if (m)
|
||||||
return -1;
|
return -1;
|
||||||
else
|
else
|
||||||
|
@ -352,14 +369,14 @@ void ast_update_use_count(void)
|
||||||
/* Notify any module monitors that the use count for a
|
/* Notify any module monitors that the use count for a
|
||||||
resource has changed */
|
resource has changed */
|
||||||
struct loadupdate *m;
|
struct loadupdate *m;
|
||||||
if (pthread_mutex_lock(&modlock))
|
if (ast_pthread_mutex_lock(&modlock))
|
||||||
ast_log(LOG_WARNING, "Failed to lock\n");
|
ast_log(LOG_WARNING, "Failed to lock\n");
|
||||||
m = updaters;
|
m = updaters;
|
||||||
while(m) {
|
while(m) {
|
||||||
m->updater();
|
m->updater();
|
||||||
m = m->next;
|
m = m->next;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&modlock);
|
ast_pthread_mutex_unlock(&modlock);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,7 +392,7 @@ int ast_update_module_list(int (*modentry)(char *module, char *description, int
|
||||||
m = m->next;
|
m = m->next;
|
||||||
}
|
}
|
||||||
if (unlock)
|
if (unlock)
|
||||||
pthread_mutex_unlock(&modlock);
|
ast_pthread_mutex_unlock(&modlock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,11 +402,11 @@ int ast_loader_register(int (*v)(void))
|
||||||
/* XXX Should be more flexible here, taking > 1 verboser XXX */
|
/* XXX Should be more flexible here, taking > 1 verboser XXX */
|
||||||
if ((tmp = malloc(sizeof (struct loadupdate)))) {
|
if ((tmp = malloc(sizeof (struct loadupdate)))) {
|
||||||
tmp->updater = v;
|
tmp->updater = v;
|
||||||
if (pthread_mutex_lock(&modlock))
|
if (ast_pthread_mutex_lock(&modlock))
|
||||||
ast_log(LOG_WARNING, "Failed to lock\n");
|
ast_log(LOG_WARNING, "Failed to lock\n");
|
||||||
tmp->next = updaters;
|
tmp->next = updaters;
|
||||||
updaters = tmp;
|
updaters = tmp;
|
||||||
pthread_mutex_unlock(&modlock);
|
ast_pthread_mutex_unlock(&modlock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -399,7 +416,7 @@ int ast_loader_unregister(int (*v)(void))
|
||||||
{
|
{
|
||||||
int res = -1;
|
int res = -1;
|
||||||
struct loadupdate *tmp, *tmpl=NULL;
|
struct loadupdate *tmp, *tmpl=NULL;
|
||||||
if (pthread_mutex_lock(&modlock))
|
if (ast_pthread_mutex_lock(&modlock))
|
||||||
ast_log(LOG_WARNING, "Failed to lock\n");
|
ast_log(LOG_WARNING, "Failed to lock\n");
|
||||||
tmp = updaters;
|
tmp = updaters;
|
||||||
while(tmp) {
|
while(tmp) {
|
||||||
|
@ -415,6 +432,6 @@ int ast_loader_unregister(int (*v)(void))
|
||||||
}
|
}
|
||||||
if (tmp)
|
if (tmp)
|
||||||
res = 0;
|
res = 0;
|
||||||
pthread_mutex_unlock(&modlock);
|
ast_pthread_mutex_unlock(&modlock);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue