diff mbox series

[v2] Lua: make handler not found message more pleasant

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

Commit Message

Storm, Christian Sept. 29, 2017, 2:52 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 +++++++++++---------
 include/lua_util.h      |  2 +-
 3 files changed, 13 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/core/swupdate.c b/core/swupdate.c
index b490871..f1140d2 100644
--- a/core/swupdate.c
+++ b/core/swupdate.c
@@ -850,8 +850,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;
diff --git a/include/lua_util.h b/include/lua_util.h
index d7e8754..0667b2b 100644
--- a/include/lua_util.h
+++ b/include/lua_util.h
@@ -44,7 +44,7 @@  static inline lua_State *lua_parser_init(const char __attribute__ ((__unused__))
 static inline int lua_parser_fn(lua_State __attribute__ ((__unused__)) *L,
 			 const char __attribute__ ((__unused__)) *fcn,
 			 struct img_type __attribute__ ((__unused__)) *img) { return -1; }
-#define lua_handlers_init(void)  (0) 
+#define lua_handlers_init(void) { return 0; }
 #endif