]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/deb/dpkgpm.cc
* apt-pkg/contrib/fileutl.cc, apt-pkg/deb/dpkgpm.cc:
[apt.git] / apt-pkg / deb / dpkgpm.cc
index 395c3fb1aed6da42338b556fa99688a31ef645bc..5747f11643cbc6ec335e1cedfedac843ca2602bb 100644 (file)
@@ -308,6 +308,15 @@ bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf)
         SetCloseExec(STDIN_FILENO,false);      
         SetCloseExec(STDERR_FILENO,false);
 
+        if (_config->FindDir("DPkg::Chroot-Directory","/") != "/") 
+        {
+           std::cerr << "Chrooting into " 
+                     << _config->FindDir("DPkg::Chroot-Directory") 
+                     << std::endl;
+           if (chroot(_config->FindDir("DPkg::Chroot-Directory","/").c_str()) != 0)
+              _exit(100);
+        }
+
         const char *Args[4];
         Args[0] = "/bin/sh";
         Args[1] = "-c";
@@ -322,7 +331,6 @@ bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf)
         return _error->Errno("fdopen","Faild to open new FD");
       
       // Feed it the filenames.
-      bool Die = false;
       if (Version <= 1)
       {
         for (vector<Item>::iterator I = List.begin(); I != List.end(); I++)
@@ -339,14 +347,11 @@ bool pkgDPkgPM::RunScriptsWithPkgs(const char *Cnf)
               into the pipe. */
            fprintf(F,"%s\n",I->File.c_str());
            if (ferror(F) != 0)
-           {
-              Die = true;
               break;
-           }
         }
       }
       else
-        Die = !SendV2Pkgs(F);
+        SendV2Pkgs(F);
 
       fclose(F);
       
@@ -660,6 +665,7 @@ bool pkgDPkgPM::OpenLog()
       if (term_out == NULL)
         return _error->WarningE("OpenLog", _("Could not open file '%s'"), logfile_name.c_str());
       setvbuf(term_out, NULL, _IONBF, 0);
+      SetCloseExec(fileno(term_out), true);
       chmod(logfile_name.c_str(), 0600);
       fprintf(term_out, "\nLog started: %s\n", timestr);
    }
@@ -1229,7 +1235,7 @@ bool pkgDPkgPM::Go(int OutStatusFd)
            strprintf(dpkg_error, "Sub-process %s exited unexpectedly",Args[0]);
 
         if(dpkg_error.size() > 0)
-           _error->Error(dpkg_error.c_str());
+           _error->Error("%s", dpkg_error.c_str());
 
         if(stopOnError) 
         {
@@ -1414,7 +1420,7 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
       {
         while( fgets(buf, sizeof(buf), log) != NULL)
            fprintf(report, " %s", buf);
-        fclose(log);
+        pclose(log);
       }
    }
 
@@ -1430,7 +1436,7 @@ void pkgDPkgPM::WriteApportReport(const char *pkgpath, const char *errormsg)
       {
         while( fgets(buf, sizeof(buf), log) != NULL)
            fprintf(report, " %s", buf);
-        fclose(log);
+        pclose(log);
       }
    }