Fix incorrect SIGPIPE handling
This commit is contained in:
parent
7528c2465f
commit
a5d5be3462
|
@ -236,12 +236,13 @@ def command_help(args):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def nocommand(args):
|
||||||
|
print("command required")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""CLI entry point"""
|
"""CLI entry point"""
|
||||||
# Enable piping
|
|
||||||
from signal import signal, SIGPIPE, SIG_DFL
|
|
||||||
signal(SIGPIPE, SIG_DFL)
|
|
||||||
|
|
||||||
# Collect the commands from this module
|
# Collect the commands from this module
|
||||||
import inquisitor.cli
|
import inquisitor.cli
|
||||||
commands = {
|
commands = {
|
||||||
|
@ -283,8 +284,11 @@ def main():
|
||||||
add_logging_handler(verbose=args.verbose, log_filename=None)
|
add_logging_handler(verbose=args.verbose, log_filename=None)
|
||||||
|
|
||||||
# Execute command
|
# Execute command
|
||||||
if args.command:
|
try:
|
||||||
sys.exit(commands[args.command](args.args))
|
command = commands.get(args.command, nocommand)
|
||||||
else:
|
sys.exit(command(args.args))
|
||||||
print("command required")
|
except BrokenPipeError:
|
||||||
sys.exit(0)
|
# See https://docs.python.org/3.10/library/signal.html#note-on-sigpipe
|
||||||
|
devnull = os.open(os.devnull, os.O_WRONLY)
|
||||||
|
os.dup2(devnull, sys.stdout.fileno())
|
||||||
|
sys.exit(1)
|
||||||
|
|
Loading…
Reference in New Issue