Give at least some indication of error from fchdir() failures

- Failure to return to current dir is likely to be lethal, at least
  log an error and return a different code for it.
This commit is contained in:
Panu Matilainen 2011-04-19 13:21:36 +03:00
parent b2abe49578
commit 7ea4fcd87f
1 changed files with 5 additions and 3 deletions

View File

@ -58,15 +58,17 @@ static rpmRC runLuaScript(int selinux, ARGV_const_t prefixes,
/* XXX TODO: use cwd from chroot state to save unnecessary open here */
cwd = open(".", O_RDONLY);
if (cwd != -1) {
int xx;
mode_t oldmask = umask(0);
umask(oldmask);
if (chdir("/") == 0 && rpmluaRunScript(lua, script, sname) == 0) {
rc = RPMRC_OK;
}
/* XXX no way to return error from restore meaningfully atm */
xx = fchdir(cwd);
/* This failing would be fatal, return something different for it... */
if (fchdir(cwd)) {
rpmlog(RPMLOG_ERR, _("Unable to restore current directory: %m"));
rc = RPMRC_NOTFOUND;
}
close(cwd);
umask(oldmask);
}