diff --git a/lib/cli/daemonutility.cpp b/lib/cli/daemonutility.cpp index 4c862abb2..c73da694a 100644 --- a/lib/cli/daemonutility.cpp +++ b/lib/cli/daemonutility.cpp @@ -250,8 +250,6 @@ bool DaemonUtility::LoadConfigFiles(const std::vector& configs, return false; } - ConfigCompilerContext::GetInstance()->FinishObjectsFile(); - try { ScriptGlobal::WriteToFile(varsfile); } catch (const std::exception& ex) { @@ -259,5 +257,7 @@ bool DaemonUtility::LoadConfigFiles(const std::vector& configs, Application::Exit(1); } + ConfigCompilerContext::GetInstance()->FinishObjectsFile(); + return true; } diff --git a/lib/cli/objectlistcommand.cpp b/lib/cli/objectlistcommand.cpp index 4fb4c4a92..3bcb31512 100644 --- a/lib/cli/objectlistcommand.cpp +++ b/lib/cli/objectlistcommand.cpp @@ -18,6 +18,7 @@ #include #include #include +#include using namespace icinga; namespace po = boost::program_options; @@ -43,6 +44,19 @@ void ObjectListCommand::InitParameters(boost::program_options::options_descripti ("type,t", po::value(), "filter by type matches"); } +static time_t GetCtime(const String& path) +{ +#ifdef _WIN32 + struct _stat statbuf; + int rc = _stat(path.CStr(), &statbuf); +#else /* _WIN32 */ + struct stat statbuf; + int rc = stat(path.CStr(), &statbuf); +#endif /* _WIN32 */ + + return rc ? 0 : statbuf.st_ctime; +} + /** * The entry point for the "object list" CLI command. * @@ -104,6 +118,15 @@ int ObjectListCommand::Run(const boost::program_options::variables_map& vm, cons Log(LogNotice, "cli") << "Parsed " << objects_count << " objects."; + auto objectsPathCtime (GetCtime(Configuration::ObjectsPath)); + auto varsPathCtime (GetCtime(Configuration::VarsPath)); + + if (objectsPathCtime < varsPathCtime) { + Log(LogWarning, "cli") + << "This data is " << Utility::FormatDuration(varsPathCtime - objectsPathCtime) + << " older than the last Icinga config (re)load. It may be outdated. Consider running 'icinga2 daemon -C --dump-objects' first."; + } + return 0; }