Skip to content
2 changes: 1 addition & 1 deletion lib/base/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class Application : public ObjectImpl<Application> {

virtual void OnShutdown();

void ValidateName(const Lazy<String>& lvalue, const ValidationUtils& utils) final;
void ValidateName(const Lazy<String>& lvalue, const ValidationUtils& utils) override final;

private:
static Application::Ptr m_Instance; /**< The application instance. */
Expand Down
33 changes: 4 additions & 29 deletions lib/base/debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,17 @@
#ifndef I2_DEBUG
# define ASSERT(expr) ((void)0)
#else /* I2_DEBUG */
# define ASSERT(expr) ((expr) ? 0 : icinga_assert_fail(#expr, __FILE__, __LINE__))
# define ASSERT(expr) ((expr) ? void(0) : icinga_assert_fail(#expr, __FILE__, __LINE__))
#endif /* I2_DEBUG */

#define VERIFY(expr) ((expr) ? 0 : icinga_assert_fail(#expr, __FILE__, __LINE__))
#define VERIFY(expr) ((expr) ? void(0) : icinga_assert_fail(#expr, __FILE__, __LINE__))

#ifdef _MSC_VER
# define NORETURNPRE __declspec(noreturn)
#else /* _MSC_VER */
# define NORETURNPRE
#endif /* _MSC_VER */
#define ABORT(expr) icinga_assert_fail(#expr, __FILE__, __LINE__)

#ifdef __GNUC__
# define NORETURNPOST __attribute__((noreturn))
#else /* __GNUC__ */
# define NORETURNPOST
#endif /* __GNUC__ */

NORETURNPRE int icinga_assert_fail(const char *expr, const char *file, int line) NORETURNPOST;

#ifdef _MSC_VER
# pragma warning( push )
# pragma warning( disable : 4646 ) /* function declared with __declspec(noreturn) has non-void return type */
#endif /* _MSC_VER */

inline int icinga_assert_fail(const char *expr, const char *file, int line)
[[noreturn]] inline void icinga_assert_fail(const char *expr, const char *file, int line) noexcept(true)
{
fprintf(stderr, "%s:%d: assertion failed: %s\n", file, line, expr);
std::abort();

#if !defined(__GNUC__) && !defined(_MSC_VER)
return 0;
#endif /* !defined(__GNUC__) && !defined(_MSC_VER) */
}

#ifdef _MSC_VER
# pragma warning( pop )
#endif /* _MSC_VER */

#endif /* DEBUG_H */
8 changes: 4 additions & 4 deletions lib/base/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ScriptError : virtual public user_error
ScriptError(String message);
ScriptError(String message, DebugInfo di, bool incompleteExpr = false);

const char *what(void) const throw() final;
const char* what() const noexcept override final;

DebugInfo GetDebugInfo() const;
bool IsIncompleteExpression() const;
Expand All @@ -59,7 +59,7 @@ class ValidationError : virtual public user_error
ValidationError(const ConfigObject::Ptr& object, const std::vector<String>& attributePath, const String& message);
~ValidationError() throw() override;

const char *what() const throw() override;
const char *what() const noexcept override;

ConfigObject::Ptr GetObject() const;
std::vector<String> GetAttributePath() const;
Expand Down Expand Up @@ -118,7 +118,7 @@ String DiagnosticInformation(const boost::exception_ptr& eptr, bool verbose = tr

class posix_error : virtual public std::exception, virtual public boost::exception {
public:
const char* what() const noexcept final;
const char* what() const noexcept override final;

private:
mutable String m_Message;
Expand Down Expand Up @@ -153,7 +153,7 @@ class invalid_downtime_removal_error : virtual public std::exception, virtual pu

~invalid_downtime_removal_error() noexcept override;

const char *what() const noexcept final;
const char* what() const noexcept override final;

private:
String m_Message;
Expand Down
2 changes: 0 additions & 2 deletions lib/base/io-engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ IoEngine::~IoEngine()
boost::asio::post(m_IoContext, []() {
throw TerminateIoThread();
});
}

for (auto& thread : m_Threads) {
thread.join();
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/base/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Logger : public ObjectImpl<Logger>
}

void SetSeverity(const String& value, bool suppress_events = false, const Value& cookie = Empty) override;
void ValidateSeverity(const Lazy<String>& lvalue, const ValidationUtils& utils) final;
void ValidateSeverity(const Lazy<String>& lvalue, const ValidationUtils& utils) override final;

protected:
void Start(bool runtimeCreated) override;
Expand Down
4 changes: 2 additions & 2 deletions lib/base/netstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ String NetString::ReadStringFromStream(const Shared<AsioTlsStream>::Ptr& stream,
}
}

if (maxMessageLength >= 0 && len > maxMessageLength) {
if (maxMessageLength >= 0 && len > static_cast<std::size_t>(maxMessageLength)) {
std::stringstream errorMessage;
errorMessage << "Max data length exceeded: " << (maxMessageLength / 1024) << " KB";

Expand Down Expand Up @@ -246,7 +246,7 @@ String NetString::ReadStringFromStream(const Shared<AsioTlsStream>::Ptr& stream,
}
}

if (maxMessageLength >= 0 && len > maxMessageLength) {
if (maxMessageLength >= 0 && len > static_cast<std::size_t>(maxMessageLength)) {
std::stringstream errorMessage;
errorMessage << "Max data length exceeded: " << (maxMessageLength / 1024) << " KB";

Expand Down
4 changes: 2 additions & 2 deletions lib/base/object-packer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ static void PackAny(const Value& value, std::string& builder)
*/
String icinga::PackObject(const Value& value)
{
std::string builder;
PackAny(value, builder);
String builder;
PackAny(value, builder.GetData());

return builder;
}
4 changes: 0 additions & 4 deletions lib/cli/clicommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,16 @@ void CLICommand::ShowCommands(int argc, char **argv, po::options_description *vi
typedef std::map<std::vector<String>, CLICommand::Ptr>::value_type CLIKeyValue;

std::vector<String> best_match;
int arg_begin = 0;
CLICommand::Ptr command;

for (const CLIKeyValue& kv : GetRegistry()) {
const std::vector<String>& vname = kv.first;

arg_begin = 0;

std::vector<String>::size_type i;
int k;
for (i = 0, k = 1; i < vname.size() && k < argc; i++, k++) {
if (strcmp(argv[k], "--no-stack-rlimit") == 0 || strcmp(argv[k], "--autocomplete") == 0 || strcmp(argv[k], "--scm") == 0) {
i--;
arg_begin++;
continue;
}

Expand Down
4 changes: 3 additions & 1 deletion lib/config/configitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,9 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
<< "Committing " << total << " new items.";
#endif /* I2_DEBUG */

#ifdef I2_DEBUG
int itemsCount {0};
#endif /* I2_DEBUG */

for (auto& type : Type::GetConfigTypesSortedByLoadDependencies()) {
std::atomic<int> committed_items(0);
Expand Down Expand Up @@ -475,9 +477,9 @@ bool ConfigItem::CommitNewItems(const ActivationContext::Ptr& context, WorkQueue
}
}

#ifdef I2_DEBUG
itemsCount += committed_items;

#ifdef I2_DEBUG
if (committed_items > 0)
Log(LogDebug, "configitem")
<< "Committed " << committed_items << " items of type '" << type->GetName() << "'.";
Expand Down
2 changes: 1 addition & 1 deletion lib/config/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ ExpressionResult GetScopeExpression::DoEvaluate(ScriptFrame& frame, DebugHint *d
else if (m_ScopeSpec == ScopeGlobal)
return frame.GetGlobals();
else
VERIFY(!"Invalid scope.");
ABORT("Invalid scope.");
}

static inline
Expand Down
2 changes: 1 addition & 1 deletion lib/icinga/checkable-dependency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ std::vector<DependencyGroup::Ptr> Checkable::GetDependencyGroups() const
static std::variant<Checkable*, String> GetDependencyGroupKey(const Dependency::Ptr& dependency)
{
if (auto redundancyGroup(dependency->GetRedundancyGroup()); !redundancyGroup.IsEmpty()) {
return std::move(redundancyGroup);
return redundancyGroup;
}

return dependency->GetParent().get();
Expand Down
2 changes: 1 addition & 1 deletion lib/icinga/checkable-flapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,6 @@ int Checkable::ServiceStateToFlappingFilter(ServiceState state)
case ServiceUnknown:
return StateFilterUnknown;
default:
VERIFY(!"Invalid state type.");
ABORT("Invalid state type.");
}
}
8 changes: 4 additions & 4 deletions lib/icinga/notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ int icinga::ServiceStateToFilter(ServiceState state)
case ServiceUnknown:
return StateFilterUnknown;
default:
VERIFY(!"Invalid state type.");
ABORT("Invalid state type.");
}
}

Expand All @@ -660,7 +660,7 @@ int icinga::HostStateToFilter(HostState state)
case HostDown:
return StateFilterDown;
default:
VERIFY(!"Invalid state type.");
ABORT("Invalid state type.");
}
}

Expand Down Expand Up @@ -736,7 +736,7 @@ String Notification::NotificationServiceStateToString(ServiceState state)
case ServiceUnknown:
return "Unknown";
default:
VERIFY(!"Invalid state type.");
ABORT("Invalid state type.");
}
}

