diff --git a/lib/rpmscript.c b/lib/rpmscript.c index 7f49e00ea8..b76c5e8480 100644 --- a/lib/rpmscript.c +++ b/lib/rpmscript.c @@ -36,6 +36,7 @@ struct rpmScript_s { char *body; /* script body */ char *descr; /* description for logging */ rpmscriptFlags flags; /* flags to control operation */ + char *rpmver; /* builder rpm version */ int chroot; /* chrooted script? */ struct scriptNextFileFunc_s *nextFileFunc; /* input function */ }; @@ -179,11 +180,19 @@ static rpmRC runLuaScript(rpmPlugins plugins, ARGV_const_t prefixes, mode_t oldmask = umask(0); umask(oldmask); + lua_pushstring(L, "RPM_PACKAGE_RPMVERSION"); + lua_pushstring(L, script->rpmver); + lua_settable(L, LUA_REGISTRYINDEX); + if (chdir("/") == 0 && rpmluaRunScript(lua, scriptbuf, script->descr, NULL, *argvp) == 0) { rc = RPMRC_OK; } + lua_getfield(L, LUA_REGISTRYINDEX, "RPM_PACKAGE_RPMVERSION"); + lua_pushnil(L); + lua_settable(L, LUA_REGISTRYINDEX); + /* This failing would be fatal, return something different for it... */ if (fchdir(cwd)) { rpmlog(RPMLOG_ERR, _("Unable to restore current directory: %m")); @@ -530,6 +539,7 @@ static rpmScript rpmScriptNew(Header h, rpmTagVal tag, const char *body, script->type = getScriptType(tag); script->flags = getDefFlags(tag) | flags; script->body = (body != NULL) ? xstrdup(body) : NULL; + script->rpmver = headerGetAsString(h, RPMTAG_RPMVERSION); script->chroot = 1; rasprintf(&script->descr, "%%%s%s(%s)", prefix, tag2sln(tag), nevra); @@ -706,6 +716,7 @@ rpmScript rpmScriptFree(rpmScript script) free(script->args); free(script->body); free(script->descr); + free(script->rpmver); delete script->nextFileFunc; delete script; } diff --git a/rpmio/lposix.c b/rpmio/lposix.c index 62fe7db073..4f53a3eb14 100644 --- a/rpmio/lposix.c +++ b/rpmio/lposix.c @@ -333,7 +333,7 @@ static int Pmkfifo(lua_State *L) /** mkfifo(path) */ static int Pexec(lua_State *L) /** exec(path,[args]) */ { - check_deprecated(L, "posix.exec"); + check_deprecated(L, "posix.exec", "4.20.0"); const char *path = luaL_checkstring(L, 1); int i,n=lua_gettop(L); @@ -354,7 +354,7 @@ static int Pexec(lua_State *L) /** exec(path,[args]) */ static int Pfork(lua_State *L) /** fork() */ { - check_deprecated(L, "posix.fork"); + check_deprecated(L, "posix.fork", "4.20.0"); pid_t pid = fork(); if (pid == 0) { @@ -366,7 +366,7 @@ static int Pfork(lua_State *L) /** fork() */ static int Pwait(lua_State *L) /** wait([pid]) */ { - check_deprecated(L, "posix.wait"); + check_deprecated(L, "posix.wait", "4.20.0"); pid_t pid = luaL_optinteger(L, 1, -1); return pushresult(L, waitpid(pid, NULL, 0), NULL); diff --git a/rpmio/lposix.h b/rpmio/lposix.h index b9874cb060..f1f210edc7 100644 --- a/rpmio/lposix.h +++ b/rpmio/lposix.h @@ -4,7 +4,7 @@ #include RPM_GNUC_INTERNAL -void check_deprecated(lua_State *L, const char *func); +void check_deprecated(lua_State *L, const char *func, const char *deprecated_in); RPM_GNUC_INTERNAL int luaopen_posix (lua_State *L); diff --git a/rpmio/rpmlua.c b/rpmio/rpmlua.c index 8996328f1a..36d7458dee 100644 --- a/rpmio/rpmlua.c +++ b/rpmio/rpmlua.c @@ -759,7 +759,7 @@ static int rpm_redirect2null(lua_State *L) { int target_fd, fd, r, e; - check_deprecated(L, "rpm.redirect2null"); + check_deprecated(L, "rpm.redirect2null", "4.20.0"); if (!_rpmlua_have_forked) return luaL_error(L, "redirect2null not permitted in this context"); @@ -1365,8 +1365,22 @@ static int luaopen_rpm(lua_State *L) return 1; } -void check_deprecated(lua_State *L, const char *func) +void check_deprecated(lua_State *L, const char *func, const char *deprecated_in) { - fprintf(stderr, - "warning: %s(): .fork(), .exec(), .wait() and .redirect2null() are deprecated, use rpm.spawn() or rpm.execute() instead\n", func); + int warn = 1; + lua_getfield(L, LUA_REGISTRYINDEX, "RPM_PACKAGE_RPMVERSION"); + if (lua_isstring(L, -1)) { + rpmver v1 = rpmverParse(lua_tostring(L, -1)); + rpmver v2 = rpmverParse(deprecated_in); + if (v1 && v2 && rpmverCmp(v1, v2) < 0) + warn = 0; + rpmverFree(v2); + rpmverFree(v1); + } + lua_pop(L, 1); + + if (warn) { + fprintf(stderr, + "warning: %s(): .fork(), .exec(), .wait() and .redirect2null() are deprecated, use rpm.spawn() or rpm.execute() instead\n", func); + } } diff --git a/tests/data/RPMS/luafork-1.0-1.noarch.rpm b/tests/data/RPMS/luafork-1.0-1.noarch.rpm new file mode 100644 index 0000000000..a7cd262e79 Binary files /dev/null and b/tests/data/RPMS/luafork-1.0-1.noarch.rpm differ diff --git a/tests/data/SPECS/luafork.spec b/tests/data/SPECS/luafork.spec new file mode 100644 index 0000000000..b67bcd887a --- /dev/null +++ b/tests/data/SPECS/luafork.spec @@ -0,0 +1,22 @@ +Name: luafork +Version: 1.0 +Release: 1 +License: Public domain +Summary: Testing Lua fork behavior +BuildArch: noarch + +%description +%{summary} + +%pre -p +local pid = posix.fork() +if pid == 0 then + io.stdout:write("child\n") + os.exit(0) +elseif pid > 0 then + posix.wait(pid) +else + io.stderr:write("fork failed") +end + +%files diff --git a/tests/rpmscript.at b/tests/rpmscript.at index 36181fd090..23107193b4 100644 --- a/tests/rpmscript.at +++ b/tests/rpmscript.at @@ -801,3 +801,31 @@ runroot_other test -f /tmp/scriptwrite.log []) RPMTEST_CLEANUP +AT_SETUP([deprecated Lua functions]) +AT_KEYWORDS([script lua]) + +# binary pre-built on rpm 4.18 should emit no warnings +RPMTEST_CHECK([ +RPMDB_INIT +runroot rpm -U /data/RPMS/luafork-1.0-1.noarch.rpm +], +[0], +[child +], +[]) + +RPMTEST_CHECK([ +RPMDB_INIT + +runroot rpmbuild -bb --quiet /data/SPECS/luafork.spec +runroot rpm -U /build/RPMS/noarch/luafork-1.0-1.noarch.rpm +], +[0], +[child +], +[warning: posix.fork(): .fork(), .exec(), .wait() and .redirect2null() are deprecated, use rpm.spawn() or rpm.execute() instead +warning: posix.wait(): .fork(), .exec(), .wait() and .redirect2null() are deprecated, use rpm.spawn() or rpm.execute() instead +]) + +RPMTEST_CLEANUP +