<p>N A has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19084">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">cli: Prevent assertions on startup from bad ao2 refs.<br><br>If "core show channels" is run before startup has completed, it<br>is possible for bad ao2 refs to occur because the system is not<br>yet fully initialized. This will lead to an assertion failing.<br><br>To prevent this, initialization of CLI builtins is moved to be<br>later along in the main load sequence. Core CLI commands are<br>loaded at the same time, but channel-related commands are loaded<br>later on.<br><br>ASTERISK-29846 #close<br><br>Change-Id: If6b3cde802876bd738c1b4cf2683bea6ddc615b6<br>---<br>M include/asterisk/_private.h<br>M main/asterisk.c<br>M main/cli.c<br>3 files changed, 43 insertions(+), 23 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/84/19084/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/_private.h b/include/asterisk/_private.h</span><br><span>index 4f81421..65e403f 100644</span><br><span>--- a/include/asterisk/_private.h</span><br><span>+++ b/include/asterisk/_private.h</span><br><span>@@ -37,6 +37,7 @@</span><br><span> int astdb_init(void); /*!< Provided by db.c */</span><br><span> int ast_channels_init(void); /*!< Provided by channel.c */</span><br><span> void ast_builtins_init(void); /*!< Provided by cli.c */</span><br><span style="color: hsl(120, 100%, 40%);">+void ast_cli_channels_init(void); /*!< Provided by cli.c */</span><br><span> int ast_cli_perms_init(int reload); /*!< Provided by cli.c */</span><br><span> void dnsmgr_start_refresh(void); /*!< Provided by dnsmgr.c */</span><br><span> int ast_dns_system_resolver_init(void); /*!< Provided by dns_system_resolver.c */</span><br><span>diff --git a/main/asterisk.c b/main/asterisk.c</span><br><span>index 9bc4c85..9b9fb35 100644</span><br><span>--- a/main/asterisk.c</span><br><span>+++ b/main/asterisk.c</span><br><span>@@ -4266,6 +4266,7 @@</span><br><span> </span><br><span> /* loads the cli_permissions.conf file needed to implement cli restrictions. */</span><br><span> ast_cli_perms_init(0);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli_channels_init(); /* Not always safe to access CLI commands until startup is complete. */</span><br><span> </span><br><span> ast_stun_init();</span><br><span> </span><br><span>diff --git a/main/cli.c b/main/cli.c</span><br><span>index fb4dbc5..5237945 100644</span><br><span>--- a/main/cli.c</span><br><span>+++ b/main/cli.c</span><br><span>@@ -2025,50 +2025,27 @@</span><br><span> static struct ast_cli_entry cli_cli[] = {</span><br><span> AST_CLI_DEFINE(handle_commandmatchesarray, "Returns command matches array"),</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- AST_CLI_DEFINE(handle_nodebugchan_deprecated, "Disable debugging on channel(s)"),</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- AST_CLI_DEFINE(handle_chanlist, "Display information on channels"),</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- AST_CLI_DEFINE(handle_showcalls, "Display information on calls"),</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- AST_CLI_DEFINE(handle_showchan, "Display information on a specific channel"),</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- AST_CLI_DEFINE(handle_core_set_debug_channel, "Enable/disable debugging on a channel"),</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> AST_CLI_DEFINE(handle_debug_category, "Enable/disable debugging categories"),</span><br><span> </span><br><span> AST_CLI_DEFINE(handle_debug, "Set level of debug chattiness"),</span><br><span> AST_CLI_DEFINE(handle_trace, "Set level of trace chattiness"),</span><br><span> AST_CLI_DEFINE(handle_verbose, "Set level of verbose chattiness"),</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- AST_CLI_DEFINE(group_show_channels, "Display active channels with group(s)"),</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> AST_CLI_DEFINE(handle_help, "Display help list, or specific help on a command"),</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> AST_CLI_DEFINE(handle_logger_mute, "Toggle logging output to a console"),</span><br><span> </span><br><span> AST_CLI_DEFINE(handle_modlist, "List modules and info"),</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> AST_CLI_DEFINE(handle_load, "Load a module by name"),</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> AST_CLI_DEFINE(handle_reload, "Reload configuration for a module"),</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> AST_CLI_DEFINE(handle_core_reload, "Global reload"),</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> AST_CLI_DEFINE(handle_unload, "Unload a module by name"),</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> AST_CLI_DEFINE(handle_refresh, "Completely unloads and loads a module by name"),</span><br><span> </span><br><span> AST_CLI_DEFINE(handle_showuptime, "Show uptime information"),</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- AST_CLI_DEFINE(handle_softhangup, "Request a hangup on a given channel"),</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> AST_CLI_DEFINE(handle_cli_reload_permissions, "Reload CLI permissions config"),</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> AST_CLI_DEFINE(handle_cli_show_permissions, "Show CLI permissions"),</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> AST_CLI_DEFINE(handle_cli_check_permissions, "Try a permissions config for a user"),</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> AST_CLI_DEFINE(handle_cli_wait_fullybooted, "Wait for Asterisk to be fully booted"),</span><br><span> </span><br><span> #ifdef HAVE_MALLOC_TRIM</span><br><span>@@ -2077,6 +2054,16 @@</span><br><span> </span><br><span> };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_cli_entry cli_channels_cli[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_CLI_DEFINE(handle_nodebugchan_deprecated, "Disable debugging on channel(s)"),</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_CLI_DEFINE(handle_chanlist, "Display information on channels"),</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_CLI_DEFINE(handle_showcalls, "Display information on calls"),</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_CLI_DEFINE(handle_showchan, "Display information on a specific channel"),</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_CLI_DEFINE(handle_core_set_debug_channel, "Enable/disable debugging on a channel"),</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_CLI_DEFINE(group_show_channels, "Display active channels with group(s)"),</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_CLI_DEFINE(handle_softhangup, "Request a hangup on a given channel"),</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*!</span><br><span> * Some regexp characters in cli arguments are reserved and used as separators.</span><br><span> */</span><br><span>@@ -2248,6 +2235,11 @@</span><br><span> ast_cli_unregister_multiple(cli_cli, ARRAY_LEN(cli_cli));</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void cli_channels_shutdown(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli_unregister_multiple(cli_channels_cli, ARRAY_LEN(cli_channels_cli));</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! \brief initialize the _full_cmd string in * each of the builtins. */</span><br><span> void ast_builtins_init(void)</span><br><span> {</span><br><span>@@ -2256,6 +2248,12 @@</span><br><span> ast_register_cleanup(cli_shutdown);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+void ast_cli_channels_init(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli_register_multiple(cli_channels_cli, ARRAY_LEN(cli_channels_cli));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_register_cleanup(cli_channels_shutdown);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*!</span><br><span> * match a word in the CLI entry.</span><br><span> * returns -1 on mismatch, 0 on match of an optional word,</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19084">change 19084</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/19084"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: If6b3cde802876bd738c1b4cf2683bea6ddc615b6 </div>
<div style="display:none"> Gerrit-Change-Number: 19084 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>