The following commit has been merged in the master branch:
commit 87809163331a320f9562d75591fcc6c954b9f80c
Author: Guillem Jover <guil...@debian.org>
Date:   Fri Jun 17 17:00:30 2011 +0200

    dpkg-deb: Always chdir(2) in the childs to not change the global state
    
    To not disturb the global program state we should always chdir(2) in the
    childs that actually need it. This will allow in the future to switch
    this code to be part of a library.

diff --git a/dpkg-deb/extract.c b/dpkg-deb/extract.c
index b458c1f..365be5d 100644
--- a/dpkg-deb/extract.c
+++ b/dpkg-deb/extract.c
@@ -288,19 +288,6 @@ extracthalf(const char *debar, const char *dir, const char 
*taroption,
   close(arfd);
   if (taroption) close(p2[1]);
 
-  if (taroption && dir) {
-    if (chdir(dir)) {
-      if (errno == ENOENT) {
-        if (mkdir(dir, 0777))
-          ohshite(_("failed to create directory"));
-        if (chdir(dir))
-          ohshite(_("failed to chdir to directory after creating it"));
-      } else {
-        ohshite(_("failed to chdir to directory"));
-      }
-    }
-  }
-
   if (taroption) {
     c3 = subproc_fork();
     if (!c3) {
@@ -314,6 +301,18 @@ extracthalf(const char *debar, const char *dir, const char 
*taroption,
 
       unsetenv("TAR_OPTIONS");
 
+      if (dir) {
+        if (chdir(dir)) {
+          if (errno != ENOENT)
+            ohshite(_("failed to chdir to directory"));
+
+          if (mkdir(dir, 0777))
+            ohshite(_("failed to create directory"));
+          if (chdir(dir))
+            ohshite(_("failed to chdir to directory after creating it"));
+        }
+      }
+
       execlp(TAR, "tar", buffer, "-", NULL);
       ohshite(_("unable to execute %s (%s)"), "tar", TAR);
     }
diff --git a/dpkg-deb/info.c b/dpkg-deb/info.c
index c20466d..6f43f55 100644
--- a/dpkg-deb/info.c
+++ b/dpkg-deb/info.c
@@ -54,13 +54,13 @@ static void cu_info_prepare(int argc, void **argv) {
   struct stat stab;
 
   dir = argv[0];
-  if (chdir("/"))
-    ohshite(_("failed to chdir to `/' for cleanup"));
   if (lstat(dir, &stab) && errno == ENOENT)
     return;
 
   pid = subproc_fork();
   if (pid == 0) {
+    if (chdir("/"))
+      ohshite(_("failed to chdir to `/' for cleanup"));
     execlp(RM, "rm", "-rf", dir, NULL);
     ohshite(_("unable to execute %s (%s)"), _("rm command for cleanup"), RM);
   }

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to debian-dpkg-cvs-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to