From: Michael Orlitzky Date: Tue, 20 Sep 2022 23:21:28 +0000 (-0400) Subject: bin/djbdns-logparse: handle SIGINT (again). X-Git-Tag: 0.0.1~17 X-Git-Url: http://gitweb.michael.orlitzky.com/?p=djbdns-logparse.git;a=commitdiff_plain;h=d5ffd8dfd137722335b066be63bb24289a52c71a bin/djbdns-logparse: handle SIGINT (again). I removed the KeyboardInterrupt handler from the original program and have now put it back as an async handler for SIGINT. This is helpful when the user accidentally starts the program with no arguments and it just sits there until he hits Ctrl-C (which would previously have shown a stack trace). --- diff --git a/bin/djbdns-logparse b/bin/djbdns-logparse index 7808fbd..218801d 100755 --- a/bin/djbdns-logparse +++ b/bin/djbdns-logparse @@ -2,6 +2,8 @@ r""" Convert tinydns and dnscache logs to human-readable form """ +from signal import signal, SIGINT +from sys import exit, stdin from argparse import ArgumentParser, FileType from djbdns.io import parse_logfile @@ -11,7 +13,6 @@ parser = ArgumentParser(description = __doc__) # Parse zero or more positional arguments into a list of # "logfiles". If none are given, read from stdin instead. -from sys import stdin parser.add_argument("logfiles", metavar="LOGFILE", type=FileType("r"), @@ -29,5 +30,11 @@ parser.add_argument("logfiles", # # So anyway, don't run this on several million logfiles. args = parser.parse_args() + +# Install a SIGINT handler so thst we don't spit out a stack trace when +# the user accidentally starts the program with no arguments and then +# hits Ctrl-C to kill it. +signal(SIGINT, lambda s,f: exit(0)) + for f in args.logfiles: parse_logfile(f)