summaryrefslogtreecommitdiff
path: root/pbx
diff options
context:
space:
mode:
authorDennis Guse <dennis.guse@alumni.tu-berlin.de>2016-11-23 21:52:29 +0100
committerDennis Guse <dennis.guse@alumni.tu-berlin.de>2016-11-23 23:15:35 +0100
commitead773f8016f24054e8d17b0509760fd1ddc8fff (patch)
tree1c6e0367c3be9fe43aa6967895357c382e65dd0b /pbx
parentd9b24cce0add96061a0b1e0f135b3148789af5ac (diff)
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
Diffstat (limited to 'pbx')
-rw-r--r--pbx/pbx_lua.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/pbx/pbx_lua.c b/pbx/pbx_lua.c
index 01f468de0..0754990d6 100644
--- a/pbx/pbx_lua.c
+++ b/pbx/pbx_lua.c
@@ -60,7 +60,7 @@ static char *registrar = "pbx_lua";
* 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 @@ static int lua_extension_cmp(lua_State *L)
*
* \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;
@@ -1090,6 +1091,8 @@ static char *lua_read_extensions_file(lua_State *L, long *size)
lua_pushstring(L, strerror(errno));
lua_concat(L, 4);
+ *file_not_openable = 1;
+
return NULL;
}
@@ -1199,10 +1202,14 @@ static int lua_reload_extensions(lua_State *L)
{
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 struct ast_switch lua_switch = {
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 @@ static int load_module(void)
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;