diff mbox series

[V2] BUG: bootenv functions not available

Message ID 20240704102446.54870-1-stefano.babic@swupdate.org
State Accepted
Headers show
Series [V2] BUG: bootenv functions not available | expand

Commit Message

Stefano Babic July 4, 2024, 10:24 a.m. UTC
commit f8153 introduced a regression bug. The bootenv functions are not
registered anymore and they cannot be called from scripts. They were
handled separately, but after switching to a Lua Session State, there is
no need for this and the function can be added together with the rest of
the interface.

Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
---
 corelib/lua_interface.c | 17 ++++++++++-------
 include/lua_util.h      |  1 -
 2 files changed, 10 insertions(+), 8 deletions(-)

- Changes in V2: push bootenv initialization in lua_handlers_init
	as suggested by C. Storm

--
2.34.1
diff mbox series

Patch

diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index 74590ab6..f2ef849f 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -1489,7 +1489,7 @@  call_handler_exit:
 	return 2;
 }

-int lua_handlers_init(lua_State *L)
+static int lua_handlers_init(lua_State *L, struct dict *bootenv)
 {
 	static const char location[] =
 #if defined(CONFIG_EMBEDDED_LUA_HANDLER)
@@ -1514,6 +1514,12 @@  int lua_handlers_init(lua_State *L)
 		lua_settable(L, -3);
 		lua_pop(L, 2);
 		luaL_requiref(L, "swupdate", luaopen_swupdate, 1 );
+		if (bootenv) {
+			struct dict **udbootenv = lua_newuserdata(L, sizeof(struct dict*));
+			*udbootenv = bootenv;
+			luaL_setfuncs(L, l_swupdate_bootenv, 1);
+			lua_pop(L, 1); /* remove unused copy left on stack */
+		}
 		lua_pop(L, 1); /* remove unused copy left on stack */
 		/* try to load Lua handlers for the swupdate system */
 #if defined(CONFIG_EMBEDDED_LUA_HANDLER)
@@ -1547,12 +1553,9 @@  lua_State *lua_session_init(struct dict *bootenv)
 	lua_setglobal(L, "SWUPDATE_LUA_TYPE"); /* prime L as LUA_TYPE_PEMBSCR */
 	luaL_openlibs(L); /* opens the standard libraries */
 	luaL_requiref(L, "swupdate", luaopen_swupdate, 1 );
-	struct dict **udbootenv = lua_newuserdata(L, sizeof(struct dict*));
-	*udbootenv = bootenv;
-	luaL_setfuncs(L, l_swupdate_bootenv, 1);
-	lua_pop(L, 1); /* remove unused copy left on stack */

-	lua_handlers_init(L);
+	lua_handlers_init(L, bootenv);
+

 	return L;
 }
@@ -1560,7 +1563,7 @@  lua_State *lua_session_init(struct dict *bootenv)
 int lua_init(void)
 {
 	lua_State *L = luaL_newstate();
-	int res = lua_handlers_init(L);
+	int res = lua_handlers_init(L, NULL);
 	print_registered_handlers(false);
 	unregister_session_handlers();
 	lua_close(L);
diff --git a/include/lua_util.h b/include/lua_util.h
index d3dd1cd8..d82a76d2 100644
--- a/include/lua_util.h
+++ b/include/lua_util.h
@@ -26,7 +26,6 @@  int lua_init(void);
 int lua_load_buffer(lua_State *L, const char *buf);
 int lua_parser_fn(lua_State *L, const char *fcn, struct img_type *img);
 int lua_handler_fn(lua_State *L, const char *fcn, const char *parms);
-int lua_handlers_init(lua_State *L);

 int lua_notify_trace(lua_State *L);
 int lua_notify_error(lua_State *L);