diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-08-07 03:48:00 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2003-08-07 03:48:00 +0000 |
commit | 80c651f140ec58fbff5cfca8c966117c3704bd91 (patch) | |
tree | bf0bf6fdb84162c0fc1e4e237f57ece2dd11d309 /asterisk.c | |
parent | 5483ee32c7bb0e162b7f05fe2259be8bf61005d2 (diff) |
Allow groups to be checked in reverse order, make musiconhold die on restart
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@1269 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'asterisk.c')
-rwxr-xr-x | asterisk.c | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/asterisk.c b/asterisk.c index 05b84308f..ccc384574 100755 --- a/asterisk.c +++ b/asterisk.c @@ -71,6 +71,12 @@ struct console { pthread_t t; /* Thread of handler */ }; +static struct ast_atexit { + void (*func)(void); + struct ast_atexit *next; +} *atexits = NULL; +static pthread_mutex_t atexitslock = AST_MUTEX_INITIALIZER; + time_t ast_startuptime; time_t ast_lastreloadtime; @@ -99,6 +105,43 @@ char ast_config_AST_PID[AST_CONFIG_MAX_PATH]; char ast_config_AST_SOCKET[AST_CONFIG_MAX_PATH]; char ast_config_AST_RUN_DIR[AST_CONFIG_MAX_PATH]; +int ast_register_atexit(void (*func)(void)) +{ + int res = -1; + struct ast_atexit *ae; + ast_unregister_atexit(func); + ae = malloc(sizeof(struct ast_atexit)); + ast_pthread_mutex_lock(&atexitslock); + if (ae) { + memset(ae, 0, sizeof(struct ast_atexit)); + ae->next = atexits; + ae->func = func; + atexits = ae; + res = 0; + } + ast_pthread_mutex_unlock(&atexitslock); + return res; +} + +void ast_unregister_atexit(void (*func)(void)) +{ + struct ast_atexit *ae, *prev = NULL; + ast_pthread_mutex_lock(&atexitslock); + ae = atexits; + while(ae) { + if (ae->func == func) { + if (prev) + prev->next = ae->next; + else + atexits = ae->next; + break; + } + prev = ae; + ae = ae->next; + } + ast_pthread_mutex_unlock(&atexitslock); +} + static int fdprint(int fd, const char *s) { return write(fd, s, strlen(s) + 1); @@ -356,6 +399,19 @@ static char *_argv[256]; static int shuttingdown = 0; +static void ast_run_atexits(void) +{ + struct ast_atexit *ae; + ast_pthread_mutex_lock(&atexitslock); + ae = atexits; + while(ae) { + if (ae->func) + ae->func(); + ae = ae->next; + } + ast_pthread_mutex_unlock(&atexitslock); +} + static void quit_handler(int num, int nice, int safeshutdown, int restart) { char filename[80] = ""; @@ -411,6 +467,9 @@ static void quit_handler(int num, int nice, int safeshutdown, int restart) if (el_hist != NULL) history_end(el_hist); } + if (option_verbose) + ast_verbose("Executing last minute cleanups\n"); + ast_run_atexits(); /* Called on exit */ if (option_verbose && option_console) ast_verbose("Asterisk %s ending (%d).\n", ast_active_channels() ? "uncleanly" : "cleanly", num); @@ -437,8 +496,8 @@ static void quit_handler(int num, int nice, int safeshutdown, int restart) if (option_verbose || option_console) ast_verbose("Restarting Asterisk NOW...\n"); execvp(_argv[0], _argv); - } else - exit(0); + } + exit(0); } static void __quit_handler(int num) |