From ab7f4d7ca647270ffd34b5b6c67339b0cfde51ac Mon Sep 17 00:00:00 2001
From: Michael Vogt <michael.vogt@ubuntu.com>
Date: Thu, 2 Jul 2009 14:07:18 +0200
Subject: [PATCH] * apt-pkg/acquire-worker.cc:   - show error details of failed
 methods * apt-pkg/contrib/fileutl.cc:   - if a process aborts with signal,
 show signal number * methods/http.cc:   - ignore SIGPIPE, we deal with EPIPE
 from write in     HttpMethod::ServerDie() (LP: #385144)

---
 apt-pkg/acquire-worker.cc  | 7 ++-----
 apt-pkg/contrib/fileutl.cc | 7 +++++--
 debian/changelog           | 7 +++++++
 methods/http.cc            | 4 +++-
 4 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/apt-pkg/acquire-worker.cc b/apt-pkg/acquire-worker.cc
index 78c68737c..4f0b52af9 100644
--- a/apt-pkg/acquire-worker.cc
+++ b/apt-pkg/acquire-worker.cc
@@ -527,10 +527,6 @@ bool pkgAcquire::Worker::OutFdReady()
    
    if (Res <= 0)
       return MethodFailure();
-
-   // Hmm.. this should never happen.
-   if (Res < 0)
-      return true;
    
    OutQueue.erase(0,Res);
    if (OutQueue.empty() == true)
@@ -558,7 +554,8 @@ bool pkgAcquire::Worker::MethodFailure()
 {
    _error->Error("Method %s has died unexpectedly!",Access.c_str());
    
-   ExecWait(Process,Access.c_str(),true);
+   // do not reap the child here to show meaningfull error to the user
+   ExecWait(Process,Access.c_str(),false);
    Process = -1;
    close(InFd);
    close(OutFd);
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index a5976cf3a..a7de09c44 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -450,8 +450,11 @@ bool ExecWait(pid_t Pid,const char *Name,bool Reap)
    {
       if (Reap == true)
 	 return false;
-      if (WIFSIGNALED(Status) != 0 && WTERMSIG(Status) == SIGSEGV)
-	 return _error->Error(_("Sub-process %s received a segmentation fault."),Name);
+      if (WIFSIGNALED(Status) != 0)
+	 if( WTERMSIG(Status) == SIGSEGV)
+	    return _error->Error(_("Sub-process %s received a segmentation fault."),Name);
+	 else 
+	    return _error->Error(_("Sub-process %s received signal %u."),Name, WTERMSIG(Status));
 
       if (WIFEXITED(Status) != 0)
 	 return _error->Error(_("Sub-process %s returned an error code (%u)"),Name,WEXITSTATUS(Status));
diff --git a/debian/changelog b/debian/changelog
index ba57dbadc..65fd9e590 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -20,6 +20,13 @@ apt (0.7.21) UNRELEASED; urgency=low
   * apt-pkg/algorithms.cc:
     - consider recommends when making the scores for the problem 
       resolver
+  * apt-pkg/acquire-worker.cc:
+    - show error details of failed methods
+  * apt-pkg/contrib/fileutl.cc:
+    - if a process aborts with signal, show signal number
+  * methods/http.cc:
+    - ignore SIGPIPE, we deal with EPIPE from write in 
+      HttpMethod::ServerDie() (LP: #385144)
 
  -- Michael Vogt <michael.vogt@ubuntu.com>  Thu, 28 May 2009 17:51:42 +0200
 
diff --git a/methods/http.cc b/methods/http.cc
index 1bf798da4..006e89394 100644
--- a/methods/http.cc
+++ b/methods/http.cc
@@ -1316,9 +1316,11 @@ int HttpMethod::Loop()
 int main()
 {
    setlocale(LC_ALL, "");
+   // ignore SIGPIPE, this can happen on write() if the socket
+   // closes the connection (this is dealt with via ServerDie())
+   signal(SIGPIPE, SIG_IGN);
 
    HttpMethod Mth;
-   
    return Mth.Loop();
 }
 
-- 
2.47.2