[Asterisk-code-review] app_reload: New Reload application (asterisk[16])

Friendly Automation asteriskteam at digium.com
Thu Jul 15 10:05:22 CDT 2021


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/15962 )

Change subject: app_reload: New Reload application
......................................................................

app_reload: New Reload application

Adds an application to reload modules
from within the dialplan.

ASTERISK-29454

Change-Id: Ic8ab025d8b38dd525b872b41c465c999c5810774
---
A apps/app_reload.c
A doc/CHANGES-staging/app_reload.txt
2 files changed, 114 insertions(+), 0 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, approved
  Friendly Automation: Approved for Submit



diff --git a/apps/app_reload.c b/apps/app_reload.c
new file mode 100644
index 0000000..16bcd63
--- /dev/null
+++ b/apps/app_reload.c
@@ -0,0 +1,110 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2021, Naveen Albert
+ *
+ * Naveen Albert <asterisk at phreaknet.org>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Reload Asterisk modules
+ *
+ * \author Naveen Albert <asterisk at phreaknet.org>
+ *
+ * \ingroup applications
+ */
+
+/*** MODULEINFO
+	<support_level>extended</support_level>
+ ***/
+
+#include "asterisk.h"
+
+#include "asterisk/logger.h"
+#include "asterisk/channel.h"
+#include "asterisk/pbx.h"
+#include "asterisk/module.h"
+#include "asterisk/app.h"
+
+/*** DOCUMENTATION
+	<application name="Reload" language="en_US">
+		<synopsis>
+			Reloads an Asterisk module, blocking the channel until the reload has completed.
+		</synopsis>
+		<syntax>
+			<parameter name="module" required="false">
+				<para>The full name(s) of the target module(s) or resource(s) to reload.
+				If omitted, everything will be reloaded.</para>
+				<para>The full names MUST be specified (e.g. <literal>chan_iax2</literal>
+				to reload IAX2 or <literal>pbx_config</literal> to reload the dialplan.</para>
+			</parameter>
+		</syntax>
+		<description>
+			<para>Reloads the specified (or all) Asterisk modules and reports success or failure.
+			Success is determined by each individual module, and if all reloads are successful,
+			that is considered an aggregate success. If multiple modules are specified and any
+			module fails, then FAILURE will be returned. It is still possible that other modules
+			did successfully reload, however.</para>
+			<para>Sets <variable>RELOADSTATUS</variable> to one of the following values:</para>
+			<variablelist>
+				<variable name="RELOADSTATUS">
+					<value name="SUCCESS">
+						Specified module(s) reloaded successfully.
+					</value>
+					<value name="FAILURE">
+						Some or all of the specified modules failed to reload.
+					</value>
+				</variable>
+			</variablelist>
+		</description>
+	</application>
+ ***/
+
+static char *app = "Reload";
+
+static int reload_exec(struct ast_channel *chan, const char *data)
+{
+	char *targets, *target = NULL;
+	enum ast_module_reload_result res = AST_MODULE_RELOAD_SUCCESS;
+
+	targets = ast_strdupa(data);
+	ast_autoservice_start(chan);
+	if (ast_strlen_zero(targets)) { /* Reload everything */
+		res = ast_module_reload(targets);
+	} else {
+		while((target = ast_strsep(&targets, ',', AST_STRSEP_ALL))) {
+			res |= ast_module_reload(target);
+		}
+	}
+	ast_autoservice_stop(chan);
+
+	if (res == AST_MODULE_RELOAD_SUCCESS) {
+		pbx_builtin_setvar_helper(chan, "RELOADSTATUS", "SUCCESS");
+	} else {
+		pbx_builtin_setvar_helper(chan, "RELOADSTATUS", "FAILURE");
+	}
+	return 0;
+}
+
+static int unload_module(void)
+{
+	return ast_unregister_application(app);
+}
+
+static int load_module(void)
+{
+	return ast_register_application_xml(app, reload_exec);
+}
+
+AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "Reload module(s)");
diff --git a/doc/CHANGES-staging/app_reload.txt b/doc/CHANGES-staging/app_reload.txt
new file mode 100644
index 0000000..308db15
--- /dev/null
+++ b/doc/CHANGES-staging/app_reload.txt
@@ -0,0 +1,4 @@
+Subject: New Reload application
+
+Adds an application to reload modules
+

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15962
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Ic8ab025d8b38dd525b872b41c465c999c5810774
Gerrit-Change-Number: 15962
Gerrit-PatchSet: 8
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210715/929a128a/attachment.html>


More information about the asterisk-code-review mailing list