summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@oath.com>2018-09-26 16:31:24 +0200
committerHenning Baldersheim <balder@oath.com>2018-09-27 14:31:23 +0200
commit7b2c641855512aa2823d8c578b941745a4a5aca1 (patch)
tree94f085bb71edf1875d1562f698dcc36edf9020e6
parentee15790bfc2dbd633bc90076d0b2808043628190 (diff)
- NULL -> nullptr
- forward declaration. - Move from header to implementation. - use std::unordered_set
-rw-r--r--configd/src/apps/sentinel/config-handler.h1
-rw-r--r--documentapi/src/vespa/documentapi/messagebus/policies/localservicepolicy.cpp8
-rw-r--r--documentapi/src/vespa/documentapi/messagebus/policies/subsetservicepolicy.cpp7
-rw-r--r--logd/src/apps/logd/main.cpp3
-rw-r--r--logd/src/logd/errhandle.h3
-rw-r--r--logd/src/logd/forward.cpp56
-rw-r--r--logd/src/logd/forward.h14
-rw-r--r--logd/src/logd/metrics.cpp23
-rw-r--r--logd/src/logd/metrics.h20
-rw-r--r--logd/src/logd/service.cpp23
-rw-r--r--logd/src/logd/service.h6
-rw-r--r--logd/src/logd/watch.cpp18
-rw-r--r--logd/src/logd/watch.h11
-rw-r--r--logd/src/tests/forward/forward.cpp1
14 files changed, 90 insertions, 104 deletions
diff --git a/configd/src/apps/sentinel/config-handler.h b/configd/src/apps/sentinel/config-handler.h
index d294d97cff9..eb22b7fada1 100644
--- a/configd/src/apps/sentinel/config-handler.h
+++ b/configd/src/apps/sentinel/config-handler.h
@@ -6,7 +6,6 @@
#include "state-api.h"
#include <vespa/config-sentinel.h>
#include <vespa/config/config.h>
-#include <vespa/vespalib/util/hashmap.h>
#include <sys/types.h>
#include <sys/select.h>
diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/localservicepolicy.cpp b/documentapi/src/vespa/documentapi/messagebus/policies/localservicepolicy.cpp
index 4f54c0c5bac..42e1c07f3e8 100644
--- a/documentapi/src/vespa/documentapi/messagebus/policies/localservicepolicy.cpp
+++ b/documentapi/src/vespa/documentapi/messagebus/policies/localservicepolicy.cpp
@@ -4,7 +4,6 @@
#include <vespa/documentapi/messagebus/documentprotocol.h>
#include <vespa/messagebus/routing/verbatimdirective.h>
#include <vespa/messagebus/messagebus.h>
-#include <vespa/vespalib/util/hashmap.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/log/log.h>
LOG_SETUP(".localservicepolicy");
@@ -16,7 +15,6 @@ LocalServicePolicy::CacheEntry::CacheEntry() :
_generation(0),
_recipients()
{
- // empty
}
LocalServicePolicy::LocalServicePolicy(const string &param) :
@@ -24,13 +22,9 @@ LocalServicePolicy::LocalServicePolicy(const string &param) :
_address(param),
_cache()
{
- // empty
}
-LocalServicePolicy::~LocalServicePolicy()
-{
- // empty
-}
+LocalServicePolicy::~LocalServicePolicy() = default;
void
LocalServicePolicy::select(mbus::RoutingContext &ctx)
diff --git a/documentapi/src/vespa/documentapi/messagebus/policies/subsetservicepolicy.cpp b/documentapi/src/vespa/documentapi/messagebus/policies/subsetservicepolicy.cpp
index af7e2e67661..7e2d54f318f 100644
--- a/documentapi/src/vespa/documentapi/messagebus/policies/subsetservicepolicy.cpp
+++ b/documentapi/src/vespa/documentapi/messagebus/policies/subsetservicepolicy.cpp
@@ -4,8 +4,8 @@
#include <vespa/documentapi/messagebus/documentprotocol.h>
#include <vespa/messagebus/routing/verbatimdirective.h>
#include <vespa/messagebus/messagebus.h>
-#include <vespa/vespalib/util/hashmap.h>
#include <vespa/vespalib/util/stringfmt.h>
+#include <vespa/vespalib/stllike/hash_fun.h>
#include <vespa/log/log.h>
LOG_SETUP(".subsetservicepolicy");
@@ -37,10 +37,7 @@ SubsetServicePolicy::SubsetServicePolicy(const string &param) :
}
}
-SubsetServicePolicy::~SubsetServicePolicy()
-{
- // empty
-}
+SubsetServicePolicy::~SubsetServicePolicy() = default;
void
SubsetServicePolicy::select(mbus::RoutingContext &context)
diff --git a/logd/src/apps/logd/main.cpp b/logd/src/apps/logd/main.cpp
index f9d760c4d18..62f1e48b233 100644
--- a/logd/src/apps/logd/main.cpp
+++ b/logd/src/apps/logd/main.cpp
@@ -1,7 +1,6 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <logd/errhandle.h>
-#include <logd/service.h>
#include <logd/forward.h>
#include <logd/conf.h>
#include <logd/watch.h>
@@ -15,8 +14,6 @@
#include <vespa/log/log.h>
LOG_SETUP("logdemon");
-
-
using namespace logdemon;
using config::FileSpec;
diff --git a/logd/src/logd/errhandle.h b/logd/src/logd/errhandle.h
index 376005661fe..6798cac3cd9 100644
--- a/logd/src/logd/errhandle.h
+++ b/logd/src/logd/errhandle.h
@@ -1,5 +1,6 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
+
#include <stdexcept>
#include <vespa/vespalib/stllike/string.h>
@@ -10,7 +11,7 @@ private:
vespalib::string _string;
public:
MsgException(const char *s) : _string(s) {}
- virtual ~MsgException() throw() {}
+ ~MsgException() override {}
const char *what() const throw() override { return _string.c_str(); }
};
diff --git a/logd/src/logd/forward.cpp b/logd/src/logd/forward.cpp
index eba38dbcbd3..a0c4a3a003b 100644
--- a/logd/src/logd/forward.cpp
+++ b/logd/src/logd/forward.cpp
@@ -2,6 +2,7 @@
#include "forward.h"
#include "errhandle.h"
+#include "metrics.h"
#include <vespa/vespalib/component/vtag.h>
#include <vespa/vespalib/locale/c.h>
#include <unistd.h>
@@ -19,7 +20,7 @@ Forwarder::Forwarder(Metrics &metrics)
knownServices(),
_badLines(0)
{}
-Forwarder::~Forwarder() {}
+Forwarder::~Forwarder() = default;
void
Forwarder::forwardText(const char *text, int len)
@@ -44,7 +45,7 @@ Forwarder::sendMode()
snprintf(buf, 1024, "mode logd %s\n", vespalib::VersionTag);
int len = strlen(buf);
if (len < 100) {
- forwardText(buf, len);
+ forwardText(buf, len);
} else {
LOG(warning, "too long mode line: %s", buf);
}
@@ -75,9 +76,8 @@ Forwarder::parseline(const char *linestart, const char *lineend)
const char *fieldstart = linestart;
// time
const char *tab = strchr(fieldstart, '\t');
- if (tab == NULL || tab == fieldstart) {
- LOG(spam, "bad logline no 1. tab: %.*s",
- llength, linestart);
+ if (tab == nullptr || tab == fieldstart) {
+ LOG(spam, "bad logline no 1. tab: %.*s", llength, linestart);
++_badLines;
return false;
}
@@ -85,23 +85,20 @@ Forwarder::parseline(const char *linestart, const char *lineend)
double logtime = vespalib::locale::c::strtod(fieldstart, &eod);
if (eod != tab) {
int fflen = tab - linestart;
- LOG(spam, "bad logline first field not strtod parsable: %.*s",
- fflen, linestart);
+ LOG(spam, "bad logline first field not strtod parsable: %.*s", fflen, linestart);
++_badLines;
return false;
}
- time_t now = time(NULL);
+ time_t now = time(nullptr);
if (logtime - 864000 > now) {
int fflen = tab - linestart;
- LOG(warning, "bad logline, time %.*s > 10 days in the future",
- fflen, linestart);
+ LOG(warning, "bad logline, time %.*s > 10 days in the future", fflen, linestart);
++_badLines;
return false;
}
if (logtime + 8640000 < now) {
int fflen = tab - linestart;
- LOG(warning, "bad logline, time %.*s > 100 days in the past",
- fflen, linestart);
+ LOG(warning, "bad logline, time %.*s > 100 days in the past", fflen, linestart);
++_badLines;
return false;
}
@@ -109,9 +106,8 @@ Forwarder::parseline(const char *linestart, const char *lineend)
// hostname
fieldstart = tab + 1;
tab = strchr(fieldstart, '\t');
- if (tab == NULL) {
- LOG(spam, "bad logline no 2. tab: %.*s",
- llength, linestart);
+ if (tab == nullptr) {
+ LOG(spam, "bad logline no 2. tab: %.*s", llength, linestart);
++_badLines;
return false;
}
@@ -119,9 +115,8 @@ Forwarder::parseline(const char *linestart, const char *lineend)
// pid
fieldstart = tab + 1;
tab = strchr(fieldstart, '\t');
- if (tab == NULL || tab == fieldstart) {
- LOG(spam, "bad logline no 3. tab: %.*s",
- llength, linestart);
+ if (tab == nullptr || tab == fieldstart) {
+ LOG(spam, "bad logline no 3. tab: %.*s", llength, linestart);
return false;
}
int pid = strtol(fieldstart, &eod, 10);
@@ -130,24 +125,21 @@ Forwarder::parseline(const char *linestart, const char *lineend)
// service
fieldstart = tab + 1;
tab = strchr(fieldstart, '\t');
- if (tab == NULL) {
- LOG(spam, "bad logline no 4. tab: %.*s",
- llength, linestart);
+ if (tab == nullptr) {
+ LOG(spam, "bad logline no 4. tab: %.*s", llength, linestart);
++_badLines;
return false;
}
if (tab == fieldstart) {
- LOG(spam, "empty service in logline: %.*s",
- llength, linestart);
+ LOG(spam, "empty service in logline: %.*s", llength, linestart);
}
string service(fieldstart, tab-fieldstart);
// component
fieldstart = tab + 1;
tab = strchr(fieldstart, '\t');
- if (tab == NULL || tab == fieldstart) {
- LOG(spam, "bad logline no 5. tab: %.*s",
- llength, linestart);
+ if (tab == nullptr || tab == fieldstart) {
+ LOG(spam, "bad logline no 5. tab: %.*s", llength, linestart);
++_badLines;
return false;
}
@@ -156,9 +148,8 @@ Forwarder::parseline(const char *linestart, const char *lineend)
// level
fieldstart = tab + 1;
tab = strchr(fieldstart, '\t');
- if (tab == NULL || tab == fieldstart) {
- LOG(spam, "bad logline no 6. tab: %.*s",
- llength, linestart);
+ if (tab == nullptr || tab == fieldstart) {
+ LOG(spam, "bad logline no 6. tab: %.*s", llength, linestart);
++_badLines;
return false;
}
@@ -167,8 +158,7 @@ Forwarder::parseline(const char *linestart, const char *lineend)
// rest is freeform message, must be on this line:
if (tab > lineend) {
- LOG(spam, "bad logline last tab after end: %.*s",
- llength, linestart);
+ LOG(spam, "bad logline last tab after end: %.*s", llength, linestart);
++_badLines;
return false;
}
@@ -197,9 +187,9 @@ LevelParser::parseLevel(const char *level)
if (l >= 0 && l <= Logger::NUM_LOGLEVELS) {
return l;
}
- if (! _seenLevelMap[level]) {
+ if (_seenLevelMap.find(level) == _seenLevelMap.end()) {
LOG(warning, "unknown level '%s'", level);
- _seenLevelMap.set(level, true);
+ _seenLevelMap.insert(level);
}
return Logger::fatal;
}
diff --git a/logd/src/logd/forward.h b/logd/src/logd/forward.h
index e012db205fe..78e63500295 100644
--- a/logd/src/logd/forward.h
+++ b/logd/src/logd/forward.h
@@ -1,15 +1,17 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
+
#include "service.h"
-#include "metrics.h"
-#include <vespa/vespalib/util/hashmap.h>
#include <map>
+#include <unordered_set>
namespace logdemon {
-typedef vespalib::HashMap<bool> SeenMap;
+using SeenMap = std::unordered_set<std::string>;
// Mapping saying if a level should be forwarded or not
-typedef std::map<ns_log::Logger::LogLevel, bool> ForwardMap;
+using ForwardMap = std::map<ns_log::Logger::LogLevel, bool>;
+
+class Metrics;
class LevelParser
{
@@ -17,7 +19,7 @@ private:
SeenMap _seenLevelMap;
public:
ns_log::Logger::LogLevel parseLevel(const char *level);
- LevelParser() : _seenLevelMap(false) {}
+ LevelParser() : _seenLevelMap() {}
};
class Forwarder
@@ -48,4 +50,4 @@ public:
void sendMode();
};
-} // namespace
+}
diff --git a/logd/src/logd/metrics.cpp b/logd/src/logd/metrics.cpp
index 1a70a2226e2..edfa44021d5 100644
--- a/logd/src/logd/metrics.cpp
+++ b/logd/src/logd/metrics.cpp
@@ -1,3 +1,26 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "metrics.h"
+
+namespace logdemon {
+
+Metrics::Metrics(std::shared_ptr<MetricsManager> m)
+ : metrics(std::move(m)),
+ loglevel(metrics->dimension("loglevel")),
+ servicename(metrics->dimension("service")),
+ loglines(metrics->counter("logd.processed.lines",
+ "how many log lines have been processed"))
+{}
+
+Metrics::~Metrics() = default;
+
+void
+Metrics::countLine(const vespalib::string &level, const vespalib::string &service) const
+{
+ Point p = metrics->pointBuilder()
+ .bind(loglevel, level)
+ .bind(servicename, service);
+ loglines.add(1, p);
+}
+
+}
diff --git a/logd/src/logd/metrics.h b/logd/src/logd/metrics.h
index b5bc5a7dcd7..5a1a577cbf7 100644
--- a/logd/src/logd/metrics.h
+++ b/logd/src/logd/metrics.h
@@ -16,24 +16,10 @@ struct Metrics {
const Dimension servicename;
const Counter loglines;
- Metrics(std::shared_ptr<MetricsManager> m)
- : metrics(m),
- loglevel(metrics->dimension("loglevel")),
- servicename(metrics->dimension("service")),
- loglines(metrics->counter("logd.processed.lines",
- "how many log lines have been processed"))
- {}
+ Metrics(std::shared_ptr<MetricsManager> m);
+ ~Metrics();
- ~Metrics() {}
-
- void countLine(const vespalib::string &level,
- const vespalib::string &service) const
- {
- Point p = metrics->pointBuilder()
- .bind(loglevel, level)
- .bind(servicename, service);
- loglines.add(1, p);
- }
+ void countLine(const vespalib::string &level, const vespalib::string &service) const;
};
} // namespace logdemon
diff --git a/logd/src/logd/service.cpp b/logd/src/logd/service.cpp
index cd4304f5405..8084fc56416 100644
--- a/logd/src/logd/service.cpp
+++ b/logd/src/logd/service.cpp
@@ -1,18 +1,17 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
+#include <cstdlib>
+#include <cstring>
+#include <cstdio>
#include <fcntl.h>
-#include <errno.h>
+#include <cerrno>
#include <unistd.h>
-#include <time.h>
+#include <ctime>
#include <sys/stat.h>
#include <cassert>
#include <vespa/log/log.h>
#include <vespa/log/control-file.h>
LOG_SETUP("logdemon");
-LOG_RCSID("$Id$");
#include "service.h"
@@ -20,7 +19,6 @@ namespace logdemon {
unsigned long Component::defFwd = (unsigned long)-1;
-
void
Component::doLogAtAll(LogLevel level)
{
@@ -72,10 +70,7 @@ Component::shouldLogAtAll(LogLevel level)
try {
ControlFile foo(lcfn, ControlFile::READWRITE);
unsigned int *lstring = foo.getLevels(_logctlname);
- if (lstring[level] == CHARS_TO_UINT(' ', ' ', 'O', 'N'))
- return true;
- else
- return false;
+ return (lstring[level] == CHARS_TO_UINT(' ', ' ', 'O', 'N'));
} catch (...) {
LOG(debug, "exception checking logcontrol for %s", _myservice);
}
@@ -114,8 +109,7 @@ Services::dumpState(int fildesc)
while (it.valid()) {
Component *cmp = it.value();
char buf[1024];
- int pos = snprintf(buf, 1024, "setstate %s %s ",
- sit.key(), it.key());
+ int pos = snprintf(buf, 1024, "setstate %s %s ", sit.key(), it.key());
for (int i = 0; pos < 1000 && i < Logger::NUM_LOGLEVELS; i++) {
LogLevel l = static_cast<LogLevel>(i);
pos += snprintf(buf+pos, 1024-pos, "%s=%s,",
@@ -135,5 +129,4 @@ Services::dumpState(int fildesc)
}
}
-
-} // namespace
+}
diff --git a/logd/src/logd/service.h b/logd/src/logd/service.h
index 09b4ca3fa4b..8467ce7b2a2 100644
--- a/logd/src/logd/service.h
+++ b/logd/src/logd/service.h
@@ -42,7 +42,7 @@ public:
{
assert(ns_log::Logger::NUM_LOGLEVELS < 32);
const char *withoutprefix = strchr(name, '.');
- if (withoutprefix != NULL) {
+ if (withoutprefix != nullptr) {
strcpy(_logctlname, withoutprefix);
} else {
strcpy(_logctlname, "");
@@ -72,7 +72,7 @@ public:
return _components[comp];
}
Service(const char *name)
- : _myname(strdup(name)), _components(NULL) {}
+ : _myname(strdup(name)), _components(nullptr) {}
~Service();
};
@@ -89,7 +89,7 @@ public:
}
return _services[serv];
}
- Services() : _services(NULL) {}
+ Services() : _services(nullptr) {}
~Services();
void dumpState(int fildesc);
};
diff --git a/logd/src/logd/watch.cpp b/logd/src/logd/watch.cpp
index 2adc1cbbdbb..d7ebeaf74ec 100644
--- a/logd/src/logd/watch.cpp
+++ b/logd/src/logd/watch.cpp
@@ -41,7 +41,7 @@ void snooze(const struct timeval &start)
tsp.tv_sec = (wait_usecs / 1000000);
tsp.tv_nsec = (wait_usecs % 1000000) * 1000;
- if (nanosleep(&tsp, NULL) != 0 && errno != EINTR) {
+ if (nanosleep(&tsp, nullptr) != 0 && errno != EINTR) {
LOG(error, "nanosleep %ld s %ld ns failed: %s",
(long)tsp.tv_sec, (long)tsp.tv_nsec, strerror(errno));
throw SomethingBad("nanosleep failed");
@@ -68,7 +68,7 @@ Watcher::Watcher(ConfSub &cfs, Forwarder &fw)
_forwarder(fw),
_wfd(-1)
{
- if (_buffer == NULL) {
+ if (_buffer == nullptr) {
LOG(error, "could not allocate 1MB memory");
throw SomethingBad("out of memory");
}
@@ -174,7 +174,7 @@ Watcher::watchfile()
struct donecache already;
char *target = getenv("VESPA_LOG_TARGET");
- if (target == NULL || strncmp(target, "file:", 5) != 0) {
+ if (target == nullptr || strncmp(target, "file:", 5) != 0) {
LOG(error, "expected VESPA_LOG_TARGET (%s) to be a file: target",
target);
throw SomethingBad("bad log target");
@@ -251,13 +251,13 @@ Watcher::watchfile()
_buffer[rsize] = '\0';
char *l = _buffer;
char *nnl = (char *)memchr(_buffer, '\n', rsize);
- if (nnl == NULL && rsize == bufsiz - 1) {
+ if (nnl == nullptr && rsize == bufsiz - 1) {
// incredibly long block without any newline ?
LOG(error, "no newline in %ld bytes, skipping",
static_cast<long>(rsize));
offset += rsize;
}
- while (nnl != NULL && elapsed(tickStart) < 1) {
+ while (nnl != nullptr && elapsed(tickStart) < 1) {
++nnl;
_forwarder.forwardLine(l, nnl);
ssize_t wsize = nnl - l;
@@ -276,7 +276,7 @@ Watcher::watchfile()
already.st_dev = sb.st_dev;
already.st_ino = sb.st_ino;
- time_t now = time(NULL);
+ time_t now = time(nullptr);
bool wantrotate = (now > created + _confsubscriber.getRotateAge())
|| (sb.st_size > _confsubscriber.getRotateSize());
@@ -388,7 +388,7 @@ Watcher::removeOldLogs(const char *prefix)
myglob.gl_pathc = 0;
myglob.gl_offs = 0;
myglob.gl_flags = 0;
- myglob.gl_pathv = NULL;
+ myglob.gl_pathv = nullptr;
off_t totalsize = 0;
@@ -404,10 +404,10 @@ Watcher::removeOldLogs(const char *prefix)
}
if (S_ISREG(sb.st_mode)) {
if (sb.st_mtime +
- _confsubscriber.getRemoveAge() * 86400 < time(NULL))
+ _confsubscriber.getRemoveAge() * 86400 < time(nullptr))
{
LOG(info, "removing %s, too old (%f days)", fname,
- (double)(time(NULL)-sb.st_mtime)/86400.0);
+ (double)(time(nullptr)-sb.st_mtime)/86400.0);
if (unlink(fname) != 0) {
LOG(warning, "cannot remove %s: %s",
diff --git a/logd/src/logd/watch.h b/logd/src/logd/watch.h
index 29523181303..67616b18a48 100644
--- a/logd/src/logd/watch.h
+++ b/logd/src/logd/watch.h
@@ -1,7 +1,11 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
+
namespace logdemon {
+class Forwarder;
+class ConfSub;
+
class Watcher
{
private:
@@ -9,10 +13,9 @@ private:
ConfSub& _confsubscriber;
Forwarder& _forwarder;
int _wfd;
-
- Watcher(const Watcher& other);
- Watcher& operator=(const Watcher& other);
public:
+ Watcher(const Watcher& other) = delete;
+ Watcher& operator=(const Watcher& other) = delete;
Watcher(ConfSub &cfs, Forwarder &fw);
~Watcher();
@@ -20,4 +23,4 @@ public:
void removeOldLogs(const char *prefix);
};
-} // namespace
+}
diff --git a/logd/src/tests/forward/forward.cpp b/logd/src/tests/forward/forward.cpp
index db0a4e5de69..a2f1a8c8b7a 100644
--- a/logd/src/tests/forward/forward.cpp
+++ b/logd/src/tests/forward/forward.cpp
@@ -3,6 +3,7 @@
#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/vespalib/metrics/dummy_metrics_manager.h>
#include <logd/forward.h>
+#include <logd/metrics.h>
#include <sstream>
#include <fcntl.h>
#include <unistd.h>