Add an error message + comments on open(".") behavior (RhBug:672576)
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 28 Jan 2011 11:15:09 +0000 (13:15 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 28 Jan 2011 11:19:53 +0000 (13:19 +0200)
- 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.

lib/rpmchroot.c
lib/rpmscript.c
lib/transaction.c

index e91be71..81bb5e5 100644 (file)
@@ -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;
        }
     }
index ed52608..3801873 100644 (file)
@@ -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;
index 06e54af..628e4ea 100644 (file)
@@ -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;