Skip to content
Snippets Groups Projects
Commit ead773f8 authored by Dennis Guse's avatar Dennis Guse
Browse files

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
parent d9b24cce
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment