Added better handling of the ssh-agent process

This commit is contained in:
Konstantinos Vaggelakos 2011-10-10 01:32:57 +02:00
parent 8d46eb4dda
commit 940c5ae159
2 changed files with 41 additions and 24 deletions

View file

@ -1130,8 +1130,15 @@ namespace SparkleShare {
System.Windows.Forms.Application.Exit ();
// Also kill the SSH_AGENT
try {
// Check if we created the process, if so bring it down. Else leave it running
if (!System.Environment.GetEnvironmentVariable ("SSH_AUTH_SOCK").Equals("unknown")) {
int pid = Int32.Parse (System.Environment.GetEnvironmentVariable ("SSH_AGENT_PID"));
Process.GetProcessById (pid).Kill ();
}
} catch (Exception e) {
// Handle exception if needed
}
#endif
}

View file

@ -158,7 +158,18 @@ namespace SparkleShare {
private void StartSshAgent ()
{
if (String.IsNullOrEmpty (System.Environment.GetEnvironmentVariable ("SSH_AUTH_SOCK"))) {
// Check to see if the process is running
Process [] ProcessList = Process.GetProcesses ();
foreach (Process p in ProcessList) {
if (p.ToString ().Contains ("ssh-agent")) {
System.Environment.SetEnvironmentVariable ("SSH_AGENT_PID", p.Id.ToString ());
System.Environment.SetEnvironmentVariable ("SSH_AUTH_SOCK", "unknown");
return;
}
}
// If it wasn't running we start it
if (String.IsNullOrEmpty (System.Environment.GetEnvironmentVariable ("SSH_AGENT_PID"))) {
ProcessStartInfo processInfo = new ProcessStartInfo ();
Process process;
@ -181,8 +192,7 @@ namespace SparkleShare {
if (AgentPid.Success) {
System.Environment.SetEnvironmentVariable ("SSH_AGENT_PID", AgentPid.Groups [1].Value);
SparkleHelpers.DebugInfo ("SSH", "ssh-agent started, PID=" + AgentPid.Groups [1].Value);
}
else {
} else {
SparkleHelpers.DebugInfo ("SSH", "ssh-agent started, PID=unknown");
}
}