Made the ssh-agent close when quitting the application

This commit is contained in:
unknown 2011-10-05 02:02:14 +02:00
parent 951fbf6579
commit 9f8224c0a0

View file

@ -65,6 +65,8 @@ namespace SparkleShare {
System.Environment.SetEnvironmentVariable ("HOME", Environment.ExpandEnvironmentVariables ("%HOMEDRIVE%%HOMEPATH%")); System.Environment.SetEnvironmentVariable ("HOME", Environment.ExpandEnvironmentVariables ("%HOMEDRIVE%%HOMEPATH%"));
StartSshAgent(); StartSshAgent();
// Start the agent but also make it stop when application is qutting
Application.ApplicationExit += new EventHandler(this.StopSshAgent);
base.Initialize (); base.Initialize ();
} }
@ -160,15 +162,17 @@ namespace SparkleShare {
{ {
if (String.IsNullOrEmpty (System.Environment.GetEnvironmentVariable ("SSH_AUTH_SOCK"))) { if (String.IsNullOrEmpty (System.Environment.GetEnvironmentVariable ("SSH_AUTH_SOCK"))) {
Process process = new Process (); ProcessStartInfo processInfo = new ProcessStartInfo ();
process.StartInfo.FileName = "ssh-agent"; Process process;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.Start (); processInfo.FileName = "ssh-agent";
processInfo.UseShellExecute = false;
processInfo.RedirectStandardOutput = true;
process = Process.Start (processInfo);
string Output = process.StandardOutput.ReadToEnd (); string Output = process.StandardOutput.ReadToEnd ();
process.WaitForExit(); process.WaitForExit();
process.Close ();
Match AuthSock = new Regex (@"SSH_AUTH_SOCK=([^;\n\r]*)").Match (Output); Match AuthSock = new Regex (@"SSH_AUTH_SOCK=([^;\n\r]*)").Match (Output);
if (AuthSock.Success) { if (AuthSock.Success) {
@ -186,6 +190,12 @@ namespace SparkleShare {
} }
} }
private void StopSshAgent (object sender, EventArgs e)
{
int pid = Int32.Parse(System.Environment.GetEnvironmentVariable("SSH_AGENT_PID"));
Process.GetProcessById(pid).Kill();
}
} }