diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index a586ad63..dd333958 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -1143,7 +1143,7 @@ namespace SparkleShare { } - public void Quit () + public virtual void Quit () { foreach (SparkleRepoBase repo in Repositories) repo.Dispose (); @@ -1152,14 +1152,6 @@ namespace SparkleShare { Environment.Exit (0); #else System.Windows.Forms.Application.Exit (); - - // Also kill the SSH_AGENT that we started - try { - int pid = Int32.Parse (System.Environment.GetEnvironmentVariable ("SSH_AGENT_PID")); - Process.GetProcessById (pid).Kill (); - } catch (ArgumentException) { - SparkleHelpers.DebugInfo ("SSH", "Could not kill the ssh-agent, due to the process wasn't running"); - } #endif } diff --git a/SparkleShare/Windows/SparkleController.cs b/SparkleShare/Windows/SparkleController.cs index 1a4cdbe2..5d54d868 100644 --- a/SparkleShare/Windows/SparkleController.cs +++ b/SparkleShare/Windows/SparkleController.cs @@ -30,6 +30,7 @@ using CefSharp; namespace SparkleShare { public class SparkleController : SparkleControllerBase { + private int sshAgentPid; public override string PluginsPath { @@ -166,12 +167,18 @@ namespace SparkleShare { process.Start(); } + public override void Quit () + { + KillSshAgent (); + base.Quit (); + } + private void StartSshAgent () { - if (String.IsNullOrEmpty (System.Environment.GetEnvironmentVariable ("SSH_AUTH_SOCK"))) { + if (String.IsNullOrEmpty (System.Environment.GetEnvironmentVariable ("SSH_AUTH_SOCK"))) { - Process process = new Process (); - process.StartInfo.FileName = "ssh-agent"; + Process process = new Process (); + process.StartInfo.FileName = "ssh-agent"; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; @@ -187,6 +194,7 @@ namespace SparkleShare { Match AgentPid = new Regex (@"SSH_AGENT_PID=([^;\n\r]*)").Match (Output); if (AgentPid.Success) { + Int32.TryParse (AgentPid.Groups [1].Value, out sshAgentPid); System.Environment.SetEnvironmentVariable ("SSH_AGENT_PID", AgentPid.Groups[1].Value); SparkleHelpers.DebugInfo ("SSH", "ssh-agent started, PID=" + AgentPid.Groups[1].Value); } @@ -196,7 +204,18 @@ namespace SparkleShare { } } + private void KillSshAgent () + { + if (sshAgentPid != 0) { + // Kill the SSH_AGENT that we started + try { + Process.GetProcessById (sshAgentPid).Kill (); + } catch (ArgumentException) { + SparkleHelpers.DebugInfo ("SSH", "Could not kill the ssh-agent, because the process wasn't running"); + } + } + } - } + } }