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,6 +77,7 @@ 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 = []
if sys.stdin.isatty(): # short-circuit calling `tty`
try: try:
ttyname = subprocess.check_output(args=['tty']).strip() ttyname = subprocess.check_output(args=['tty']).strip()
options.append(b'ttyname=' + ttyname) options.append(b'ttyname=' + ttyname)