summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <egon@tas>2007-02-01 12:32:50 +0100
committerMichael Vogt <egon@tas>2007-02-01 12:32:50 +0100
commit36280399db0ae203d3f1ae4d44b946f31e9a38ce (patch)
tree79cba67d2c395b54d2b2ff5863de00ffeab4fdda
parent362d29343e5d25248bcd84300aa1b18effe891e7 (diff)
* commited the latest mirror failure detection code
-rw-r--r--apt-pkg/acquire-item.cc51
-rw-r--r--apt-pkg/acquire-item.h5
-rw-r--r--apt-pkg/acquire-method.cc21
-rw-r--r--apt-pkg/acquire-method.h8
-rwxr-xr-xcmdline/apt-report-mirror-failure23
-rw-r--r--methods/connect.cc17
-rw-r--r--methods/mirror.cc45
-rw-r--r--methods/mirror.h1
-rw-r--r--po/apt-all.pot44
9 files changed, 120 insertions, 95 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index 7b2a89763..61564c7aa 100644
--- a/apt-pkg/acquire-item.cc
+++ b/apt-pkg/acquire-item.cc
@@ -79,6 +79,10 @@ void pkgAcquire::Item::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
Status = StatError;
Dequeue();
}
+
+ // report mirror failure back to LP if we actually use a mirror
+ if(!UsedMirror.empty())
+ ReportMirrorFailure(ErrorText);
}
/*}}}*/
// Acquire::Item::Start - Item has begun to download /*{{{*/
@@ -100,6 +104,7 @@ void pkgAcquire::Item::Done(string Message,unsigned long Size,string,
{
// We just downloaded something..
string FileName = LookupTag(Message,"Filename");
+ UsedMirror = LookupTag(Message,"UsedMirror");
if (Complete == false && FileName == DestFile)
{
if (Owner->Log != 0)
@@ -108,7 +113,6 @@ void pkgAcquire::Item::Done(string Message,unsigned long Size,string,
if (FileSize == 0)
FileSize= Size;
-
Status = StatDone;
ErrorText = string();
Owner->Dequeue(this);
@@ -131,6 +135,42 @@ void pkgAcquire::Item::Rename(string From,string To)
}
/*}}}*/
+void pkgAcquire::Item::ReportMirrorFailure(string FailCode)
+{
+ // report that Queue->Uri failed
+#if 0
+ std::cerr << "\nReportMirrorFailure: "
+ << UsedMirror
+ << " FailCode: "
+ << FailCode << std::endl;
+#endif
+ const char *Args[40];
+ unsigned int i = 0;
+ string report = _config->Find("Methods::Mirror::ProblemReporting",
+ "/usr/bin/apt-report-mirror-failure");
+ if(!FileExists(report))
+ return;
+ Args[i++] = report.c_str();
+ Args[i++] = UsedMirror.c_str();
+ Args[i++] = FailCode.c_str();
+ pid_t pid = ExecFork();
+ if(pid < 0)
+ {
+ _error->Error("ReportMirrorFailure Fork failed");
+ return;
+ }
+ else if(pid == 0)
+ {
+ execvp(report.c_str(), (char**)Args);
+ }
+ if(!ExecWait(pid, "report-mirror-failure"))
+ {
+ _error->Warning("Couldn't report problem to '%s'",
+ _config->Find("Acquire::Mirror::ReportFailures").c_str());
+ }
+}
+
+
// AcqIndex::AcqIndex - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* The package file is added to the queue and a second class is
@@ -176,8 +216,6 @@ string pkgAcqIndex::Custom600Headers()
struct stat Buf;
if (stat(Final.c_str(),&Buf) != 0)
return "\nIndex-File: true";
- if(ExpectedMD5 != "")
- return "\nExpectedMD5: " + ExpectedMD5;
return "\nIndex-File: true\nLast-Modified: " + TimeRFC1123(Buf.st_mtime);
}
/*}}}*/
@@ -1016,13 +1054,6 @@ void pkgAcqArchive::Failed(string Message,pkgAcquire::MethodConfig *Cnf)
}
}
/*}}}*/
-// ---------------------------------------------------------------------
-string pkgAcqArchive::Custom600Headers()
-{
- if(MD5 != "")
- return "\nExpectedMD5: " + MD5;
- return "";
-}
// AcqArchive::IsTrusted - Determine whether this archive comes from a
// trusted source /*{{{*/
// ---------------------------------------------------------------------
diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h
index c9cd75321..9949d0044 100644
--- a/apt-pkg/acquire-item.h
+++ b/apt-pkg/acquire-item.h
@@ -56,6 +56,7 @@ class pkgAcquire::Item
unsigned long ID;
bool Complete;
bool Local;
+ string UsedMirror;
// Number of queues we are inserted into
unsigned int QueueCounter;
@@ -78,6 +79,9 @@ class pkgAcquire::Item
pkgAcquire *GetOwner() {return Owner;};
virtual bool IsTrusted() {return false;};
+ // report mirror problems
+ void ReportMirrorFailure(string FailCode);
+
Item(pkgAcquire *Owner);
virtual ~Item();
};
@@ -205,7 +209,6 @@ class pkgAcqArchive : public pkgAcquire::Item
virtual string ShortDesc() {return Desc.ShortDesc;};
virtual void Finished();
virtual bool IsTrusted();
- virtual string Custom600Headers();
pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
pkgRecords *Recs,pkgCache::VerIterator const &Version,
diff --git a/apt-pkg/acquire-method.cc b/apt-pkg/acquire-method.cc
index 638797657..13201d310 100644
--- a/apt-pkg/acquire-method.cc
+++ b/apt-pkg/acquire-method.cc
@@ -99,12 +99,11 @@ void pkgAcqMethod::Fail(string Err,bool Transient)
}
char S[1024];
+ char *End = S;
if (Queue != 0)
{
- snprintf(S,sizeof(S)-50,"400 URI Failure\nURI: %s\n"
- "Message: %s %s\n",Queue->Uri.c_str(),Err.c_str(),
- FailExtra.c_str());
-
+ End += snprintf(S,sizeof(S)-50,"400 URI Failure\nURI: %s\n"
+ "Message: %s %s\n",Queue->Uri.c_str(), Err.c_str(), IP.c_str());
// Dequeue
FetchItem *Tmp = Queue;
Queue = Queue->Next;
@@ -113,10 +112,14 @@ void pkgAcqMethod::Fail(string Err,bool Transient)
QueueBack = Queue;
}
else
- snprintf(S,sizeof(S)-50,"400 URI Failure\nURI: <UNKNOWN>\n"
- "Message: %s %s\n",Err.c_str(),
- FailExtra.c_str());
-
+ {
+ End += snprintf(S,sizeof(S)-50,"400 URI Failure\nURI: <UNKNOWN>\n"
+ "Message: %s\n",Err.c_str());
+ }
+ if(FailReason.empty() == false)
+ End += snprintf(End,sizeof(S)-50 - (End - S),"FailReason: %s\n",FailReason.c_str());
+ if (UsedMirror.empty() == false)
+ End += snprintf(End,sizeof(S)-50 - (End - S),"UsedMirror: %s\n",UsedMirror.c_str());
// Set the transient flag
if (Transient == true)
strcat(S,"Transient-Failure: true\n\n");
@@ -182,6 +185,8 @@ void pkgAcqMethod::URIDone(FetchResult &Res, FetchResult *Alt)
End += snprintf(End,sizeof(S)-50 - (End - S),"MD5-Hash: %s\n",Res.MD5Sum.c_str());
if (Res.SHA1Sum.empty() == false)
End += snprintf(End,sizeof(S)-50 - (End - S),"SHA1-Hash: %s\n",Res.SHA1Sum.c_str());
+ if (UsedMirror.empty() == false)
+ End += snprintf(End,sizeof(S)-50 - (End - S),"UsedMirror: %s\n",UsedMirror.c_str());
if (Res.GPGVOutput.size() > 0)
End += snprintf(End,sizeof(S)-50 - (End - S),"GPGVOutput:\n");
for (vector<string>::iterator I = Res.GPGVOutput.begin();
diff --git a/apt-pkg/acquire-method.h b/apt-pkg/acquire-method.h
index 9e908d32c..ee68c75f7 100644
--- a/apt-pkg/acquire-method.h
+++ b/apt-pkg/acquire-method.h
@@ -55,7 +55,9 @@ class pkgAcqMethod
vector<string> Messages;
FetchItem *Queue;
FetchItem *QueueBack;
- string FailExtra;
+ string FailReason;
+ string UsedMirror;
+ string IP;
// Handlers for messages
virtual bool Configuration(string Message);
@@ -72,7 +74,6 @@ class pkgAcqMethod
virtual void Exit() {};
public:
-
enum CnfFlags {SingleInstance = (1<<0),
Pipeline = (1<<1), SendConfig = (1<<2),
LocalOnly = (1<<3), NeedsCleanup = (1<<4),
@@ -82,7 +83,8 @@ class pkgAcqMethod
void Status(const char *Format,...);
int Run(bool Single = false);
- inline void SetFailExtraMsg(string Msg) {FailExtra = Msg;};
+ inline void SetFailReason(string Msg) {FailReason = Msg;};
+ inline void SetIP(string aIP) {IP = aIP;};
pkgAcqMethod(const char *Ver,unsigned long Flags = 0);
virtual ~pkgAcqMethod() {};
diff --git a/cmdline/apt-report-mirror-failure b/cmdline/apt-report-mirror-failure
new file mode 100755
index 000000000..70b16cf4f
--- /dev/null
+++ b/cmdline/apt-report-mirror-failure
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+
+import sys
+import urllib
+import apt_pkg
+
+print "apt-report-mirror-failure"
+
+apt_pkg.init()
+url = apt_pkg.Config.Find("Acquire::Mirror::ReportFailures",
+ "http://people.ubuntu.com:9000/mirror-failure")
+ #"http://localhost:9000/mirror-failure")
+if not url:
+ sys.exit(0)
+
+data = {}
+data['url'] = sys.argv[1]
+data['error'] = sys.argv[2]
+f = urllib.urlopen(url, urllib.urlencode(data))
+f.read()
+f.close()
+
+
diff --git a/methods/connect.cc b/methods/connect.cc
index 8c2ac6d56..4e227c3fd 100644
--- a/methods/connect.cc
+++ b/methods/connect.cc
@@ -18,6 +18,7 @@
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
+#include <sstream>
// Internet stuff
#include <netinet/in.h>
@@ -67,12 +68,10 @@ static bool DoConnect(struct addrinfo *Addr,string Host,
wrong this will get tacked onto the end of the error message */
if (LastHostAddr->ai_next != 0)
{
- char Name2[NI_MAXHOST + NI_MAXSERV + 10];
- snprintf(Name2,sizeof(Name2),_("[IP: %s %s]"),Name,Service);
- Owner->SetFailExtraMsg(string(Name2));
- }
- else
- Owner->SetFailExtraMsg("");
+ std::stringstream ss;
+ ioprintf(ss, _("[IP: %s %s]"),Name,Service);
+ Owner->SetIP(ss.str());
+ }
// Get a socket
if ((Fd = socket(Addr->ai_family,Addr->ai_socktype,
@@ -89,7 +88,7 @@ static bool DoConnect(struct addrinfo *Addr,string Host,
/* This implements a timeout for connect by opening the connection
nonblocking */
if (WaitFd(Fd,true,TimeOut) == false) {
- Owner->SetFailExtraMsg("\nFailReason: Timeout");
+ Owner->SetFailReason("Timeout");
return _error->Error(_("Could not connect to %s:%s (%s), "
"connection timed out"),Host.c_str(),Service,Name);
}
@@ -104,7 +103,7 @@ static bool DoConnect(struct addrinfo *Addr,string Host,
{
errno = Err;
if(errno == ECONNREFUSED)
- Owner->SetFailExtraMsg("\nFailReason: ConnectionRefused");
+ Owner->SetFailReason("ConnectionRefused");
return _error->Errno("connect",_("Could not connect to %s:%s (%s)."),Host.c_str(),
Service,Name);
}
@@ -169,7 +168,7 @@ bool Connect(string Host,int Port,const char *Service,int DefPort,int &Fd,
if (Res == EAI_AGAIN)
{
- Owner->SetFailExtraMsg("\nFailReason: TmpResolveFailure");
+ Owner->SetFailReason("TmpResolveFailure");
return _error->Error(_("Temporary failure resolving '%s'"),
Host.c_str());
}
diff --git a/methods/mirror.cc b/methods/mirror.cc
index 8f9b8ed34..8ccfb8559 100644
--- a/methods/mirror.cc
+++ b/methods/mirror.cc
@@ -38,7 +38,7 @@ using namespace std;
*
* TODO:
* what about gpgv failures? this should call-out to the problem reporting
- script, but we need to know what mirror was used
+ script, but we need to know what mirror was used -> just run pkgAcquire::Item::ReportMirrorFailure()
* better standard format for errors to send back
* - implement failure reporting at the pkgAcquire::Item::Failed() level
but then we need to send back what uri exactly was failing
@@ -48,7 +48,7 @@ using namespace std;
* - deal with runing as non-root because we can't write to the lists
dir then -> use the cached mirror file
* - better method to download than having a pkgAcquire interface here
- * - magicmarker is (a bit) evil, maybe just use a similar approach as in
+ * - magicmarker is evil, maybe just use a similar approach as in
clean and read the sources.list and use the GetURI() method to find
the prefix?
* support more than http
@@ -191,6 +191,8 @@ bool MirrorMethod::SelectMirror()
getline(in, Mirror);
if(Debug)
cerr << "Using mirror: " << Mirror << endl;
+
+ UsedMirror = Mirror;
return true;
}
@@ -220,9 +222,6 @@ bool MirrorMethod::Fetch(FetchItem *Itm)
void MirrorMethod::Fail(string Err,bool Transient)
{
- // FIXME: queue next mirror?
- ReportMirrorFailure(Err);
-
if(Queue->Uri.find("http://") != string::npos)
Queue->Uri.replace(0,Mirror.size(), BaseUri);
pkgAcqMethod::Fail(Err, Transient);
@@ -237,47 +236,11 @@ void MirrorMethod::URIStart(FetchResult &Res)
void MirrorMethod::URIDone(FetchResult &Res,FetchResult *Alt)
{
- // FIXME: queue next mirror?
- if(Queue->ExpectedMD5 != "" && Res.MD5Sum != Queue->ExpectedMD5)
- ReportMirrorFailure("499 Hash mismatch");
-
if(Queue->Uri.find("http://") != string::npos)
Queue->Uri.replace(0,Mirror.size(), BaseUri);
pkgAcqMethod::URIDone(Res, Alt);
}
-void MirrorMethod::ReportMirrorFailure(string FailCode)
-{
- // report that Queue->Uri failed
-#if 0
- std::cerr << "\nReportMirrorFailure: "
- << Queue->Uri
- << " FailCode: "
- << FailCode << std::endl;
-#endif
- const char *Args[40];
- unsigned int i = 0;
- string report = _config->Find("Methods::Mirror::ProblemReporting",
- "/usr/lib/apt/report-mirror-failure");
- Args[i++] = report.c_str();
- Args[i++] = Queue->Uri.c_str();
- Args[i++] = FailCode.c_str();
- pid_t pid = ExecFork();
- if(pid < 0)
- {
- _error->Error("ReportMirrorFailure Fork failed");
- return;
- }
- else if(pid == 0)
- {
- execvp(report.c_str(), (char**)Args);
- }
- if(!ExecWait(pid, "report-mirror-failure"))
- {
- _error->Warning("Couldn't report problem to '%s'",
- _config->Find("Acquire::Mirror::ReportFailures").c_str());
- }
-}
int main()
{
diff --git a/methods/mirror.h b/methods/mirror.h
index 3ff9e1a96..798f5a9b5 100644
--- a/methods/mirror.h
+++ b/methods/mirror.h
@@ -35,7 +35,6 @@ class MirrorMethod : public HttpMethod
bool GetMirrorFile(string uri);
bool SelectMirror();
bool Clean(string dir);
- void ReportMirrorFailure(string FailCode);
// we need to overwrite those to transform the url back
virtual void Fail(string Why, bool Transient = false);
diff --git a/po/apt-all.pot b/po/apt-all.pot
index dd140bd63..15b650fda 100644
--- a/po/apt-all.pot
+++ b/po/apt-all.pot
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2007-01-24 12:51+0100\n"
+"POT-Creation-Date: 2007-01-24 17:20+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -950,7 +950,7 @@ msgstr ""
msgid "Calculating upgrade... "
msgstr ""
-#: cmdline/apt-get.cc:1716 methods/ftp.cc:702 methods/connect.cc:101
+#: cmdline/apt-get.cc:1716 methods/ftp.cc:702 methods/connect.cc:100
msgid "Failed"
msgstr ""
@@ -1330,7 +1330,7 @@ msgstr ""
#: apt-inst/extract.cc:467 apt-pkg/contrib/configuration.cc:750
#: apt-pkg/contrib/cdromutl.cc:153 apt-pkg/sourcelist.cc:324
-#: apt-pkg/acquire.cc:421 apt-pkg/clean.cc:38 methods/mirror.cc:96
+#: apt-pkg/acquire.cc:421 apt-pkg/clean.cc:38 methods/mirror.cc:99
#, c-format
msgid "Unable to read %s"
msgstr ""
@@ -1648,59 +1648,59 @@ msgstr ""
msgid "Unable to invoke "
msgstr ""
-#: methods/connect.cc:64
+#: methods/connect.cc:65
#, c-format
msgid "Connecting to %s (%s)"
msgstr ""
-#: methods/connect.cc:71
+#: methods/connect.cc:72
#, c-format
msgid "[IP: %s %s]"
msgstr ""
-#: methods/connect.cc:80
+#: methods/connect.cc:79
#, c-format
msgid "Could not create a socket for %s (f=%u t=%u p=%u)"
msgstr ""
-#: methods/connect.cc:86
+#: methods/connect.cc:85
#, c-format
msgid "Cannot initiate the connection to %s:%s (%s)."
msgstr ""
-#: methods/connect.cc:93
+#: methods/connect.cc:92
#, c-format
msgid "Could not connect to %s:%s (%s), connection timed out"
msgstr ""
-#: methods/connect.cc:108
+#: methods/connect.cc:107
#, c-format
msgid "Could not connect to %s:%s (%s)."
msgstr ""
#. We say this mainly because the pause here is for the
#. ssh connection that is still going
-#: methods/connect.cc:136 methods/rsh.cc:425
+#: methods/connect.cc:135 methods/rsh.cc:425
#, c-format
msgid "Connecting to %s"
msgstr ""
-#: methods/connect.cc:167
+#: methods/connect.cc:166
#, c-format
msgid "Could not resolve '%s'"
msgstr ""
-#: methods/connect.cc:173
+#: methods/connect.cc:172
#, c-format
msgid "Temporary failure resolving '%s'"
msgstr ""
-#: methods/connect.cc:176
+#: methods/connect.cc:175
#, c-format
msgid "Something wicked happened resolving '%s:%s' (%i)"
msgstr ""
-#: methods/connect.cc:223
+#: methods/connect.cc:222
#, c-format
msgid "Unable to connect to %s %s:"
msgstr ""
@@ -1956,7 +1956,7 @@ msgid "Unable to stat the mount point %s"
msgstr ""
#: apt-pkg/contrib/cdromutl.cc:149 apt-pkg/acquire.cc:427 apt-pkg/clean.cc:44
-#: methods/mirror.cc:102
+#: methods/mirror.cc:105
#, c-format
msgid "Unable to change to %s"
msgstr ""
@@ -2357,40 +2357,40 @@ msgstr ""
msgid "IO Error saving source cache"
msgstr ""
-#: apt-pkg/acquire-item.cc:126
+#: apt-pkg/acquire-item.cc:128
#, c-format
msgid "rename failed, %s (%s -> %s)."
msgstr ""
-#: apt-pkg/acquire-item.cc:237 apt-pkg/acquire-item.cc:946
+#: apt-pkg/acquire-item.cc:275 apt-pkg/acquire-item.cc:984
msgid "MD5Sum mismatch"
msgstr ""
-#: apt-pkg/acquire-item.cc:641
+#: apt-pkg/acquire-item.cc:679
msgid "There is no public key available for the following key IDs:\n"
msgstr ""
-#: apt-pkg/acquire-item.cc:754
+#: apt-pkg/acquire-item.cc:792
#, c-format
msgid ""
"I wasn't able to locate a file for the %s package. This might mean you need "
"to manually fix this package. (due to missing arch)"
msgstr ""
-#: apt-pkg/acquire-item.cc:813
+#: apt-pkg/acquire-item.cc:851
#, c-format
msgid ""
"I wasn't able to locate file for the %s package. This might mean you need to "
"manually fix this package."
msgstr ""
-#: apt-pkg/acquire-item.cc:849
+#: apt-pkg/acquire-item.cc:887
#, c-format
msgid ""
"The package index files are corrupted. No Filename: field for package %s."
msgstr ""
-#: apt-pkg/acquire-item.cc:936
+#: apt-pkg/acquire-item.cc:974
msgid "Size mismatch"
msgstr ""