=== modified file 'mandos-ctl' --- mandos-ctl 2019-03-17 17:34:07 +0000 +++ mandos-ctl 2019-03-17 18:17:02 +0000 @@ -962,16 +962,13 @@ @staticmethod @contextlib.contextmanager def redirect_stderr_to_devnull(): - null = os.open(os.path.devnull, os.O_RDWR) - stderrcopy = os.dup(sys.stderr.fileno()) - os.dup2(null, sys.stderr.fileno()) - os.close(null) - try: - yield - finally: - # restore stderr - os.dup2(stderrcopy, sys.stderr.fileno()) - os.close(stderrcopy) + old_stderr = sys.stderr + with contextlib.closing(open(os.devnull, "w")) as null: + sys.stderr = null + try: + yield + finally: + sys.stderr = old_stderr def check_option_syntax(self, options): check_option_syntax(self.parser, options)