Module: check_mk
Branch: master
Commit: 2df021a0efeb011b7c2490235461babd5d39ceb6
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2df021a0efeb01…
Author: Konstantin Büttner <kb(a)mathias-kettner.de>
Date: Thu Dec 20 12:35:20 2018 +0100
EC: Minor refactoring
Having the non-EOF-case first when reading data from a pipe is more readable.
Change-Id: Ia173ab58a412bed6a4660998f7a3979d19c8e125
---
cmk/ec/main.py | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/cmk/ec/main.py b/cmk/ec/main.py
index a4372d0..4e10814 100644
--- a/cmk/ec/main.py
+++ b/cmk/ec/main.py
@@ -1002,17 +1002,7 @@ class EventServer(ECServerThread):
if pipe in readable:
try:
data = os.read(pipe, 4096)
- if len(data) == 0: # END OF FILE!
- os.close(pipe)
- pipe = self.open_pipe()
- listen_list[0] = pipe
- # Pending fragments from previos reads that are not terminated
- # by a \n are ignored.
- if pipe_fragment:
- self._logger.warning(
- "Ignoring incomplete message '%s' from
pipe" % pipe_fragment)
- pipe_fragment = ""
- else:
+ if data:
# Prepend previous beginning of message to read data
data = pipe_fragment + data
pipe_fragment = ""
@@ -1026,6 +1016,16 @@ class EventServer(ECServerThread):
pipe_fragment = data # keep beginning of message, wait
for \n
else:
self.process_raw_lines(data)
+ else: # EOF
+ os.close(pipe)
+ pipe = self.open_pipe()
+ listen_list[0] = pipe
+ # Pending fragments from previos reads that are not terminated
+ # by a \n are ignored.
+ if pipe_fragment:
+ self._logger.warning(
+ "Ignoring incomplete message '%s' from
pipe" % pipe_fragment)
+ pipe_fragment = ""
except Exception:
pass