Module: check_mk
Branch: master
Commit: 068974e1c09dc73595aef5643f6c9441f573343a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=068974e1c09dc7…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Mon Apr 8 15:45:43 2019 +0200
Use std::filesystem a bit more, simplifying things.
Change-Id: I2a96a3564783bfa9e5c0f3504371149e23e95a3a
---
livestatus/src/LogwatchListColumn.cc | 6 +++---
livestatus/src/LogwatchListColumn.h | 3 ++-
livestatus/src/mk_logwatch.cc | 9 +++++----
livestatus/src/mk_logwatch.h | 3 ++-
livestatus/src/module.cc | 12 ------------
5 files changed, 12 insertions(+), 21 deletions(-)
diff --git a/livestatus/src/LogwatchListColumn.cc b/livestatus/src/LogwatchListColumn.cc
index b3ab6b3..11710d4 100644
--- a/livestatus/src/LogwatchListColumn.cc
+++ b/livestatus/src/LogwatchListColumn.cc
@@ -62,12 +62,12 @@ std::vector<std::string> LogwatchListColumn::getValue(
return {};
}
-std::string LogwatchListColumn::getDirectory(Row row) const {
+fs::path LogwatchListColumn::getDirectory(Row row) const {
auto logwatch_path = _mc->mkLogwatchPath();
auto host_name = getHostName(row);
return logwatch_path.empty() || host_name.empty()
- ? ""
- : logwatch_path + pnp_cleanup(host_name);
+ ? fs::path()
+ : fs::path(logwatch_path) / pnp_cleanup(host_name);
}
std::string LogwatchListColumn::getHostName(Row row) const {
diff --git a/livestatus/src/LogwatchListColumn.h b/livestatus/src/LogwatchListColumn.h
index e090d04..b640c93 100644
--- a/livestatus/src/LogwatchListColumn.h
+++ b/livestatus/src/LogwatchListColumn.h
@@ -29,6 +29,7 @@
#include <chrono>
#include <string>
#include <vector>
+#include "FileSystem.h"
#include "ListColumn.h"
#include "contact_fwd.h"
class MonitoringCore;
@@ -50,7 +51,7 @@ public:
private:
MonitoringCore *_mc;
- std::string getDirectory(Row row) const;
+ fs::path getDirectory(Row row) const;
std::string getHostName(Row row) const;
};
diff --git a/livestatus/src/mk_logwatch.cc b/livestatus/src/mk_logwatch.cc
index dc23876..ba315c3 100644
--- a/livestatus/src/mk_logwatch.cc
+++ b/livestatus/src/mk_logwatch.cc
@@ -23,12 +23,12 @@
// Boston, MA 02110-1301 USA.
#include "mk_logwatch.h"
-#include <unistd.h>
#include <ostream>
+#include <system_error>
#include "Logger.h"
#include "pnp4nagios.h"
-void mk_logwatch_acknowledge(Logger *logger, const std::string &logwatch_path,
+void mk_logwatch_acknowledge(Logger *logger, const fs::path &logwatch_path,
const std::string &host_name,
const std::string &file_name) {
if (file_name.find('/') != std::string::npos) {
@@ -39,8 +39,9 @@ void mk_logwatch_acknowledge(Logger *logger, const std::string
&logwatch_path,
if (logwatch_path.empty()) {
return;
}
- std::string path = logwatch_path + pnp_cleanup(host_name) + "/" +
file_name;
- if (unlink(path.c_str()) != 0) {
+ auto path = fs::path(logwatch_path) / pnp_cleanup(host_name) / file_name;
+ std::error_code ec;
+ if (!fs::remove(path, ec)) {
generic_error ge("Cannot acknowledge mk_logfile file '" + file_name
+
"' of host '" + host_name +
"'");
Warning(logger) << ge;
diff --git a/livestatus/src/mk_logwatch.h b/livestatus/src/mk_logwatch.h
index b373911..164643e 100644
--- a/livestatus/src/mk_logwatch.h
+++ b/livestatus/src/mk_logwatch.h
@@ -27,9 +27,10 @@
#include "config.h" // IWYU pragma: keep
#include <string>
+#include "FileSystem.h"
class Logger;
-void mk_logwatch_acknowledge(Logger *logger, const std::string &logwatch_path,
+void mk_logwatch_acknowledge(Logger *logger, const fs::path &logwatch_path,
const std::string &host_name,
const std::string &file_name);
diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc
index 6fb25fe..b8d53b2 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -1121,29 +1121,17 @@ void livestatus_parse_arguments(const char *args_orig) {
}
} else if (strcmp(left, "pnp_path") == 0) {
fl_paths._pnp_path = right;
- if (right[strlen(right) - 1] != '/') {
- fl_paths._pnp_path += "/";
- }
check_path("PNP perfdata directory", fl_paths._pnp_path);
} else if (strcmp(left, "mk_inventory_path") == 0) {
fl_paths._mk_inventory_path = right;
- if (right[strlen(right) - 1] != '/') {
- fl_paths._mk_inventory_path += "/";
- }
check_path("Check_MK Inventory directory",
fl_paths._mk_inventory_path);
} else if (strcmp(left, "structured_status_path") == 0) {
fl_paths._structured_status_path = right;
- if (right[strlen(right) - 1] != '/') {
- fl_paths._structured_status_path += "/";
- }
check_path("Check_MK structured status directory",
fl_paths._structured_status_path);
} else if (strcmp(left, "mk_logwatch_path") == 0) {
fl_paths._mk_logwatch_path = right;
- if (right[strlen(right) - 1] != '/') {
- fl_paths._mk_logwatch_path += "/";
- }
check_path("Check_MK logwatch directory",
fl_paths._mk_logwatch_path);
} else if (strcmp(left, "data_encoding") == 0) {