[Rpm-maint] [Suse patch] Lua-script cwd issues

Panu Matilainen pmatilai at redhat.com
Tue May 22 07:43:15 UTC 2007


Cwd isn't consistently set for Lua-scripts, this patch fixes it. For full 
details see 
https://lists.dulug.duke.edu/pipermail/rpm-devel/2006-August/001475.html

Already applied.

 	- Panu -

Index: lib/psm.c
===================================================================
--- lib/psm.c.orig
+++ lib/psm.c
@@ -502,6 +502,8 @@ static rpmRC runLuaScript(rpmpsm psm, He
  {
      const rpmts ts = psm->ts;
      int rootFd = -1;
+    int chroot_done;
+    const char *rootDir;
      const char *n, *v, *r;
      rpmRC rc = RPMRC_OK;
      int i;
@@ -511,20 +513,27 @@ static rpmRC runLuaScript(rpmpsm psm, He

      xx = headerNVR(h, &n, &v, &r);

-    if (!rpmtsChrootDone(ts)) {
-	const char *rootDir = rpmtsRootDir(ts);
-	xx = chdir("/");
+    chroot_done = rpmtsChrootDone(ts);
+    rootDir = rpmtsRootDir(ts);
+    if (!chroot_done) {
+	if (rootDir != NULL && strcmp(rootDir, "/") && *rootDir == '/') {
+	    xx = chdir("/");
  /*@-nullpass@*/
-	rootFd = open(".", O_RDONLY, 0);
+	    rootFd = open(".", O_RDONLY, 0);
  /*@=nullpass@*/
-	if (rootFd >= 0) {
-	    /*@-superuser -noeffect @*/
-	    if (rootDir != NULL && strcmp(rootDir, "/") && *rootDir == '/')
+	    if (rootFd >= 0) {
+		/*@-superuser -noeffect @*/
  		xx = chroot(rootDir);
-	    /*@=superuser =noeffect @*/
-	    xx = rpmtsSetChrootDone(ts, 1);
+		/*@=superuser =noeffect @*/
+		xx = rpmtsSetChrootDone(ts, 1);
+	    }
  	}
+    } else {
+/*@-nullpass@*/
+	rootFd = open(".", O_RDONLY, 0);
+/*@=nullpass@*/
      }
+    xx = chdir("/");

      /* Create arg variable */
      rpmluaPushTable(lua, "arg");
@@ -561,14 +570,19 @@ static rpmRC runLuaScript(rpmpsm psm, He
      rpmluaDelVar(lua, "arg");

      if (rootFd >= 0) {
-	const char *rootDir = rpmtsRootDir(ts);
  	xx = fchdir(rootFd);
  	xx = close(rootFd);
-	/*@-superuser -noeffect @*/
-	if (rootDir != NULL && strcmp(rootDir, "/") && *rootDir == '/')
+	if (!chroot_done) {
+	    /*@-superuser -noeffect @*/
  	    xx = chroot(".");
-	/*@=superuser =noeffect @*/
-	xx = rpmtsSetChrootDone(ts, 0);
+	    /*@=superuser =noeffect @*/
+	    xx = rpmtsSetChrootDone(ts, 0);
+	}
+    }
+    if (!chroot_done) {
+	const char *currDir = rpmtsCurrDir(ts);
+	if (currDir != NULL)
+	    xx = chdir(currDir);
      }

      return rc;



More information about the Rpm-maint mailing list