Give at least some indication of error from fchdir() failures
authorPanu Matilainen <pmatilai@redhat.com>
Tue, 19 Apr 2011 10:21:36 +0000 (13:21 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Tue, 19 Apr 2011 10:21:36 +0000 (13:21 +0300)
- Failure to return to current dir is likely to be lethal, at least
  log an error and return a different code for it.

lib/rpmscript.c

index 5568821..905d1cf 100644 (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);
     }