diff mbox series

Lua: Fix Lua session handlers

Message ID 6775FF21-CC3C-4C34-A749-690180F6C1B2@siemens.com
State Accepted
Headers show
Series Lua: Fix Lua session handlers | expand

Commit Message

Storm, Christian June 9, 2024, 7:28 p.m. UTC
In order to promote a Lua session state from embedded script type to
handler type, the swupdate module must be force-reloaded.

With parser/parser.c::parser()
-> corelib/lua_interface.c::lua_init()
   -> corelib/lua_interface.c::lua_handlers_init(),
the session Lua state is primed LUA_TYPE_PEMBSCR in lua_init() and
since package.loaded["swupdate"] == nil, the swupdate module is
loaded with corelib/lua_interface.c::luaopen_swupdate() skipping
the Lua handler specifics. Now, promoting the Lua state from embedded
script to handler type in lua_handlers_init() needs to force-reload
the swupdate module as now package.loaded["swupdate"] ~= nil and hence
a require("swupdate") has no effect.

Setting package.loaded["swupdate"] = nil has no effect if the swupdate
module is not yet loaded.

Signed-off-by: Christian Storm <christian.storm@siemens.com>
---
 corelib/lua_interface.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index d913b654..43930daa 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -1538,6 +1538,14 @@  int lua_handlers_init(lua_State *L)
 		lua_setglobal(L, "SWUPDATE_LUA_TYPE");
 		/* load standard libraries */
 		luaL_openlibs(L);
+		/* load / fore-reload swupdate module */
+		lua_getglobal(L, "package");
+		lua_pushliteral(L, "loaded");
+		lua_gettable(L, -2);
+		lua_pushstring(L, "swupdate");
+		lua_pushnil(L);
+		lua_settable(L, -3);
+		lua_pop(L, 2);
 		luaL_requiref(L, "swupdate", luaopen_swupdate, 1 );
 		lua_pop(L, 1); /* remove unused copy left on stack */