summaryrefslogtreecommitdiff
path: root/cmdline/apt-helper.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-09-01 18:32:22 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2015-09-01 19:01:45 +0200
commit76abe9a5aad69eb7e67295588c6825cdae0341af (patch)
treef118c70def8f789a07a2e81a3c8966fa56e322e7 /cmdline/apt-helper.cc
parent63d609985eb7eefa5f2332bfe4fab96f017760a1 (diff)
use clock() as source for SRV randomness
Initializing a random number generator with the time since epoch could be good enough, but reaches its limits in test code as the 100 iterations might very well happen in the same second and hence the seed number is always the sameā€¦ clock() has a way lower resolution so it changes more often and not unimportant: If many users start the update at the same time it isn't to unlikely the SRV record will be ordered in the same second choosing the same for them all, but it seems less likely that the exact same clock() time has passed for them. And if I have to touch this, lets change a few other things as well to make me and/or compilers a bit happier (clang complained about the usage of a GNU extension in the testcase for example).
Diffstat (limited to 'cmdline/apt-helper.cc')
-rw-r--r--cmdline/apt-helper.cc30
1 files changed, 16 insertions, 14 deletions
diff --git a/cmdline/apt-helper.cc b/cmdline/apt-helper.cc
index 3c49bf149..2d24a8aee 100644
--- a/cmdline/apt-helper.cc
+++ b/cmdline/apt-helper.cc
@@ -82,25 +82,27 @@ static bool DoDownloadFile(CommandLine &CmdL)
static bool DoSrvLookup(CommandLine &CmdL)
{
if (CmdL.FileSize() < 1)
- return _error->Error(_("Must specifc at least one srv record"));
+ return _error->Error("Must specify at least one SRV record");
- std::vector<SrvRec> srv_records;
- c1out << "# target priority weight port" << std::endl;
- for(int i=1; CmdL.FileList[i] != NULL; i++)
+ for(size_t i = 1; CmdL.FileList[i] != NULL; ++i)
{
- if(GetSrvRecords(CmdL.FileList[i], srv_records) == false)
- _error->Warning(_("GetSrvRec failed for %s"), CmdL.FileList[i]);
- for (std::vector<SrvRec>::const_iterator I = srv_records.begin();
- I != srv_records.end(); ++I)
+ std::vector<SrvRec> srv_records;
+ std::string const name = CmdL.FileList[i];
+ c0out << "# Target\tPriority\tWeight\tPort # for " << name << std::endl;
+ size_t const found = name.find(":");
+ if (found != std::string::npos)
{
- c1out << (*I).target.c_str() << " "
- << (*I).priority << " "
- << (*I).weight << " "
- << (*I).port << " "
- << std::endl;
+ std::string const host = name.substr(0, found);
+ size_t const port = atoi(name.c_str() + found + 1);
+ if(GetSrvRecords(host, port, srv_records) == false)
+ _error->Warning(_("GetSrvRec failed for %s"), name.c_str());
}
- }
+ else if(GetSrvRecords(name, srv_records) == false)
+ _error->Warning(_("GetSrvRec failed for %s"), name.c_str());
+ for (SrvRec const &I : srv_records)
+ c1out << I.target << "\t" << I.priority << "\t" << I.weight << "\t" << I.port << std::endl;
+ }
return true;
}