summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/srvrec.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2019-08-22 13:11:00 +0200
committerJulian Andres Klode <julian.klode@canonical.com>2019-08-22 13:11:00 +0200
commitb9127ca07c37288f16b1fdc267d3f106721ed301 (patch)
tree345c647a8776531245d50482e69c2c1f72978ef4 /apt-pkg/contrib/srvrec.cc
parent489da40d56075efaa28bfdcfb7b02b3bcc222323 (diff)
srvrec: Use re-entrant resolver functions
This should probably make those functions thread-safe, which might be useful for some external users.
Diffstat (limited to 'apt-pkg/contrib/srvrec.cc')
-rw-r--r--apt-pkg/contrib/srvrec.cc9
1 files changed, 7 insertions, 2 deletions
diff --git a/apt-pkg/contrib/srvrec.cc b/apt-pkg/contrib/srvrec.cc
index a97d9c615..7d9bf116e 100644
--- a/apt-pkg/contrib/srvrec.cc
+++ b/apt-pkg/contrib/srvrec.cc
@@ -17,6 +17,7 @@
#include <time.h>
#include <algorithm>
+#include <memory>
#include <tuple>
#include <apt-pkg/configuration.h>
@@ -61,11 +62,15 @@ bool GetSrvRecords(std::string name, std::vector<SrvRec> &Result)
unsigned char answer[PACKETSZ];
int answer_len, compressed_name_len;
int answer_count;
+ struct __res_state res;
- if (res_init() != 0)
+ if (res_ninit(&res) != 0)
return _error->Errno("res_init", "Failed to init resolver");
- answer_len = res_query(name.c_str(), C_IN, T_SRV, answer, sizeof(answer));
+ // Close on return
+ std::shared_ptr<void> guard(&res, res_nclose);
+
+ answer_len = res_nquery(&res, name.c_str(), C_IN, T_SRV, answer, sizeof(answer));
if (answer_len == -1)
return false;
if (answer_len < (int)sizeof(HEADER))