diff options
author | Julian Andres Klode <jak@debian.org> | 2015-10-23 20:31:12 +0200 |
---|---|---|
committer | Julian Andres Klode <jak@debian.org> | 2015-10-30 14:20:09 +0100 |
commit | 308d0cf53f4b7ad1750fb1efb42b908c8e336b9f (patch) | |
tree | d376de54b4771ee29762a9e72f93b7d76d3dcdbc | |
parent | f77ea39c94988ab6adcb2d6bbf5466b0bc65953b (diff) |
GetSrvRecords: Make thread-safe
Gbp-Dch: ignore
-rw-r--r-- | apt-pkg/contrib/srvrec.cc | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/apt-pkg/contrib/srvrec.cc b/apt-pkg/contrib/srvrec.cc index 837f2c84e..9af282653 100644 --- a/apt-pkg/contrib/srvrec.cc +++ b/apt-pkg/contrib/srvrec.cc @@ -28,8 +28,13 @@ bool GetSrvRecords(std::string host, int port, std::vector<SrvRec> &Result) { std::string target; - struct servent *s_ent = getservbyport(htons(port), "tcp"); - if (s_ent == NULL) + int res; + struct servent s_ent_buf; + struct servent *s_ent = nullptr; + std::vector<char> buf(1024); + + res = getservbyport_r(htons(port), "tcp", &s_ent_buf, buf.data(), buf.size(), &s_ent); + if (res != 0 || s_ent == nullptr) return false; strprintf(target, "_%s._tcp.%s", s_ent->s_name, host.c_str()); |