Module: check_mk
Branch: master
Commit: ab402feaabdcf75005bcd9fa74e653a823b1b7a9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ab402feaabdcf7…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Wed Feb 17 14:07:34 2016 +0100
#3233 FIX Fixed shutdown of Nagios core with Livestatus module
The Nagios core no longer hangs now during shutdown when the Livestatus
module is used. This resulted in a long delay before the core was finally
killed forcefully.
---
.werks/3233 | 13 +++++++++++++
ChangeLog | 3 +++
livestatus/src/ClientQueue.cc | 15 ++++++++++++---
livestatus/src/ClientQueue.h | 3 ++-
livestatus/src/module.c | 2 +-
livestatus/src/store_c.cc | 2 +-
livestatus/src/store_c.h | 2 +-
7 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/.werks/3233 b/.werks/3233
new file mode 100644
index 0000000..7faa26d
--- /dev/null
+++ b/.werks/3233
@@ -0,0 +1,13 @@
+Title: Fixed shutdown of Nagios core with Livestatus module
+Level: 1
+Component: livestatus
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.9i1
+Date: 1455714163
+
+The Nagios core no longer hangs now during shutdown when the Livestatus
+module is used. This resulted in a long delay before the core was finally
+killed forcefully.
+
diff --git a/ChangeLog b/ChangeLog
index 15f8d55..332a18a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -47,6 +47,9 @@
Event Console:
* 3058 FIX: Event Console is now allowing non loadable MIB modules on startup...
+ Livestatus:
+ * 3233 FIX: Fixed shutdown of Nagios core with Livestatus module...
+
HW/SW-Inventory:
* 3219 FIX: lnx_distro: Now detecting Oracle VM Server correctly
diff --git a/livestatus/src/ClientQueue.cc b/livestatus/src/ClientQueue.cc
index 254e928..a446580 100644
--- a/livestatus/src/ClientQueue.cc
+++ b/livestatus/src/ClientQueue.cc
@@ -31,7 +31,7 @@ using mk::mutex;
using mk::unique_lock;
using std::for_each;
-ClientQueue::ClientQueue() {}
+ClientQueue::ClientQueue() : _should_terminate(false) {}
ClientQueue::~ClientQueue() { for_each(_queue.begin(), _queue.end(), close); }
@@ -45,9 +45,12 @@ void ClientQueue::addConnection(int fd) {
int ClientQueue::popConnection() {
unique_lock<mutex> ul(_mutex);
- while (_queue.empty()) {
+ while (_queue.empty() && !_should_terminate) {
_cond.wait(ul);
}
+ if (_queue.empty()) {
+ return -1;
+ }
int fd = _queue.front();
_queue.pop_front();
return fd;
@@ -55,4 +58,10 @@ int ClientQueue::popConnection() {
// Note: What we *really* want here is the functionality of
// notify_all_at_thread_exit.
-void ClientQueue::wakeupAll() { _cond.notify_all(); }
+void ClientQueue::terminate() {
+ {
+ lock_guard<mutex> lg(_mutex);
+ _should_terminate = true;
+ }
+ _cond.notify_all();
+}
diff --git a/livestatus/src/ClientQueue.h b/livestatus/src/ClientQueue.h
index 44d2138..7c155ed 100644
--- a/livestatus/src/ClientQueue.h
+++ b/livestatus/src/ClientQueue.h
@@ -37,13 +37,14 @@ public:
~ClientQueue();
void addConnection(int);
int popConnection();
- void wakeupAll();
+ void terminate();
private:
typedef std::deque<int> _queue_t;
_queue_t _queue;
mk::mutex _mutex;
mk::condition_variable _cond;
+ bool _should_terminate;
};
#endif // ClientQueue_h
diff --git a/livestatus/src/module.c b/livestatus/src/module.c
index 15717e5..0671efd 100644
--- a/livestatus/src/module.c
+++ b/livestatus/src/module.c
@@ -281,7 +281,7 @@ void terminate_threads() {
logger(LG_INFO, "Waiting for main to terminate...");
pthread_join(g_mainthread_id, NULL);
logger(LG_INFO, "Waiting for client threads to terminate...");
- queue_wakeup_all();
+ queue_terminate();
int t;
for (t = 0; t < g_num_clientthreads; t++) {
if (0 != pthread_join(g_clientthread_id[t], NULL)) {
diff --git a/livestatus/src/store_c.cc b/livestatus/src/store_c.cc
index 9d22bd1..b036516 100644
--- a/livestatus/src/store_c.cc
+++ b/livestatus/src/store_c.cc
@@ -58,7 +58,7 @@ void queue_add_connection(int cc) {
g_client_queue->addConnection(cc); }
int queue_pop_connection() { return g_client_queue->popConnection(); }
-void queue_wakeup_all() { return g_client_queue->wakeupAll(); }
+void queue_terminate() { return g_client_queue->terminate(); }
void store_register_comment(nebstruct_comment_data *d) {
g_store->registerComment(d);
diff --git a/livestatus/src/store_c.h b/livestatus/src/store_c.h
index ccef9eb..7b18ed5 100644
--- a/livestatus/src/store_c.h
+++ b/livestatus/src/store_c.h
@@ -45,7 +45,7 @@ void *create_inputbuffer(int fd, const int *termination_flag);
void delete_inputbuffer(void *);
void queue_add_connection(int cc);
int queue_pop_connection();
-void queue_wakeup_all();
+void queue_terminate();
void update_timeperiods_cache(time_t);
void log_timeperiods_cache();