diff options
author | Guillem Jover <guillem@debian.org> | 2011-06-17 17:00:30 +0200 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2011-07-07 08:31:14 +0200 |
commit | 87809163331a320f9562d75591fcc6c954b9f80c (patch) | |
tree | 88ee16e1dda86a803767e8b1acb5cfc50d1c0bdd /dpkg-deb/extract.c | |
parent | 6ab502b6a7a3718b697e7c1020fcd5d7f9fd2d67 (diff) | |
download | dpkg-87809163331a320f9562d75591fcc6c954b9f80c.tar.gz |
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.
Diffstat (limited to 'dpkg-deb/extract.c')
-rw-r--r-- | dpkg-deb/extract.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/dpkg-deb/extract.c b/dpkg-deb/extract.c index b458c1fc6..365be5d13 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); } |