lua: fall through failed lua scripts
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 16 Sep 2013 12:36:43 +0000 (15:36 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Wed, 11 Jun 2014 14:48:03 +0000 (17:48 +0300)
Just print a warning. In addition, set Lua output buffer to contain
string "1" for failed scripts.

Change-Id: Id0478b64ac942fe6839f3cd8c9bb75c9b15382b2
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
rpmio/macro.c
rpmio/rpmlua.c

index 0876ea8..c1bb043 100644 (file)
@@ -1233,6 +1233,7 @@ expandMacro(MacroBuf mb, const char *src, size_t slen)
        }
 
 #ifdef WITH_LUA
+#define LUA_FAILURE_OUTPUT "1"
        if (STREQ("lua", f, fn)) {
                rpmlua lua = NULL; /* Global state. */
                const char *ls = s+sizeof("{lua:")-1;
@@ -1242,9 +1243,14 @@ expandMacro(MacroBuf mb, const char *src, size_t slen)
                memcpy(scriptbuf, ls, lse-ls);
                scriptbuf[lse-ls] = '\0';
                rpmluaPushPrintBuffer(lua);
-               if (rpmluaRunScript(lua, scriptbuf, NULL) == -1)
-                   rc = 1;
-               printbuf = rpmluaPopPrintBuffer(lua);
+               if (rpmluaRunScript(lua, scriptbuf, NULL) == -1) {
+                       printbuf = rpmluaPopPrintBuffer(lua);
+                       rpmlog(RPMLOG_WARNING, _("lua: using fallback output '%s'\n"), LUA_FAILURE_OUTPUT);
+                       printbuf = (char *)xcalloc(1, sizeof(LUA_FAILURE_OUTPUT));
+                       strcpy(printbuf, LUA_FAILURE_OUTPUT);
+               } else {
+                       printbuf = rpmluaPopPrintBuffer(lua);
+               }
                if (printbuf) {
                    mbAppendStr(mb, printbuf);
                    free(printbuf);
index 8e6841d..53c0cf9 100644 (file)
@@ -530,7 +530,7 @@ int rpmluaRunScript(rpmlua _lua, const char *script, const char *name)
        lua_pop(L, 1);
        ret = -1;
     } else if (lua_pcall(L, 0, 0, 0) != 0) {
-       rpmlog(RPMLOG_ERR, _("lua script failed: %s\n"),
+       rpmlog(RPMLOG_WARNING, _("lua script failed: %s\n"),
                 lua_tostring(L, -1));
        lua_pop(L, 1);
        ret = -1;