Module: check_mk
Branch: master
Commit: cb1c2f4c9fdcc9e9235082c634e667bd5e89b38b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=cb1c2f4c9fdcc9…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Sep 3 14:25:43 2015 +0200
#2581 FIX Fix crashing Nagios core in rare case when excessive commands are being
executed
The crash was due to the fact that the internal Nagios API for executing commands
is not thread safe. The CMC was not affected. This fixes the problems:
http://tracker.nagios.org/view.php?id=656
http://lists.mathias-kettner.de/pipermail/checkmk-en/2015-February/014497.h…
Thanks to Ryan C. Underwood for the patch!
---
.werks/2581 | 17 +++++++++++++++++
ChangeLog | 1 +
livestatus/src/Store.cc | 10 ++++++++++
livestatus/src/Store.h | 3 +++
4 files changed, 31 insertions(+)
diff --git a/.werks/2581 b/.werks/2581
new file mode 100644
index 0000000..ca2a6eb
--- /dev/null
+++ b/.werks/2581
@@ -0,0 +1,17 @@
+Title: Fix crashing Nagios core in rare case when excessive commands are being executed
+Level: 2
+Component: livestatus
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.7i3
+Date: 1441283031
+
+The crash was due to the fact that the internal Nagios API for executing commands
+is not thread safe. The CMC was not affected. This fixes the problems:
+
+http://tracker.nagios.org/view.php?id=656
+
+http://lists.mathias-kettner.de/pipermail/checkmk-en/2015-February/014497.html
+
+Thanks to Ryan C. Underwood for the patch!
diff --git a/ChangeLog b/ChangeLog
index 700435c..dc03de0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -256,6 +256,7 @@
Livestatus:
* 2493 FIX: Fixed wrong JSON format when using stats queries together with header
columns...
* 2542 FIX: Fix segmentation fault when filtering for service columns in log
table...
+ * 2581 FIX: Fix crashing Nagios core in rare case when excessive commands are being
executed...
HW/SW-Inventory:
* 2128 mk_inventory.vbs: inventory plugin for Windows now available as vbs script...
diff --git a/livestatus/src/Store.cc b/livestatus/src/Store.cc
index e2fd4e0..57449cb 100644
--- a/livestatus/src/Store.cc
+++ b/livestatus/src/Store.cc
@@ -89,8 +89,16 @@ Store::Store()
{
_table_columns.addTable(it->second);
}
+
+ pthread_mutex_init(&_command_mutex, NULL);
}
+Store::~Store()
+{
+ pthread_mutex_destroy(&_command_mutex);
+}
+
+
Table *Store::findTable(string name)
{
_tables_t::iterator it = _tables.find(name);
@@ -147,6 +155,7 @@ bool Store::answerRequest(InputBuffer *input, OutputBuffer *output)
void Store::answerCommandRequest(const char *command)
{
+ pthread_mutex_lock(&_command_mutex);
#ifdef NAGIOS4
process_external_command1((char *)command);
#else
@@ -154,6 +163,7 @@ void Store::answerCommandRequest(const char *command)
/* int ret = */
submit_external_command((char *)command, &buffer_items);
#endif
+ pthread_mutex_unlock(&_command_mutex);
}
diff --git a/livestatus/src/Store.h b/livestatus/src/Store.h
index 5d72b41..19b35e0 100644
--- a/livestatus/src/Store.h
+++ b/livestatus/src/Store.h
@@ -68,8 +68,11 @@ class Store
typedef map<string, Table *> _tables_t;
_tables_t _tables;
+ pthread_mutex_t _command_mutex;
+
public:
Store();
+ ~Store();
LogCache* logCache() { return &_log_cache; };
void registerHostgroup(hostgroup *);
void registerComment(nebstruct_comment_data *);