Message ID | 20170929145903.23007-1-christian.storm@siemens.com |
---|---|
State | Accepted |
Headers | show |
Series | [v3] Lua: make handler not found message more pleasant | expand |
On 29/09/2017 16:59, Christian Storm wrote: > 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 --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..7842cc5 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) > +static inline int lua_handlers_init(void) { return 0; } > #endif > > > Applied to -master, thanks ! Best regards, Stefano Babic
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..7842cc5 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) +static inline int lua_handlers_init(void) { return 0; } #endif
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(-)