From: Felipe Huici Date: Wed, 12 Feb 2020 18:51:00 +0000 (+0100) Subject: Fix broken behaviour when given append parameter. X-Git-Tag: RELEASE-0.4^0 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=b33791cc422f2e5419a1e98201aa13567a538a01;p=unikraft%2Flibs%2Flua.git Fix broken behaviour when given append parameter. This patch makes it so that Lua now goes straight into interactive mode when not given initrd as a parameter; previosuly it was assuming that the --append parameter was a file name to be read and executed, which was broken. Signed-off-by: Felipe Huici Reviewed-by: Simon Kuenzer --- diff --git a/Makefile.uk b/Makefile.uk index 3c3d05a..4a855ab 100644 --- a/Makefile.uk +++ b/Makefile.uk @@ -39,7 +39,7 @@ LIBLUA_SRCS-$(CONFIG_LIBLUA_MAIN_FUNCTION) += $(LIBLUA_BASE)/main.c ################################################################################ # Library flags ################################################################################ -LIBLUA_SUPPRESS_FLAGS += -Wno-implicit-function-declaration +LIBLUA_SUPPRESS_FLAGS += -Wno-implicit-function-declaration -Wno-unused-function LIBLUA_FLAGS += -DLUA_COMPAT_5_2 LIBLUA_CFLAGS-y += $(LIBLUA_FLAGS) $(LIBLUA_SUPPRESS_FLAGS) diff --git a/patches/0001-add-initrd-rename-entry-point.patch b/patches/0001-add-initrd-rename-entry-point.patch deleted file mode 100644 index 135a0c4..0000000 --- a/patches/0001-add-initrd-rename-entry-point.patch +++ /dev/null @@ -1,42 +0,0 @@ ---- a/src/lua.c 2017-04-19 19:29:57.000000000 +0200 -+++ b/src/lua.c 2019-09-03 13:36:09.437807890 +0200 -@@ -6,6 +6,8 @@ - - #define lua_c - -+#include -+ - #include "lprefix.h" - - -@@ -555,6 +557,9 @@ - int argc = (int)lua_tointeger(L, 1); - char **argv = (char **)lua_touserdata(L, 2); - int script; -+ struct ukplat_memregion_desc img; -+ char *cstr; -+ - int args = collectargs(argv, &script); - luaL_checkversion(L); /* check that interpreter has correct version */ - if (argv[0] && argv[0][0]) progname = argv[0]; -@@ -581,6 +586,11 @@ - return 0; - if (args & has_i) /* -i option? */ - doREPL(L); /* do read-eval-print loop */ -+ /* see if script is available from initrd */ -+ else if (ukplat_memregion_find_initrd0(&img) >= 0) { -+ cstr = (char *)img.base; -+ dostring(L, cstr, "initrd"); -+ } - else if (script == argc && !(args & (has_e | has_v))) { /* no arguments? */ - if (lua_stdin_is_tty()) { /* running in interactive mode? */ - print_version(); -@@ -593,7 +603,7 @@ - } - - --int main (int argc, char **argv) { -+int lua_main (int argc, char **argv) { - int status, result; - lua_State *L = luaL_newstate(); /* create state */ - if (L == NULL) { diff --git a/patches/0001-lua-main-add-initrd.patch b/patches/0001-lua-main-add-initrd.patch new file mode 100644 index 0000000..ecfb8f0 --- /dev/null +++ b/patches/0001-lua-main-add-initrd.patch @@ -0,0 +1,53 @@ +--- a/src/lua.c 2017-04-19 19:29:57.000000000 +0200 ++++ b/src/lua.c 2020-02-12 19:38:09.704428160 +0100 +@@ -6,6 +6,8 @@ + + #define lua_c + ++#include ++ + #include "lprefix.h" + + +@@ -555,6 +557,9 @@ + int argc = (int)lua_tointeger(L, 1); + char **argv = (char **)lua_touserdata(L, 2); + int script; ++ struct ukplat_memregion_desc img; ++ char *cstr; ++ + int args = collectargs(argv, &script); + luaL_checkversion(L); /* check that interpreter has correct version */ + if (argv[0] && argv[0][0]) progname = argv[0]; +@@ -576,24 +581,23 @@ + } + if (!runargs(L, argv, script)) /* execute arguments -e and -l */ + return 0; /* something failed */ +- if (script < argc && /* execute main script (if there is one) */ +- handle_script(L, argv + script) != LUA_OK) +- return 0; + if (args & has_i) /* -i option? */ + doREPL(L); /* do read-eval-print loop */ +- else if (script == argc && !(args & (has_e | has_v))) { /* no arguments? */ +- if (lua_stdin_is_tty()) { /* running in interactive mode? */ ++ /* see if script is available from initrd */ ++ else if (ukplat_memregion_find_initrd0(&img) >= 0) { ++ cstr = (char *)img.base; ++ dostring(L, cstr, "initrd"); ++ } ++ else { + print_version(); + doREPL(L); /* do read-eval-print loop */ +- } +- else dofile(L, NULL); /* executes stdin as a file */ + } + lua_pushboolean(L, 1); /* signal no errors */ + return 1; + } + + +-int main (int argc, char **argv) { ++int lua_main (int argc, char **argv) { + int status, result; + lua_State *L = luaL_newstate(); /* create state */ + if (L == NULL) {