Skip to content

Commit cd0d60a

Browse files
InterLinked1Friendly Automation
authored and
Friendly Automation
committed
cli: Prevent assertions on startup from bad ao2 refs.
If "core show channels" is run before startup has completed, it is possible for bad ao2 refs to occur because the system is not yet fully initialized. This will lead to an assertion failing. To prevent this, initialization of CLI builtins is moved to be later along in the main load sequence. Core CLI commands are loaded at the same time, but channel-related commands are loaded later on. ASTERISK-29846 #close Change-Id: If6b3cde802876bd738c1b4cf2683bea6ddc615b6
1 parent cffaf12 commit cd0d60a

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

include/asterisk/_private.h

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ int ast_term_init(void); /*!< Provided by term.c */
3737
int astdb_init(void); /*!< Provided by db.c */
3838
int ast_channels_init(void); /*!< Provided by channel.c */
3939
void ast_builtins_init(void); /*!< Provided by cli.c */
40+
void ast_cli_channels_init(void); /*!< Provided by cli.c */
4041
int ast_cli_perms_init(int reload); /*!< Provided by cli.c */
4142
void dnsmgr_start_refresh(void); /*!< Provided by dnsmgr.c */
4243
int ast_dns_system_resolver_init(void); /*!< Provided by dns_system_resolver.c */

main/asterisk.c

+1
Original file line numberDiff line numberDiff line change
@@ -4269,6 +4269,7 @@ static void asterisk_daemon(int isroot, const char *runuser, const char *rungrou
42694269

42704270
/* loads the cli_permissions.conf file needed to implement cli restrictions. */
42714271
ast_cli_perms_init(0);
4272+
ast_cli_channels_init(); /* Not always safe to access CLI commands until startup is complete. */
42724273

42734274
ast_stun_init();
42744275

main/cli.c

+21-23
Original file line numberDiff line numberDiff line change
@@ -2016,50 +2016,27 @@ static char *handle_help(struct ast_cli_entry *e, int cmd, struct ast_cli_args *
20162016
static struct ast_cli_entry cli_cli[] = {
20172017
AST_CLI_DEFINE(handle_commandmatchesarray, "Returns command matches array"),
20182018

2019-
AST_CLI_DEFINE(handle_nodebugchan_deprecated, "Disable debugging on channel(s)"),
2020-
2021-
AST_CLI_DEFINE(handle_chanlist, "Display information on channels"),
2022-
2023-
AST_CLI_DEFINE(handle_showcalls, "Display information on calls"),
2024-
2025-
AST_CLI_DEFINE(handle_showchan, "Display information on a specific channel"),
2026-
2027-
AST_CLI_DEFINE(handle_core_set_debug_channel, "Enable/disable debugging on a channel"),
2028-
20292019
AST_CLI_DEFINE(handle_debug_category, "Enable/disable debugging categories"),
20302020

20312021
AST_CLI_DEFINE(handle_debug, "Set level of debug chattiness"),
20322022
AST_CLI_DEFINE(handle_trace, "Set level of trace chattiness"),
20332023
AST_CLI_DEFINE(handle_verbose, "Set level of verbose chattiness"),
20342024

2035-
AST_CLI_DEFINE(group_show_channels, "Display active channels with group(s)"),
2036-
20372025
AST_CLI_DEFINE(handle_help, "Display help list, or specific help on a command"),
2038-
20392026
AST_CLI_DEFINE(handle_logger_mute, "Toggle logging output to a console"),
20402027

20412028
AST_CLI_DEFINE(handle_modlist, "List modules and info"),
2042-
20432029
AST_CLI_DEFINE(handle_load, "Load a module by name"),
2044-
20452030
AST_CLI_DEFINE(handle_reload, "Reload configuration for a module"),
2046-
20472031
AST_CLI_DEFINE(handle_core_reload, "Global reload"),
2048-
20492032
AST_CLI_DEFINE(handle_unload, "Unload a module by name"),
2050-
20512033
AST_CLI_DEFINE(handle_refresh, "Completely unloads and loads a module by name"),
20522034

20532035
AST_CLI_DEFINE(handle_showuptime, "Show uptime information"),
20542036

2055-
AST_CLI_DEFINE(handle_softhangup, "Request a hangup on a given channel"),
2056-
20572037
AST_CLI_DEFINE(handle_cli_reload_permissions, "Reload CLI permissions config"),
2058-
20592038
AST_CLI_DEFINE(handle_cli_show_permissions, "Show CLI permissions"),
2060-
20612039
AST_CLI_DEFINE(handle_cli_check_permissions, "Try a permissions config for a user"),
2062-
20632040
AST_CLI_DEFINE(handle_cli_wait_fullybooted, "Wait for Asterisk to be fully booted"),
20642041

20652042
#ifdef HAVE_MALLOC_TRIM
@@ -2068,6 +2045,16 @@ static struct ast_cli_entry cli_cli[] = {
20682045

20692046
};
20702047

2048+
static struct ast_cli_entry cli_channels_cli[] = {
2049+
AST_CLI_DEFINE(handle_nodebugchan_deprecated, "Disable debugging on channel(s)"),
2050+
AST_CLI_DEFINE(handle_chanlist, "Display information on channels"),
2051+
AST_CLI_DEFINE(handle_showcalls, "Display information on calls"),
2052+
AST_CLI_DEFINE(handle_showchan, "Display information on a specific channel"),
2053+
AST_CLI_DEFINE(handle_core_set_debug_channel, "Enable/disable debugging on a channel"),
2054+
AST_CLI_DEFINE(group_show_channels, "Display active channels with group(s)"),
2055+
AST_CLI_DEFINE(handle_softhangup, "Request a hangup on a given channel"),
2056+
};
2057+
20712058
/*!
20722059
* Some regexp characters in cli arguments are reserved and used as separators.
20732060
*/
@@ -2239,6 +2226,11 @@ static void cli_shutdown(void)
22392226
ast_cli_unregister_multiple(cli_cli, ARRAY_LEN(cli_cli));
22402227
}
22412228

2229+
static void cli_channels_shutdown(void)
2230+
{
2231+
ast_cli_unregister_multiple(cli_channels_cli, ARRAY_LEN(cli_channels_cli));
2232+
}
2233+
22422234
/*! \brief initialize the _full_cmd string in * each of the builtins. */
22432235
void ast_builtins_init(void)
22442236
{
@@ -2247,6 +2239,12 @@ void ast_builtins_init(void)
22472239
ast_register_cleanup(cli_shutdown);
22482240
}
22492241

2242+
void ast_cli_channels_init(void)
2243+
{
2244+
ast_cli_register_multiple(cli_channels_cli, ARRAY_LEN(cli_channels_cli));
2245+
ast_register_cleanup(cli_channels_shutdown);
2246+
}
2247+
22502248
/*!
22512249
* match a word in the CLI entry.
22522250
* returns -1 on mismatch, 0 on match of an optional word,

0 commit comments

Comments
 (0)