Module: check_mk
Branch: master
Commit: 2974e58c73441211f12014389e34555dbeac0368
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2974e58c734412…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Thu Dec 20 13:40:40 2012 +0100
FIX: mkeventd: remove event pipe on program shutdown
---
ChangeLog | 1 +
mkeventd/bin/mkeventd | 24 ++++++++++++++++++++++++
2 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 0ec8b7a..0c2e3e8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -80,6 +80,7 @@
* Speedup access to event history by earlier filtering and prefiltering with grep
* New builtin syslog server! Please refer to online docu for details.
* Icon to events of host links to view that has context button to host
+ * FIX: remove event pipe on program shutdown, prevents syslog freeze
1.2.1i3:
Core:
diff --git a/mkeventd/bin/mkeventd b/mkeventd/bin/mkeventd
index 2cec2a3..642ab46 100755
--- a/mkeventd/bin/mkeventd
+++ b/mkeventd/bin/mkeventd
@@ -131,6 +131,21 @@ def open_logfile():
global g_logfile
g_logfile = file(g_logfile_path, "a")
+
+def drain_pipe(pipe):
+ while True:
+ readable = select.select([ pipe ], [], [], 1)[0]
+ data = None
+ if pipe in readable:
+ try:
+ data = os.read(pipe, 4096)
+ if len(data) == 0: # END OF FILE!
+ break
+ except:
+ break # Error while reading
+ else:
+ break # No data available
+
def log(text):
if type(text) == unicode:
text = text.encode("utf-8")
@@ -2654,6 +2669,15 @@ try:
# We reach this point, if the server has been killed by
# a signal or hitting Ctrl-C (in foreground mode)
+ # Remove event pipe and drain it, so that we make sure
+ # that processes (syslog, etc) will not hang when trying
+ # to write into the pipe.
+ log("Cleaning up event pipe")
+ pipe = g_event_server.open_pipe() # Open it
+ os.remove(g_pipe_path) # Remove pipe
+ drain_pipe(pipe) # Drain any data
+ os.close(pipe) # Close pipe
+
g_event_status.save_status()
os.remove(g_socket_path)
os.remove(g_pid_file)