{
rpmVSFlags vsflags, ovsflags;
int ec = 0, xx;
+ int dirfd = -1;
const char * rootDir = rpmtsRootDir(ts);
FD_t scriptFd = fdDup(STDOUT_FILENO);
rpmtsOpenDB(ts, O_RDONLY);
rpmdbOpenAll(rpmtsGetRdb(ts));
if (rootDir && !rstreq(rootDir, "/")) {
- if (chroot(rootDir) == -1) {
+ dirfd = open(".", O_RDONLY);
+ if (dirfd == -1 || chdir("/") == -1 || chroot(rootDir) == -1) {
rpmlog(RPMLOG_ERR, _("Unable to change root directory: %m\n"));
ec = 1;
goto exit;
if (rpmtsChrootDone(ts)) {
/* only done if previous chroot succeeded, assume success */
xx = chroot(".");
+ xx = fchdir(dirfd);
rpmtsSetChrootDone(ts, 0);
}
exit:
Fclose(scriptFd);
+ if (dirfd >= 0) close(dirfd);
return ec;
}