From dbae28448732d6a7085b71ea7a2e8ff2752d63be Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Fri, 25 Dec 2020 09:27:57 +0200 Subject: [PATCH] Short-circuit calling `tty` if stdin is redirected --- libagent/device/ui.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libagent/device/ui.py b/libagent/device/ui.py index baf0ecf..4d91437 100644 --- a/libagent/device/ui.py +++ b/libagent/device/ui.py @@ -3,6 +3,7 @@ import logging import os import subprocess +import sys try: from trezorlib.client import PASSPHRASE_ON_DEVICE @@ -76,11 +77,12 @@ class UI: def create_default_options_getter(): """Return current TTY and DISPLAY settings for GnuPG pinentry.""" options = [] - try: - ttyname = subprocess.check_output(args=['tty']).strip() - options.append(b'ttyname=' + ttyname) - except subprocess.CalledProcessError as e: - log.warning('no TTY found: %s', e) + if sys.stdin.isatty(): # short-circuit calling `tty` + try: + ttyname = subprocess.check_output(args=['tty']).strip() + options.append(b'ttyname=' + ttyname) + except subprocess.CalledProcessError as e: + log.warning('no TTY found: %s', e) display = os.environ.get('DISPLAY') if display is not None: