aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArne Juul <arnej@yahoo-inc.com>2017-09-08 08:05:55 +0000
committerArne Juul <arnej@yahoo-inc.com>2017-09-08 08:05:55 +0000
commitdaadb26ae52c23924ec9c0094e12d7a5d7499a41 (patch)
treefd645b8002a566033a68c21fbf84d922e46ca0a6
parent5734bcd664f92dd29f40d3cb8fad85547e6c9fef (diff)
use Defaults::vespaHostname
-rw-r--r--vespaclient/src/vespa/vespaclient/vdsstates/statesapp.cpp11
-rw-r--r--vespalib/src/vespa/vespalib/util/host_name.cpp11
-rw-r--r--vespalog/src/vespa/log/llparser.cpp7
-rw-r--r--vespalog/src/vespa/log/log.cpp5
4 files changed, 8 insertions, 26 deletions
diff --git a/vespaclient/src/vespa/vespaclient/vdsstates/statesapp.cpp b/vespaclient/src/vespa/vespaclient/vdsstates/statesapp.cpp
index 99c91216d20..b24eb3e0373 100644
--- a/vespaclient/src/vespa/vespaclient/vdsstates/statesapp.cpp
+++ b/vespaclient/src/vespa/vespaclient/vdsstates/statesapp.cpp
@@ -1,5 +1,6 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/defaults.h>
#include <vespa/document/util/stringutil.h>
#include <vespa/fnet/frt/frt.h>
#include <vespa/slobrok/sbmirror.h>
@@ -339,15 +340,7 @@ struct StateApp : public FastOS_Application {
{
indexes.push_back(_options._nodeIndex);
} else {
- std::vector<char> host(HOST_NAME_MAX);
- int result = gethostname(&host[0], host.size());
- if (result != 0) {
- std::cerr << "Failed to retrieve hostname of this node, "
- "thus we cannot figure out what services run "
- "on this node.\n";
- break;
- }
- std::string hostname(&host[0]);
+ std::string hostname(vespa::Defaults::vespaHostname());
FRT_RPCRequest* req = supervisor.AllocRPCRequest();
req->SetMethodName("getNodeList");
target->InvokeSync(req, 10.0);
diff --git a/vespalib/src/vespa/vespalib/util/host_name.cpp b/vespalib/src/vespa/vespalib/util/host_name.cpp
index a33f81b068f..98ac2c80183 100644
--- a/vespalib/src/vespa/vespalib/util/host_name.cpp
+++ b/vespalib/src/vespa/vespalib/util/host_name.cpp
@@ -1,21 +1,14 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "host_name.h"
-#include <vespa/vespalib/util/exceptions.h>
-#include <unistd.h>
+#include <vespa/defaults.h>
namespace vespalib {
namespace {
vespalib::string make_host_name() {
- constexpr size_t max_size = 1024;
- char hostname[max_size + 1];
- memset(hostname, 0, sizeof(hostname));
- if (gethostname(hostname, max_size) != 0) {
- throw FatalException("gethostname failed");
- }
- return hostname;
+ return vespa::Defaults::vespaHostname();
}
} // namespace vespalib::<unnamed>
diff --git a/vespalog/src/vespa/log/llparser.cpp b/vespalog/src/vespa/log/llparser.cpp
index d239f291c9f..5e48343dfaf 100644
--- a/vespalog/src/vespa/log/llparser.cpp
+++ b/vespalog/src/vespa/log/llparser.cpp
@@ -6,15 +6,15 @@
#include <cstdlib>
#include <unistd.h>
#include <sys/time.h>
+#include <vespa/defaults.h>
namespace ns_log {
static const char *defcomponent = "logger";
static const char *defservice = "-";
-static char defhostname[256] = "localhost";
LLParser::LLParser()
- : _defHostname(defhostname),
+ : _defHostname(vespa::Defaults::vespaHostname()),
_defService(defservice),
_defComponent(defcomponent),
_defLevel(Logger::info),
@@ -37,9 +37,6 @@ LLParser::LLParser()
delete _target;
_target = target;
}
- if (gethostname(defhostname, 256) == 0) {
- _defHostname = defhostname;
- }
snprintf(_defPid, 10, "%d", (int)getpid());
}
diff --git a/vespalog/src/vespa/log/log.cpp b/vespalog/src/vespa/log/log.cpp
index a0977406dc0..7d98c22957d 100644
--- a/vespalog/src/vespa/log/log.cpp
+++ b/vespalog/src/vespa/log/log.cpp
@@ -12,6 +12,7 @@ LOG_SETUP_INDIRECT(".log", "$Id$");
#include "control-file.h"
#include "bufferedlogger.h"
+#include <vespa/defaults.h>
#include <vespa/fastos/thread.h>
#include <cassert>
#include <cstdarg>
@@ -114,9 +115,7 @@ void
Logger::ensureHostname()
{
if (_hostname[0] == '\0') {
- char hn[257];
- snprintf(_hostname, sizeof _hostname, "%s",
- (gethostname(hn, sizeof hn) == 0) ? hn : "-");
+ snprintf(_hostname, sizeof _hostname, "%s", vespa::Defaults::vespaHostname());
}
}