diff mbox series

Lua: make handler not found message more pleasant

Message ID 20170929134354.18335-1-christian.storm@siemens.com
State Changes Requested
Headers show
Series Lua: make handler not found message more pleasant | expand

Commit Message

Storm, Christian Sept. 29, 2017, 1:43 p.m. UTC
Currently, a stack dump is printed on a failed
require("swupdate_handlers") which is thereafter
clarified as being no error.
Make this message more friendly.

Only package.path is shown as it's assumed that
custom Lua handlers won't be written as a .so.
In this case, they may be written as a regular
handler in C in the first place.

Signed-off-by: Christian Storm <christian.storm@siemens.com>
---
 core/swupdate.c         |  3 +--
 corelib/lua_interface.c | 20 +++++++++++---------
 2 files changed, 12 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/core/swupdate.c b/core/swupdate.c
index a9c71cf..62db84a 100644
--- a/core/swupdate.c
+++ b/core/swupdate.c
@@ -822,8 +822,7 @@  int main(int argc, char **argv)
 		}
 	}
 
-	if (lua_handlers_init())
-		printf("\nCustom handlers not found, no error, skipping...\n\n");
+	lua_handlers_init();
 
 	if(!get_hw_revision(&swcfg.hw))
 		printf("Running on %s Revision %s\n", swcfg.hw.boardname, swcfg.hw.revision);
diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index 5f48726..0553c1d 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -472,22 +472,24 @@  int lua_handlers_init(void)
 {
 	int ret = -1;
 
-	gL = NULL;
 	gL = luaL_newstate();
 	if (gL) {
-		printf("Searching for custom Lua handlers :");
 		/* load standard libraries */
 		luaL_openlibs(gL);
 		luaL_requiref( gL, "swupdate", luaopen_swupdate, 1 );
 		/* try to load lua handlers for the swupdate system */
-		ret = luaL_dostring(gL,"require (\"swupdate_handlers\")");
-		if(ret != 0)
-		{
-			TRACE("No lua handler found:\n%s", lua_tostring(gL, -1));
-		} else
-			printf(" OK\n");
+		if ((ret = luaL_dostring(gL, "require (\"swupdate_handlers\")")) != 0) {
+			INFO("No Lua handler(s) found.");
+			if (luaL_dostring(gL, "return package.path:gsub(';','\\n'):gsub('?','swupdate_handlers')") == 0) {
+				lua_pop(gL, 1);
+				TRACE("Lua handler search path:\n%s", lua_tostring(gL, -1));
+				lua_pop(gL, 1);
+			}
+		} else {
+			INFO("Lua handler(s) found.");
+		}
 	} else	{
-		printf ("Unable to register Lua context for callbacks\n");
+		WARN("Unable to register Lua context for callbacks\n");
 	}
 
 	return ret;