mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-17 15:29:05 +00:00
autoservice: stop thread on graceful shutdown
This change adds thread shutdown to autoservice for graceful shutdowns only. ast_register_cleanup is backported to 1.8 to allow this. The logger callid is also released on shutdown in 11+. ASTERISK-23827 #close Reported by: Corey Farrell Review: https://reviewboard.asterisk.org/r/3594/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@415463 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -209,6 +209,7 @@ struct console {
|
||||
|
||||
struct ast_atexit {
|
||||
void (*func)(void);
|
||||
int is_cleanup;
|
||||
AST_LIST_ENTRY(ast_atexit) list;
|
||||
};
|
||||
|
||||
@@ -944,13 +945,13 @@ static char *handle_show_version_files(struct ast_cli_entry *e, int cmd, struct
|
||||
|
||||
#endif /* ! LOW_MEMORY */
|
||||
|
||||
static void ast_run_atexits(void)
|
||||
static void ast_run_atexits(int run_cleanups)
|
||||
{
|
||||
struct ast_atexit *ae;
|
||||
|
||||
AST_LIST_LOCK(&atexits);
|
||||
while ((ae = AST_LIST_REMOVE_HEAD(&atexits, list))) {
|
||||
if (ae->func) {
|
||||
if (ae->func && (!ae->is_cleanup || run_cleanups)) {
|
||||
ae->func();
|
||||
}
|
||||
ast_free(ae);
|
||||
@@ -972,7 +973,7 @@ static void __ast_unregister_atexit(void (*func)(void))
|
||||
AST_LIST_TRAVERSE_SAFE_END;
|
||||
}
|
||||
|
||||
int ast_register_atexit(void (*func)(void))
|
||||
static int register_atexit(void (*func)(void), int is_cleanup)
|
||||
{
|
||||
struct ast_atexit *ae;
|
||||
|
||||
@@ -981,6 +982,7 @@ int ast_register_atexit(void (*func)(void))
|
||||
return -1;
|
||||
}
|
||||
ae->func = func;
|
||||
ae->is_cleanup = is_cleanup;
|
||||
|
||||
AST_LIST_LOCK(&atexits);
|
||||
__ast_unregister_atexit(func);
|
||||
@@ -990,6 +992,16 @@ int ast_register_atexit(void (*func)(void))
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ast_register_atexit(void (*func)(void))
|
||||
{
|
||||
return register_atexit(func, 0);
|
||||
}
|
||||
|
||||
int ast_register_cleanup(void (*func)(void))
|
||||
{
|
||||
return register_atexit(func, 1);
|
||||
}
|
||||
|
||||
void ast_unregister_atexit(void (*func)(void))
|
||||
{
|
||||
AST_LIST_LOCK(&atexits);
|
||||
@@ -1748,8 +1760,9 @@ static int can_safely_quit(shutdown_nice_t niceness, int restart)
|
||||
static void really_quit(int num, shutdown_nice_t niceness, int restart)
|
||||
{
|
||||
int active_channels;
|
||||
int run_cleanups = niceness >= SHUTDOWN_NICE;
|
||||
|
||||
if (niceness >= SHUTDOWN_NICE) {
|
||||
if (run_cleanups) {
|
||||
ast_module_shutdown();
|
||||
}
|
||||
|
||||
@@ -1791,7 +1804,7 @@ static void really_quit(int num, shutdown_nice_t niceness, int restart)
|
||||
|
||||
if (option_verbose)
|
||||
ast_verbose("Executing last minute cleanups\n");
|
||||
ast_run_atexits();
|
||||
ast_run_atexits(run_cleanups);
|
||||
|
||||
ast_debug(1, "Asterisk ending (%d).\n", num);
|
||||
if (ast_socket > -1) {
|
||||
|
||||
Reference in New Issue
Block a user