A new user interface for you! Read more...

File luaroot.diff of Package rpm.SLE_11

Index: lib/psm.c
===================================================================
--- lib/psm.c.orig
+++ lib/psm.c
@@ -506,6 +506,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;
@@ -515,20 +517,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");
@@ -565,14 +574,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;