<p>Joshua Colp <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/17812">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
George Joseph: Looks good to me, approved
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">cli: Add module refresh command<br><br>Adds a command to the CLI to unload and then<br>load a module. This makes it easier to perform<br>these operations which are often done<br>subsequently to load a new version of a module.<br><br>"module reload" already refers to reloading of<br>configuration, so the name "refresh" is chosen<br>instead.<br><br>ASTERISK-29807 #close<br><br>Change-Id: I595f6f11774a0de2565a1fba38da22309ce93a2c<br>---<br>A doc/CHANGES-staging/cli_refresh.txt<br>M main/cli.c<br>2 files changed, 39 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/cli_refresh.txt b/doc/CHANGES-staging/cli_refresh.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..82bcd23</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/cli_refresh.txt</span><br><span>@@ -0,0 +1,5 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: cli</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+The "module refresh" command has been added,</span><br><span style="color: hsl(120, 100%, 40%);">+which allows unloading and then loading a</span><br><span style="color: hsl(120, 100%, 40%);">+module with a single command.</span><br><span>diff --git a/main/cli.c b/main/cli.c</span><br><span>index 3b4c958..fb4dbc5 100644</span><br><span>--- a/main/cli.c</span><br><span>+++ b/main/cli.c</span><br><span>@@ -805,6 +805,38 @@</span><br><span> return CLI_SUCCESS;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static char *handle_refresh(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ /* "module refresh <mod>" */</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (cmd) {</span><br><span style="color: hsl(120, 100%, 40%);">+ case CLI_INIT:</span><br><span style="color: hsl(120, 100%, 40%);">+ e->command = "module refresh";</span><br><span style="color: hsl(120, 100%, 40%);">+ e->usage =</span><br><span style="color: hsl(120, 100%, 40%);">+ "Usage: module refresh <module name>\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ " Unloads and loads the specified module into Asterisk.\n";</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ case CLI_GENERATE:</span><br><span style="color: hsl(120, 100%, 40%);">+ if (a->pos != e->args) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_module_helper(a->line, a->word, a->pos, a->n, a->pos, AST_MODULE_HELPER_UNLOAD);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (a->argc != e->args + 1) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return CLI_SHOWUSAGE;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_unload_resource(a->argv[e->args], AST_FORCE_SOFT)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, "Unable to unload resource %s\n", a->argv[e->args]);</span><br><span style="color: hsl(120, 100%, 40%);">+ return CLI_FAILURE;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_load_resource(a->argv[e->args])) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, "Unable to load module %s\n", a->argv[e->args]);</span><br><span style="color: hsl(120, 100%, 40%);">+ return CLI_FAILURE;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, "Unloaded and loaded %s\n", a->argv[e->args]);</span><br><span style="color: hsl(120, 100%, 40%);">+ return CLI_SUCCESS;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static char *handle_unload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)</span><br><span> {</span><br><span> /* "module unload mod_1 [mod_2 .. mod_N]" */</span><br><span>@@ -2025,6 +2057,8 @@</span><br><span> </span><br><span> AST_CLI_DEFINE(handle_unload, "Unload a module by name"),</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ AST_CLI_DEFINE(handle_refresh, "Completely unloads and loads a module by name"),</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> AST_CLI_DEFINE(handle_showuptime, "Show uptime information"),</span><br><span> </span><br><span> AST_CLI_DEFINE(handle_softhangup, "Request a hangup on a given channel"),</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/17812">change 17812</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/+/17812"/><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: I595f6f11774a0de2565a1fba38da22309ce93a2c </div>
<div style="display:none"> Gerrit-Change-Number: 17812 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>