corelib/lua_interface.c | 39 +++++++++++++++++++++++++++++++++++++++
include/lua_util.h | 7 +++++++
2 files changed, 46 insertions(+)
Chanmges since V2:
- return a table with type / value
diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index f9900e4..e4e4e9f 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -808,6 +808,35 @@ l_umount_exit:
return 1;
}
+static int l_getroot(lua_State *L) {
+ char *rootdev = get_root_device();
+ root_dev_type type = ROOT_DEV_PATH;
+ char **root = NULL;
+ char *value = rootdev;
+
+ root = string_split(rootdev, '=');
+ if (count_string_array((const char **)root) > 1) {
+ if (!strncmp(root[0], "UUID", strlen("UUID"))) {
+ type = ROOT_DEV_UUID;
+ } else if (strncmp(root[0], "PARTUUID", strlen("PARTUUID"))) {
+ type = ROOT_DEV_PARTUUID;
+ } else if (strncmp(root[0], "PARTLABEL", strlen("PARTLABEL"))) {
+ type = ROOT_DEV_PARTLABEL;
+ }
+ value = root[1];
+ }
+ lua_newtable (L);
+ lua_pushstring(L, "type");
+ lua_pushinteger(L, type);
+ lua_settable(L, -3);
+ lua_pushstring(L, "value");
+ lua_pushstring(L, value);
+ lua_settable(L, -3);
+ free(rootdev);
+ free_string_array(root);
+ return 1;
+}
+
static int l_get_bootenv(lua_State *L) {
const char *name = luaL_checkstring(L, 1);
char *value = NULL;
@@ -881,6 +910,7 @@ static const luaL_Reg l_swupdate[] = {
{ "debug", lua_notify_debug },
{ "mount", l_mount },
{ "umount", l_umount },
+ { "getroot", l_getroot },
{ NULL, NULL }
};
@@ -933,6 +963,15 @@ static int luaopen_swupdate(lua_State *L)
lua_push_enum(L, "PROGRESS", SUBPROCESS);
lua_settable(L, -3);
+ /* export the root device type */
+ lua_pushstring(L, "ROOT_DEVICE");
+ lua_newtable (L);
+ lua_push_enum(L, "PATH", ROOT_DEV_PATH);
+ lua_push_enum(L, "UUID", ROOT_DEV_UUID);
+ lua_push_enum(L, "PARTUUID", ROOT_DEV_PARTUUID);
+ lua_push_enum(L, "PARTLABEL", ROOT_DEV_PARTLABEL);
+ lua_settable(L, -3);
+
#ifdef CONFIG_HANDLER_IN_LUA
if (is_type(L, LUA_TYPE_HANDLER)) {
/* register handler-specific functions to swupdate module table. */
diff --git a/include/lua_util.h b/include/lua_util.h
index 1cefc88..088ad2e 100644
--- a/include/lua_util.h
+++ b/include/lua_util.h
@@ -15,6 +15,13 @@
#include "lualib.h"
#include "util.h"
+typedef enum {
+ ROOT_DEV_PATH,
+ ROOT_DEV_UUID,
+ ROOT_DEV_PARTUUID,
+ ROOT_DEV_PARTLABEL
+} root_dev_type;
+
void LUAstackDump (lua_State *L);
int run_lua_script(const char *script, const char *function, char *parms);
lua_State *lua_parser_init(const char *buf, struct dict *bootenv);
--
2.25.1