summaryrefslogtreecommitdiff
path: root/net/powerdns-recursor/patches/patch-rec-carbon.cc
blob: 42628a0d984b053d389f23d79f9131e32ba87671 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$NetBSD: patch-rec-carbon.cc,v 1.1.2.2 2020/06/25 18:21:29 bsiegert Exp $

backport changes based on PR #9127 from
https://github.com/PowerDNS/pdns/pull/9127

--- rec-carbon.cc.orig	2020-06-17 21:27:18.582569489 +0000
+++ rec-carbon.cc
@@ -32,17 +32,13 @@ try
   if(namespace_name.empty()) {
     namespace_name="pdns";
   }
-  if(hostname.empty()) {
-    char tmp[HOST_NAME_MAX+1];
-    memset(tmp, 0, sizeof(tmp));
-    if (gethostname(tmp, sizeof(tmp)) != 0) {
-      throw std::runtime_error("The 'carbon-ourname' setting has not been set and we are unable to determine the system's hostname: " + stringerror());
+  if (hostname.empty()) {
+    try {
+      hostname = getCarbonHostName();
+    }
+    catch(const std::exception& e) {
+      throw std::runtime_error(std::string("The 'carbon-ourname' setting has not been set and we are unable to determine the system's hostname: ") + e.what());
     }
-    char *p = strchr(tmp, '.');
-    if(p) *p=0;
-
-    hostname=tmp;
-    boost::replace_all(hostname, ".", "_");    
   }
   if(instance_name.empty()) {
     instance_name="recursor";