From 6c2b880b7d6a29342d618eebccf521e4a6e8d480 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Sat, 16 Oct 2021 20:58:30 +0300 Subject: [PATCH] Support daemonization of GPG agent --- libagent/gpg/__init__.py | 11 +++++++++++ setup.py | 1 + 2 files changed, 12 insertions(+) diff --git a/libagent/gpg/__init__.py b/libagent/gpg/__init__.py index 5ed6af9..51d50fb 100644 --- a/libagent/gpg/__init__.py +++ b/libagent/gpg/__init__.py @@ -226,6 +226,8 @@ def run_agent(device_type): p.add_argument('-v', '--verbose', default=0, action='count') p.add_argument('--server', default=False, action='store_true', help='Use stdin/stdout for communication with GPG.') + p.add_argument('--daemon', default=False, action='store_true', + help='Daemonize the agent.') p.add_argument('--pin-entry-binary', type=str, default='pinentry', help='Path to PIN entry UI helper.') @@ -236,6 +238,15 @@ def run_agent(device_type): args, _ = p.parse_known_args() + if args.daemon: + with daemon.DaemonContext(): + run_agent_internal(args, device_type) + else: + run_agent_internal(args, device_type) + + +def run_agent_internal(args, device_type): + """Actually run the server.""" assert args.homedir log_file = os.path.join(args.homedir, 'gpg-agent.log') diff --git a/setup.py b/setup.py index 97b184a..e3396df 100755 --- a/setup.py +++ b/setup.py @@ -17,6 +17,7 @@ setup( ], install_requires=[ 'docutils>=0.14', + 'python-daemon>=2.3.0', 'wheel>=0.32.3', 'backports.shutil_which>=3.5.1', 'ConfigArgParse>=0.12.1',