From 39d4bb3c35ffb3bc6cdead5ecb58b3377f87867c Mon Sep 17 00:00:00 2001 From: sebres Date: Tue, 11 Aug 2020 13:57:36 +0200 Subject: [PATCH] closes gh-2758: no explicit flush (close std-channels on exit, it would cause implicit flush without to produce an error 32 "Broken pipe" on closed pipe) --- fail2ban/client/fail2bancmdline.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fail2ban/client/fail2bancmdline.py b/fail2ban/client/fail2bancmdline.py index 53c86de6..8936e03f 100644 --- a/fail2ban/client/fail2bancmdline.py +++ b/fail2ban/client/fail2bancmdline.py @@ -308,6 +308,10 @@ class Fail2banCmdLine(): # since method is also exposed in API via globally bound variable @staticmethod def _exit(code=0): + # implicit flush without to produce broken pipe error (32): + sys.stderr.close() + sys.stdout.close() + # exit: if hasattr(os, '_exit') and os._exit: os._exit(code) else: @@ -318,8 +322,6 @@ class Fail2banCmdLine(): logSys.debug("Exit with code %s", code) # because of possible buffered output in python, we should flush it before exit: logging.shutdown() - sys.stdout.flush() - sys.stderr.flush() # exit Fail2banCmdLine._exit(code)