- 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.
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;
}
}
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;
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;