Module: check_mk
Branch: master
Commit: b4372ed8ee2c6ed68fd658458d22f02320109781
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b4372ed8ee2c6e…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Wed Apr 5 14:20:34 2017 +0200
Remove three global variables.
Change-Id: Ib105361adb7b6cf36840e630a8909ebce35d7937
---
livestatus/src/InputBuffer.cc | 21 ++++++++++-----------
livestatus/src/InputBuffer.h | 7 ++++++-
livestatus/src/module.cc | 11 ++++++-----
livestatus/src/waittriggers.cc | 6 +++---
4 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/livestatus/src/InputBuffer.cc b/livestatus/src/InputBuffer.cc
index bc31eaf..d76c94d 100644
--- a/livestatus/src/InputBuffer.cc
+++ b/livestatus/src/InputBuffer.cc
@@ -26,7 +26,6 @@
#include <sys/select.h>
#include <unistd.h>
#include <cctype>
-#include <chrono>
#include <cstring>
#include <ostream>
#include <ratio>
@@ -37,9 +36,6 @@ using std::chrono::milliseconds;
using std::chrono::system_clock;
using std::string;
-extern milliseconds g_query_timeout;
-extern milliseconds g_idle_timeout;
-
namespace {
const size_t initial_buffer_size = 4096;
// TODO(sp): Make this configurable?
@@ -52,9 +48,12 @@ bool timeout_reached(const system_clock::time_point &start,
}
} // namespace
-InputBuffer::InputBuffer(int fd, const bool &termination_flag, Logger *logger)
+InputBuffer::InputBuffer(int fd, const bool &termination_flag, Logger *logger,
+ milliseconds query_timeout, milliseconds idle_timeout)
: _fd(fd)
, _termination_flag(termination_flag)
+ , _query_timeout(query_timeout)
+ , _idle_timeout(idle_timeout)
, _readahead_buffer(initial_buffer_size)
, _logger(logger) {
_read_index = 0; // points to data not yet processed
@@ -98,14 +97,14 @@ InputBuffer::Result InputBuffer::readRequest() {
if (rd == Result::timeout) {
if (query_started) {
Informational(_logger)
- << "Timeout of " <<
g_query_timeout.count()
+ << "Timeout of " <<
_query_timeout.count()
<< " ms exceeded while reading query";
return Result::timeout;
}
// Check if we exceeded the maximum time between two queries
- if (timeout_reached(start_of_idle, g_idle_timeout)) {
+ if (timeout_reached(start_of_idle, _idle_timeout)) {
Informational(_logger)
- << "Idle timeout of " <<
g_idle_timeout.count()
+ << "Idle timeout of " <<
_idle_timeout.count()
<< " ms exceeded. Going to close
connection.";
return Result::timeout;
}
@@ -197,12 +196,12 @@ InputBuffer::Result InputBuffer::readRequest() {
}
}
-// read at least *some* data. Return IB_TIMEOUT if that
-// lasts more than g_query_timeout_msec msecs.
+// read at least *some* data. Return IB_TIMEOUT if that lasts more than
+// _query_timeout msecs.
InputBuffer::Result InputBuffer::readData() {
auto start = system_clock::now();
while (!_termination_flag) {
- if (timeout_reached(start, g_query_timeout)) {
+ if (timeout_reached(start, _query_timeout)) {
return Result::timeout;
}
diff --git a/livestatus/src/InputBuffer.h b/livestatus/src/InputBuffer.h
index ec05783..2579fb8 100644
--- a/livestatus/src/InputBuffer.h
+++ b/livestatus/src/InputBuffer.h
@@ -26,6 +26,7 @@
#define InputBuffer_h
#include "config.h" // IWYU pragma: keep
+#include <chrono>
#include <cstddef>
#include <list>
#include <string>
@@ -45,7 +46,9 @@ public:
timeout
};
- InputBuffer(int fd, const bool &termination_flag, Logger *logger);
+ InputBuffer(int fd, const bool &termination_flag, Logger *logger,
+ std::chrono::milliseconds query_timeout,
+ std::chrono::milliseconds idle_timeout);
Result readRequest();
bool empty() const;
std::string nextLine();
@@ -53,6 +56,8 @@ public:
private:
int _fd;
const bool &_termination_flag;
+ std::chrono::milliseconds _query_timeout;
+ std::chrono::milliseconds _idle_timeout;
std::vector<char> _readahead_buffer;
size_t _read_index;
size_t _write_index;
diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc
index 46a8003..2b62e45 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -86,10 +86,10 @@ extern int enable_environment_macros;
extern char *log_file;
// maximum idle time for connection in keep alive state
-milliseconds g_idle_timeout = minutes(5);
+static milliseconds fl_idle_timeout = minutes(5);
// maximum time for reading a query
-milliseconds g_query_timeout = seconds(10);
+static milliseconds fl_query_timeout = seconds(10);
size_t g_num_clientthreads =
10; /* allow 10 concurrent connections per default */
@@ -234,7 +234,8 @@ void *client_thread(void *data) {
Debug(fl_logger_livestatus) << "accepted client connection on fd
"
<< cc;
InputBuffer input_buffer(cc, fl_should_terminate,
- fl_logger_livestatus);
+ fl_logger_livestatus, fl_query_timeout,
+ fl_idle_timeout);
bool keepalive = true;
unsigned requestnr = 0;
while (keepalive) {
@@ -940,7 +941,7 @@ void livestatus_parse_arguments(const char *args_orig) {
if (c < 0) {
Warning(fl_logger_nagios) << "query_timeout must be >=
0";
} else {
- g_query_timeout = milliseconds(c);
+ fl_query_timeout = milliseconds(c);
if (c == 0) {
Notice(fl_logger_nagios) << "disabled query
timeout!";
} else {
@@ -954,7 +955,7 @@ void livestatus_parse_arguments(const char *args_orig) {
if (c < 0) {
Warning(fl_logger_nagios) << "idle_timeout must be >=
0";
} else {
- g_idle_timeout = milliseconds(c);
+ fl_idle_timeout = milliseconds(c);
if (c == 0) {
Notice(fl_logger_nagios) << "disabled idle
timeout!";
} else {
diff --git a/livestatus/src/waittriggers.cc b/livestatus/src/waittriggers.cc
index 0a196d3..56a9a97 100644
--- a/livestatus/src/waittriggers.cc
+++ b/livestatus/src/waittriggers.cc
@@ -45,7 +45,7 @@ condition_variable *from_trigger(struct trigger *c) {
return reinterpret_cast<condition_variable *>(c);
}
-mutex g_wait_mutex;
+mutex wait_mutex;
condition_variable cond_all;
condition_variable cond_check;
@@ -127,12 +127,12 @@ void trigger_notify_all(struct trigger *which) {
}
void trigger_wait(struct trigger *which) {
- unique_lock<mutex> ul(g_wait_mutex);
+ unique_lock<mutex> ul(wait_mutex);
from_trigger(which)->wait(ul);
}
int trigger_wait_for(struct trigger *which, unsigned ms) {
- unique_lock<mutex> ul(g_wait_mutex);
+ unique_lock<mutex> ul(wait_mutex);
return static_cast<int>(from_trigger(which)->wait_for(
ul, milliseconds(ms)) == cv_status::no_timeout);
}