From 30b7cb343f6533f7f1c4035c21163a028b38d471 Mon Sep 17 00:00:00 2001 From: Mikhail Efremov Date: Sat, 28 Apr 2012 16:48:22 +0400 Subject: [PATCH] Fix gpg-agent shutdown. If gpg-agent was started without ssh support then don't use SSH_AGENT_PID. --- xfce4-session/xfsm-startup.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/xfce4-session/xfsm-startup.c b/xfce4-session/xfsm-startup.c index 911eec6..701d98e 100644 --- a/xfce4-session/xfsm-startup.c +++ b/xfce4-session/xfsm-startup.c @@ -88,7 +88,7 @@ static void xfsm_startup_handle_failed_startup (XfsmProperties *properties static gchar *running_sshagent = NULL; - +static gboolean gpg_agent_only = FALSE; static void @@ -241,6 +241,7 @@ xfsm_startup_init (XfconfChannel *channel) cmd = g_strdup_printf ("%s --sh --daemon --write-env-file '%s'", path, envfile); xfsm_startup_init_sshagent (cmd, agent); g_free (cmd); + gpg_agent_only = TRUE; } else { @@ -282,11 +283,31 @@ xfsm_startup_shutdown (void) const gchar *agentpid; pid_t pid; gboolean is_gpg_agent; + gchar **fields; if (running_sshagent == NULL) return; - agentpid = g_getenv ("SSH_AGENT_PID"); + if (G_UNLIKELY (gpg_agent_only)) + { + const char *gpg_agent_info = g_getenv ("GPG_AGENT_INFO"); + + if (G_UNLIKELY (gpg_agent_info == NULL)) + { + g_warning ("%s was started, but GPG_AGENT_INFO is not set", running_sshagent); + return; + } + + fields = g_strsplit (gpg_agent_info, ":", 3); + g_assert (fields != NULL); + /* second field of GPG_AGENT_INFO is a PID */ + agentpid = fields[1]; + } + else + { + agentpid = g_getenv ("SSH_AGENT_PID"); + } + if (G_UNLIKELY (agentpid == NULL)) { g_warning ("%s was started, but SSH_AGENT_PID is not set, nothing to kill", running_sshagent); @@ -313,9 +334,16 @@ xfsm_startup_shutdown (void) } } - /* make sure the env values are unset */ - g_unsetenv ("SSH_AGENT_PID"); - g_unsetenv ("SSH_AUTH_SOCK"); + if (G_UNLIKELY (gpg_agent_only)) + { + g_strfreev (fields); + } + else + { + /* make sure the env values are unset */ + g_unsetenv ("SSH_AGENT_PID"); + g_unsetenv ("SSH_AUTH_SOCK"); + } g_free (running_sshagent); } -- 1.7.9.6