lib/gpg: Add helper to kill GPG agent

With GnuPG 2, any time you do basically any operation, a gpg-agent will
be spawned for the GPG home directory in use. The classic way to kill a
gpg-agent is to use `gpg-connect-agent` and send the `killagent` command
as is done in libtest.sh.

Closes: #1799
Approved by: cgwalters
This commit is contained in:
Dan Nicholson 2019-01-10 13:49:17 -06:00 committed by Atomic Bot
parent 0c63f30783
commit 4670837f7c
2 changed files with 28 additions and 0 deletions

View File

@ -437,3 +437,29 @@ ot_gpgme_new_ctx (const char *homedir,
return g_steal_pointer (&context);
}
void
ot_gpgme_kill_agent (const char *homedir)
{
g_return_if_fail (homedir != NULL);
/* Run gpg-connect-agent killagent /bye */
g_autoptr(GError) local_error = NULL;
g_autoptr(GSubprocess) proc = g_subprocess_new(G_SUBPROCESS_FLAGS_STDOUT_SILENCE,
&local_error,
"gpg-connect-agent",
"--homedir",
homedir,
"killagent",
"/bye",
NULL);
if (proc == NULL) {
g_debug ("Spawning gpg-connect-agent failed: %s", local_error->message);
return;
}
if (!g_subprocess_wait_check (proc, NULL, &local_error)) {
g_debug ("Killing GPG agent with gpg-connect-agent failed: %s",
local_error->message);
return;
}
}

View File

@ -46,4 +46,6 @@ gpgme_data_t ot_gpgme_data_output (GOutputStream *output_stream);
gpgme_ctx_t ot_gpgme_new_ctx (const char *homedir,
GError **error);
void ot_gpgme_kill_agent (const char *homedir);
G_END_DECLS