[asterisk-commits] pbx lua: On configuration errors report module load failure ... (asterisk[master])
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Dec 2 05:36:27 CST 2016
Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/4493 )
Change subject: pbx_lua: On configuration errors report module load failure instead of decline.
......................................................................
pbx_lua: On configuration errors report module load failure instead of decline.
Switched from AST_MODULE_LOAD_DECLINE to AST_MODULE_LOAD_FAILURE.
Therefore, if pbx_lua fails to load and pbx_lua is marked as required,
Asterisk exits as expected.
If extensions.lua cannot be opened, AST_MODULE_LOAD_DECLINE is reported.
Change-Id: I8e5a0037e69b41743db60c568541ebb2f52a7a8f
---
M pbx/pbx_lua.c
1 file changed, 21 insertions(+), 7 deletions(-)
Approvals:
George Joseph: Looks good to me, approved
Anonymous Coward #1000019: Verified
Joshua Colp: Looks good to me, but someone else must approve
diff --git a/pbx/pbx_lua.c b/pbx/pbx_lua.c
index 01f468d..0754990 100644
--- a/pbx/pbx_lua.c
+++ b/pbx/pbx_lua.c
@@ -60,7 +60,7 @@
* applications might return */
#define LUA_GOTO_DETECTED 5
-static char *lua_read_extensions_file(lua_State *L, long *size);
+static char *lua_read_extensions_file(lua_State *L, long *size, int *file_not_openable);
static int lua_load_extensions(lua_State *L, struct ast_channel *chan);
static int lua_reload_extensions(lua_State *L);
static void lua_free_extensions(void);
@@ -1070,12 +1070,13 @@
*
* \param L the lua_State to use
* \param size a pointer to store the size of the buffer
+ * \param file_not_openable a pointer to store if config file could be opened
*
* \note The caller is expected to free the buffer at some point.
*
* \return a pointer to the buffer
*/
-static char *lua_read_extensions_file(lua_State *L, long *size)
+static char *lua_read_extensions_file(lua_State *L, long *size, int *file_not_openable)
{
FILE *f;
int error_func;
@@ -1089,6 +1090,8 @@
lua_pushstring(L, "' for reading: ");
lua_pushstring(L, strerror(errno));
lua_concat(L, 4);
+
+ *file_not_openable = 1;
return NULL;
}
@@ -1199,10 +1202,14 @@
{
long size = 0;
char *data = NULL;
+ int file_not_openable = 0;
luaL_openlibs(L);
- if (!(data = lua_read_extensions_file(L, &size))) {
+ if (!(data = lua_read_extensions_file(L, &size, &file_not_openable))) {
+ if (file_not_openable) {
+ return -1;
+ }
return 1;
}
@@ -1621,17 +1628,24 @@
static int load_or_reload_lua_stuff(void)
{
int res = AST_MODULE_LOAD_SUCCESS;
+ int loaded = 0;
lua_State *L = luaL_newstate();
if (!L) {
ast_log(LOG_ERROR, "Error allocating lua_State, no memory\n");
- return AST_MODULE_LOAD_DECLINE;
+ return AST_MODULE_LOAD_FAILURE;
}
- if (lua_reload_extensions(L)) {
+ loaded = lua_reload_extensions(L);
+ if (loaded) {
const char *error = lua_tostring(L, -1);
ast_log(LOG_ERROR, "Error loading extensions.lua: %s\n", error);
- res = AST_MODULE_LOAD_DECLINE;
+
+ if (loaded < 0) {
+ res = AST_MODULE_LOAD_DECLINE;
+ } else {
+ res = AST_MODULE_LOAD_FAILURE;
+ }
}
if (!res) {
@@ -1664,7 +1678,7 @@
if (ast_register_switch(&lua_switch)) {
ast_log(LOG_ERROR, "Unable to register LUA PBX switch\n");
- return AST_MODULE_LOAD_DECLINE;
+ return AST_MODULE_LOAD_FAILURE;
}
return AST_MODULE_LOAD_SUCCESS;
--
To view, visit https://gerrit.asterisk.org/4493
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8e5a0037e69b41743db60c568541ebb2f52a7a8f
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Dennis Guse <dennis.guse at alumni.tu-berlin.de>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Dennis Guse <dennis.guse at alumni.tu-berlin.de>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
More information about the asterisk-commits
mailing list