Expand All @@ -748,7 +748,7 @@ String Notification::NotificationHostStateToString(HostState state)
case HostDown:
return "Down";
default:
VERIFY(!"Invalid state type.");
ABORT("Invalid state type.");
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/icingadb/icingadb-objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ std::vector<std::vector<intrusive_ptr<ConfigObject>>> IcingaDB::ChunkObjects(std

chunks.reserve((std::distance(offset, end) + chunkSize - 1) / chunkSize);

while (std::distance(offset, end) >= chunkSize) {
while (static_cast<std::size_t>(std::distance(offset, end)) >= chunkSize) {
auto until (offset + chunkSize);
chunks.emplace_back(offset, until);
offset = until;
Expand Down Expand Up @@ -1375,7 +1375,7 @@ void IcingaDB::UpdateDependenciesState(const Checkable::Ptr& checkable, const De
}

RedisConnection::Queries streamStates;
auto addDependencyStateToStream([this, &streamStates](const String& redisKey, const Dictionary::Ptr& stateAttrs) {
auto addDependencyStateToStream([&streamStates](const String& redisKey, const Dictionary::Ptr& stateAttrs) {
RedisConnection::Query xAdd{
"XADD", "icinga:runtime:state", "MAXLEN", "~", "1000000", "*", "runtime_type", "upsert",
"redis_key", redisKey
Expand Down
2 changes: 1 addition & 1 deletion lib/perfdata/graphitewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ void GraphiteWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C
std::vector<std::pair<String, double>> metadata;
if (GetEnableSendMetadata()) {
metadata = {
{"state", service ? service->GetState() : host->GetState()},
{"state", service ? static_cast<unsigned int>(service->GetState()) : static_cast<unsigned int>(host->GetState())},
{"current_attempt", checkable->GetCheckAttempt()},
{"max_check_attempts", checkable->GetMaxCheckAttempts()},
{"state_type", checkable->GetStateType()},
Expand Down
2 changes: 1 addition & 1 deletion lib/remote/apilistener-authority.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void ApiListener::UpdateObjectAuthority()

std::vector<Endpoint::Ptr> endpoints;
Endpoint::Ptr my_endpoint;
int hostChildrenInheritObjectAuthority = 0;
std::size_t hostChildrenInheritObjectAuthority = 0;

if (my_zone) {
my_endpoint = Endpoint::GetLocalEndpoint();
Expand Down
5 changes: 0 additions & 5 deletions lib/remote/apilistener-filesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ void ApiListener::SyncLocalZoneDir(const Zone::Ptr& zone) const

Utility::MkDirP(productionZonesDir, 0700);

// Copy content and add additional meta data.
size_t numBytes = 0;

/* Note: We cannot simply copy directories here.
*
* Zone directories are registered from everywhere and we already
Expand All @@ -131,8 +128,6 @@ void ApiListener::SyncLocalZoneDir(const Zone::Ptr& zone) const

fp << content;
fp.close();

numBytes += content.GetLength();
}
}

Expand Down
26 changes: 12 additions & 14 deletions lib/remote/apilistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,11 +1004,11 @@ void ApiListener::ApiTimerHandler()
{
double now = Utility::GetTime();

std::vector<int> files;
std::vector<std::uint64_t> files;
Utility::Glob(GetApiDir() + "log/*", [&files](const String& file) { LogGlobHandler(files, file); }, GlobFile);
std::sort(files.begin(), files.end());

for (int ts : files) {
for (auto ts : files) {
bool need = false;
auto localZone (GetLocalEndpoint()->GetZone());

Expand Down Expand Up @@ -1468,7 +1468,7 @@ void ApiListener::RotateLogFile()
ts = Utility::GetTime();

String oldpath = GetApiDir() + "log/current";
String newpath = GetApiDir() + "log/" + Convert::ToString(static_cast<int>(ts)+1);
String newpath = GetApiDir() + "log/" + Convert::ToString(static_cast<std::uint64_t>(ts)+1);

// If the log is being rotated more than once per second,
// don't overwrite the previous one, but silently deny rotation.
Expand All @@ -1486,22 +1486,20 @@ void ApiListener::RotateLogFile()
}
}

void ApiListener::LogGlobHandler(std::vector<int>& files, const String& file)
void ApiListener::LogGlobHandler(std::vector<std::uint64_t>& files, const String& file)
{
String name = Utility::BaseName(file);

if (name == "current")
return;

int ts;

try {
ts = Convert::ToLong(name);
} catch (const std::exception&) {
files.emplace_back(boost::lexical_cast<std::uint64_t>(name));
} catch (const std::exception& ex) {
Log(LogCritical, "ApiListener")
<< "Error converting log file name " << file << " to uint64: " << ex.what();
return;
}

files.push_back(ts);
}

void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)
Expand Down Expand Up @@ -1548,19 +1546,19 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client)

count = 0;

std::vector<int> files;
std::vector<std::uint64_t> files;
Utility::Glob(GetApiDir() + "log/*", [&files](const String& file) { LogGlobHandler(files, file); }, GlobFile);
std::sort(files.begin(), files.end());

std::vector<std::pair<int, String>> allFiles;
std::vector<std::pair<std::uint64_t, String>> allFiles;

for (int ts : files) {
for (auto ts : files) {
if (ts >= peer_ts) {
allFiles.emplace_back(ts, GetApiDir() + "log/" + Convert::ToString(ts));
}
}

allFiles.emplace_back(Utility::GetTime() + 1, GetApiDir() + "log/current");
allFiles.emplace_back(static_cast<std::uint64_t>(Utility::GetTime()) + 1, GetApiDir() + "log/current");

for (auto& file : allFiles) {
Log(LogNotice, "ApiListener")
Expand Down
2 changes: 1 addition & 1 deletion lib/remote/apilistener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class ApiListener final : public ObjectImpl<ApiListener>
void OpenLogFile();
void RotateLogFile();
void CloseLogFile();
static void LogGlobHandler(std::vector<int>& files, const String& file);
static void LogGlobHandler(std::vector<std::uint64_t>& files, const String& file);
void ReplayLog(const JsonRpcConnection::Ptr& client);

static void CopyCertificateFile(const String& oldCertPath, const String& newCertPath);
Expand Down
1 change: 0 additions & 1 deletion lib/remote/consolehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ using namespace icinga;

REGISTER_URLHANDLER("/v1/console", ConsoleHandler);

static std::mutex l_QueryMutex;
static std::map<String, ApiScriptFrame> l_ApiScriptFrames;
static Timer::Ptr l_FrameCleanupTimer;
static std::mutex l_ApiScriptMutex;
Expand Down
Loading
Loading