From 827119a18d2683cc56d8071c19bca09f7aaea890 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Thu, 10 Nov 2016 23:29:47 +0200 Subject: [PATCH] gpg: handle KILLAGENT command so `gpg-connect-agent KILLAGENT` should stop the running agent --- trezor_agent/gpg/__main__.py | 3 +++ trezor_agent/gpg/agent.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/trezor_agent/gpg/__main__.py b/trezor_agent/gpg/__main__.py index 4aa92b6..5f6a5b5 100755 --- a/trezor_agent/gpg/__main__.py +++ b/trezor_agent/gpg/__main__.py @@ -112,6 +112,9 @@ def main_agent(): with contextlib.closing(conn): try: agent.handle_connection(conn) + except StopIteration: + log.info('stopping gpg-agent') + return except Exception as e: # pylint: disable=broad-except log.exception('gpg-agent failed: %s', e) diff --git a/trezor_agent/gpg/agent.py b/trezor_agent/gpg/agent.py index 22b6f31..b4ae5a0 100644 --- a/trezor_agent/gpg/agent.py +++ b/trezor_agent/gpg/agent.py @@ -142,6 +142,9 @@ def handle_connection(conn): keyring.sendline(conn, fmt.format(keygrip).encode('ascii')) elif command == b'BYE': return + elif command == b'KILLAGENT': + keyring.sendline(conn, b'OK') + raise StopIteration else: log.error('unknown request: %r', line) return