mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-24 06:53:41 +00:00
Clean up the dundi cache every 5 minutes.
(closes issue #13819) Reported by: adomjan Patches: pbx_dundi.c-clearcache.patch uploaded by adomjan (license 487) dundi_clearecache3.diff uploaded by mnicholson (license 96) Tested by: adomjan git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@163316 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -111,6 +111,7 @@ static struct sched_context *sched;
|
|||||||
static int netsocket = -1;
|
static int netsocket = -1;
|
||||||
static pthread_t netthreadid = AST_PTHREADT_NULL;
|
static pthread_t netthreadid = AST_PTHREADT_NULL;
|
||||||
static pthread_t precachethreadid = AST_PTHREADT_NULL;
|
static pthread_t precachethreadid = AST_PTHREADT_NULL;
|
||||||
|
static pthread_t clearcachethreadid = AST_PTHREADT_NULL;
|
||||||
static int tos = 0;
|
static int tos = 0;
|
||||||
static int dundidebug = 0;
|
static int dundidebug = 0;
|
||||||
static int authdebug = 0;
|
static int authdebug = 0;
|
||||||
@@ -2171,6 +2172,41 @@ static void *network_thread(void *ignore)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void *process_clearcache(void *ignore)
|
||||||
|
{
|
||||||
|
struct ast_db_entry *db_entry, *db_tree;
|
||||||
|
int striplen = sizeof("/dundi/cache");
|
||||||
|
time_t now;
|
||||||
|
|
||||||
|
while (!dundi_shutdown) {
|
||||||
|
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
|
||||||
|
|
||||||
|
time(&now);
|
||||||
|
|
||||||
|
db_entry = db_tree = ast_db_gettree("dundi/cache", NULL);
|
||||||
|
for (; db_entry; db_entry = db_entry->next) {
|
||||||
|
time_t expiry;
|
||||||
|
|
||||||
|
if (!ast_get_time_t(db_entry->data, &expiry, 0, NULL)) {
|
||||||
|
if (expiry < now) {
|
||||||
|
if (option_debug)
|
||||||
|
ast_log(LOG_DEBUG, "clearing expired DUNDI cache entry: %s\n", db_entry->key);
|
||||||
|
ast_db_del("dundi/cache", db_entry->key + striplen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ast_db_freetree(db_tree);
|
||||||
|
|
||||||
|
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
|
||||||
|
pthread_testcancel();
|
||||||
|
sleep(60);
|
||||||
|
pthread_testcancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
clearcachethreadid = AST_PTHREADT_NULL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static void *process_precache(void *ign)
|
static void *process_precache(void *ign)
|
||||||
{
|
{
|
||||||
struct dundi_precache_queue *qe;
|
struct dundi_precache_queue *qe;
|
||||||
@@ -2212,6 +2248,7 @@ static int start_network_thread(void)
|
|||||||
{
|
{
|
||||||
ast_pthread_create_background(&netthreadid, NULL, network_thread, NULL);
|
ast_pthread_create_background(&netthreadid, NULL, network_thread, NULL);
|
||||||
ast_pthread_create_background(&precachethreadid, NULL, process_precache, NULL);
|
ast_pthread_create_background(&precachethreadid, NULL, process_precache, NULL);
|
||||||
|
ast_pthread_create_background(&clearcachethreadid, NULL, process_clearcache, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4538,7 +4575,7 @@ static int set_config(char *config_file, struct sockaddr_in* sin)
|
|||||||
|
|
||||||
static int unload_module(void)
|
static int unload_module(void)
|
||||||
{
|
{
|
||||||
pthread_t previous_netthreadid = netthreadid, previous_precachethreadid = precachethreadid;
|
pthread_t previous_netthreadid = netthreadid, previous_precachethreadid = precachethreadid, previous_clearcachethreadid = clearcachethreadid;
|
||||||
ast_module_user_hangup_all();
|
ast_module_user_hangup_all();
|
||||||
|
|
||||||
/* Stop all currently running threads */
|
/* Stop all currently running threads */
|
||||||
@@ -4551,7 +4588,11 @@ static int unload_module(void)
|
|||||||
pthread_kill(previous_precachethreadid, SIGURG);
|
pthread_kill(previous_precachethreadid, SIGURG);
|
||||||
pthread_join(previous_precachethreadid, NULL);
|
pthread_join(previous_precachethreadid, NULL);
|
||||||
}
|
}
|
||||||
|
if (previous_clearcachethreadid != AST_PTHREADT_NULL) {
|
||||||
|
pthread_cancel(previous_clearcachethreadid);
|
||||||
|
pthread_join(previous_clearcachethreadid, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
ast_cli_unregister_multiple(cli_dundi, sizeof(cli_dundi) / sizeof(struct ast_cli_entry));
|
ast_cli_unregister_multiple(cli_dundi, sizeof(cli_dundi) / sizeof(struct ast_cli_entry));
|
||||||
ast_unregister_switch(&dundi_switch);
|
ast_unregister_switch(&dundi_switch);
|
||||||
ast_custom_function_unregister(&dundi_function);
|
ast_custom_function_unregister(&dundi_function);
|
||||||
|
Reference in New Issue
Block a user