瀏覽代碼

fix some coverity chroot() releated warnings

Michael Vogt 13 年之前
父節點
當前提交
36a0c0f786
共有 3 個文件被更改,包括 5 次插入4 次删除
  1. 2 2
      apt-pkg/aptconfiguration.cc
  2. 1 0
      apt-pkg/deb/dpkgpm.cc
  3. 2 2
      cmdline/apt-mark.cc

+ 2 - 2
apt-pkg/aptconfiguration.cc

@@ -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);

+ 1 - 0
apt-pkg/deb/dpkgpm.cc

@@ -134,6 +134,7 @@ static void dpkgChrootDirectory()
    std::cerr << "Chrooting into " << chrootDir << std::endl;
    if (chroot(chrootDir.c_str()) != 0)
       _exit(100);
+   chdir("/");
 }
 									/*}}}*/
 

+ 2 - 2
cmdline/apt-mark.cc

@@ -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);