Short-circuit calling tty if stdin is redirected

This commit is contained in:
Roman Zeyde
2020-12-25 09:27:57 +02:00
parent f5b99c0794
commit dbae284487

View File

@@ -3,6 +3,7 @@
import logging import logging
import os import os
import subprocess import subprocess
import sys
try: try:
from trezorlib.client import PASSPHRASE_ON_DEVICE from trezorlib.client import PASSPHRASE_ON_DEVICE
@@ -76,11 +77,12 @@ class UI:
def create_default_options_getter(): def create_default_options_getter():
"""Return current TTY and DISPLAY settings for GnuPG pinentry.""" """Return current TTY and DISPLAY settings for GnuPG pinentry."""
options = [] options = []
try: if sys.stdin.isatty(): # short-circuit calling `tty`
ttyname = subprocess.check_output(args=['tty']).strip() try:
options.append(b'ttyname=' + ttyname) ttyname = subprocess.check_output(args=['tty']).strip()
except subprocess.CalledProcessError as e: options.append(b'ttyname=' + ttyname)
log.warning('no TTY found: %s', e) except subprocess.CalledProcessError as e:
log.warning('no TTY found: %s', e)
display = os.environ.get('DISPLAY') display = os.environ.get('DISPLAY')
if display is not None: if display is not None: