Module: check_mk
Branch: master
Commit: bc93301565474eace56864d9c6299a0aea289bfb
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=bc93301565474e…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Mon Aug 29 15:03:41 2016 +0200
Make the logfile path non-global.
---
livestatus/src/logger.cc | 9 +++++----
livestatus/src/logger.h | 3 ++-
livestatus/src/module.cc | 16 ++++++++--------
3 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/livestatus/src/logger.cc b/livestatus/src/logger.cc
index 26ead67..2fc12f4 100644
--- a/livestatus/src/logger.cc
+++ b/livestatus/src/logger.cc
@@ -34,16 +34,17 @@
#include <ctime>
#include "nagios.h"
-extern char g_logfile_path[];
+using std::string;
+
pthread_t g_mainthread_id;
FILE *g_logfile = nullptr;
-void open_logfile() {
- g_logfile = fopen(g_logfile_path, "a");
+void open_logfile(const string &path) {
+ g_logfile = fopen(path.c_str(), "a");
// needed to determine main thread later
g_mainthread_id = pthread_self();
if (g_logfile == nullptr) {
- logger(LOG_WARNING, "Cannot open logfile %s: %s", g_logfile_path,
+ logger(LOG_WARNING, "Cannot open logfile %s: %s", path.c_str(),
strerror(errno));
}
}
diff --git a/livestatus/src/logger.h b/livestatus/src/logger.h
index 678f67a..f0bf6a5 100644
--- a/livestatus/src/logger.h
+++ b/livestatus/src/logger.h
@@ -27,10 +27,11 @@
#include "config.h" // IWYU pragma: keep
#include <syslog.h>
+#include <string>
void logger(int priority, const char *loginfo, ...)
__attribute__((format(printf, 2, 3)));
-void open_logfile();
+void open_logfile(const std::string &path);
void close_logfile();
#endif // logger_h
diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc
index 05e3723..1e5f692 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -97,7 +97,7 @@ char pnp_path_storage[4096];
char *g_pnp_path = pnp_path_storage;
char g_mk_inventory_path[4096]; // base path of Check_MK inventory files
char g_mk_logwatch_path[4096]; // base path of Check_MK logwatch files
-char g_logfile_path[4096];
+static char fl_logfile_path[4096];
char g_mkeventd_socket_path[4096];
int g_debug_level = 0;
int g_should_terminate = false;
@@ -670,11 +670,11 @@ void livestatus_parse_arguments(const char *args_orig) {
strncpy(g_socket_path, DEFAULT_SOCKET_PATH, sizeof(g_socket_path));
/* set default path to our logfile to be in the same path as nagios.log */
- strncpy(g_logfile_path, log_file,
- sizeof(g_logfile_path) - 16 /* len of "livestatus.log" */);
- char *slash = strrchr(g_logfile_path, '/');
+ strncpy(fl_logfile_path, log_file,
+ sizeof(fl_logfile_path) - 16 /* len of "livestatus.log" */);
+ char *slash = strrchr(fl_logfile_path, '/');
if (slash == nullptr) {
- strncpy(g_logfile_path, "/tmp/livestatus.log", 20);
+ strncpy(fl_logfile_path, "/tmp/livestatus.log", 20);
} else {
strncpy(slash + 1, "livestatus.log", 15);
}
@@ -701,7 +701,7 @@ void livestatus_parse_arguments(const char *args_orig) {
g_debug_level = atoi(right);
Informational() << "Setting debug level to " <<
g_debug_level;
} else if (strcmp(left, "log_file") == 0) {
- strncpy(g_logfile_path, right, sizeof(g_logfile_path));
+ strncpy(fl_logfile_path, right, sizeof(fl_logfile_path));
} else if (strcmp(left, "mkeventd_socket_path") == 0) {
strncpy(g_mkeventd_socket_path, right,
sizeof(g_mkeventd_socket_path));
@@ -866,7 +866,7 @@ extern "C" int nebmodule_init(int flags
__attribute__((__unused__)), char *args,
void *handle) {
g_nagios_handle = handle;
livestatus_parse_arguments(args);
- open_logfile();
+ open_logfile(fl_logfile_path);
Informational() << "Livestatus " << VERSION
<< " by Mathias Kettner. Socket: '" <<
g_socket_path << "'";
@@ -903,7 +903,7 @@ extern "C" int nebmodule_init(int flags
__attribute__((__unused__)), char *args,
that happens, we haven't got any data anyway... */
Informational() << "Finished initialization. Further log messages go to
"
- << g_logfile_path;
+ << fl_logfile_path;
return 0;
}