]> git.saurik.com Git - apt.git/commitdiff
fix some coverity chroot() releated warnings
authorMichael Vogt <mvo@debian.org>
Fri, 26 Jul 2013 20:10:05 +0000 (22:10 +0200)
committerMichael Vogt <mvo@debian.org>
Fri, 26 Jul 2013 20:10:05 +0000 (22:10 +0200)
apt-pkg/aptconfiguration.cc
apt-pkg/deb/dpkgpm.cc
cmdline/apt-mark.cc

index 37c8465822d394146f7acdec717803d5a5514617..e32e553a424ad34cb65f50a58148269e25f7c957 100644 (file)
@@ -388,12 +388,12 @@ std::vector<std::string> const Configuration::getArchitectures(bool const &Cache
                if (dpkgMultiArch == 0) {
                        close(external[0]);
                        std::string const chrootDir = _config->FindDir("DPkg::Chroot-Directory");
-                       if (chrootDir != "/" && chroot(chrootDir.c_str()) != 0)
-                               _error->WarningE("getArchitecture", "Couldn't chroot into %s for dpkg --print-foreign-architectures", chrootDir.c_str());
                        int const nullfd = open("/dev/null", O_RDONLY);
                        dup2(nullfd, STDIN_FILENO);
                        dup2(external[1], STDOUT_FILENO);
                        dup2(nullfd, STDERR_FILENO);
+                       if (chrootDir != "/" && chroot(chrootDir.c_str()) != 0)
+                               _error->WarningE("getArchitecture", "Couldn't chroot into %s for dpkg --print-foreign-architectures", chrootDir.c_str());
                        execvp(Args[0], (char**) &Args[0]);
                        _error->WarningE("getArchitecture", "Can't detect foreign architectures supported by dpkg!");
                        _exit(100);
index fb04735353c85af96b62f20b2c54d4b1b85d8cc2..588ab68c45ec657c4bf59aa8c334cae3194dc97c 100644 (file)
@@ -134,6 +134,7 @@ static void dpkgChrootDirectory()
    std::cerr << "Chrooting into " << chrootDir << std::endl;
    if (chroot(chrootDir.c_str()) != 0)
       _exit(100);
+   chdir("/");
 }
                                                                        /*}}}*/
 
index c5b7ca4962f87dfed3a18699d3f2eebfac248433..4c0fc28930bcba3ffafb7a8feef88280a259bee8 100644 (file)
@@ -202,13 +202,13 @@ bool DoHold(CommandLine &CmdL)
    if (dpkgAssertMultiArch == 0)
    {
       std::string const chrootDir = _config->FindDir("DPkg::Chroot-Directory");
-      if (chrootDir != "/" && chroot(chrootDir.c_str()) != 0)
-        _error->WarningE("getArchitecture", "Couldn't chroot into %s for dpkg --assert-multi-arch", chrootDir.c_str());
       // redirect everything to the ultimate sink as we only need the exit-status
       int const nullfd = open("/dev/null", O_RDONLY);
       dup2(nullfd, STDIN_FILENO);
       dup2(nullfd, STDOUT_FILENO);
       dup2(nullfd, STDERR_FILENO);
+      if (chrootDir != "/" && chroot(chrootDir.c_str()) != 0)
+        _error->WarningE("getArchitecture", "Couldn't chroot into %s for dpkg --assert-multi-arch", chrootDir.c_str());
       execvp(Args[0], (char**) &Args[0]);
       _error->WarningE("dpkgGo", "Can't detect if dpkg supports multi-arch!");
       _exit(2);