commit 431afe5167675a89682eb7e07baa3a627ceb8770 Author: Panu Matilainen Date: Fri Jan 28 13:15:09 2011 +0200 Add an error message + comments on open(".") behavior (RhBug:672576) - Bail out early and complain if current directory can't be open()'ed, as we'll need it for reliable cwd restoration after running Lua scripts. - Technically we'd only need open(".") succeeding for chroot operations and running Lua-scripts, but there's no easy way to determine whether a transaction will run Lua-scripts. They could be in-db triggers which will only be evaluated in the middle of transaction, better to fail early for consistent behavior. (cherry picked from commit fbdfe8e5bf1ef7044de7a14cff9205c4d845f90b) diff --git a/lib/rpmchroot.c b/lib/rpmchroot.c index e91be71..81bb5e5 100644 --- a/lib/rpmchroot.c +++ b/lib/rpmchroot.c @@ -40,6 +40,7 @@ int rpmChrootSet(const char *rootDir) rootState.rootDir = rstrdup(rootDir); rootState.cwd = open(".", O_RDONLY); if (rootState.cwd < 0) { + rpmlog(RPMLOG_ERR, _("Unable to open current directory: %m\n")); rc = -1; } } diff --git a/lib/rpmscript.c b/lib/rpmscript.c index ed52608..3801873 100644 --- a/lib/rpmscript.c +++ b/lib/rpmscript.c @@ -55,6 +55,7 @@ static rpmRC runLuaScript(int selinux, ARGV_const_t prefixes, rpmluaPop(lua); /* Lua scripts can change our cwd and umask, save and restore */ + /* XXX TODO: use cwd from chroot state to save unnecessary open here */ cwd = open(".", O_RDONLY); if (cwd != -1) { int xx; diff --git a/lib/transaction.c b/lib/transaction.c index 06e54af..628e4ea 100644 --- a/lib/transaction.c +++ b/lib/transaction.c @@ -1260,7 +1260,12 @@ static int rpmtsSetup(rpmts ts, rpmprobFilterFlags ignoreSet) rpmtsSELabelInit(ts, selinux_file_context_path()); } - /* XXX Make sure the database is open RDWR for package install/erase. */ + /* + * Make sure the database is open RDWR for package install/erase. + * Note that we initialize chroot state here even if it's just "/" as + * this ensures we can successfully perform open(".") which is + * required to reliably restore cwd after Lua scripts. + */ if (rpmtsOpenDB(ts, dbmode) || rpmChrootSet(rpmtsRootDir(ts))) return -1;