Module: check_mk
Branch: master
Commit: 2f27f7df2519086f3c9e2549b94b716b615625d7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2f27f7df251908…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Mon Jul 17 10:49:59 2017 +0200
Various improvements to error handling in the CMC
* fcntl/socketpair/pipe/fork return values are always checked.
* If things went wrong, log this and explicitly fail instead of proceeding
silenty, only to run into more obscure problems later.
* Log such failures as alerts: If these basic things go wrong, you have a
*serious* problem.
* Fixed various file descriptor leaks in case of an error.
Change-Id: I727c335c22b2df1bfa10c1a3386285962a7cc678
---
livestatus/src/module.cc | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc
index 638de13..3af6300 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -210,10 +210,11 @@ void *main_thread(void *data) {
if (cc > g_max_fd_ever) {
g_max_fd_ever = cc;
}
- if (fcntl(cc, F_SETFD, FD_CLOEXEC) < 0) {
+ if (fcntl(cc, F_SETFD, FD_CLOEXEC) == -1) {
generic_error ge(
"cannot set close-on-exec bit on client socket");
- Warning(fl_logger_livestatus) << ge;
+ Alert(fl_logger_livestatus) << ge;
+ break;
}
fl_client_queue->addConnection(cc); // closes fd
g_num_queued_connections++;
@@ -395,9 +396,11 @@ bool open_unix_socket() {
}
// Imortant: close on exec -> check plugins must not inherit it!
- if (fcntl(g_unix_socket, F_SETFD, FD_CLOEXEC) < 0) {
+ if (fcntl(g_unix_socket, F_SETFD, FD_CLOEXEC) == -1) {
generic_error ge("cannot set close-on-exec bit on socket");
- Informational(fl_logger_nagios) << ge;
+ Alert(fl_logger_nagios) << ge;
+ close(g_unix_socket);
+ return false;
}
// Bind it to its address. This creates the file with the name