Skip to content

Commit

Permalink
fail2ban-regex: don't error by output if stdout pipe gets closed (e…
Browse files Browse the repository at this point in the history
…. g. using together with `head`);

amend to gh-2758 (see gh-3653)
  • Loading branch information
sebres committed Dec 22, 2023
1 parent 7523a77 commit c6244a8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions fail2ban/client/fail2banregex.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,15 @@ def start(self, args):
return True


def _loc_except_hook(exctype, value, traceback):
if (exctype != BrokenPipeError and exctype != IOError or value.errno != 32):
return sys.__excepthook__(exctype, value, traceback)
# pipe seems to be closed (head / tail / etc), thus simply exit:
sys.exit(0)

def exec_command_line(*args):
sys.excepthook = _loc_except_hook; # stop on closed/broken pipe

logging.exitOnIOError = True
parser = get_opt_parser()
(opts, args) = parser.parse_args(*args)
Expand Down

0 comments on commit c6244a8

Please sign in to comment.