Added better handling of the ssh-agent process
This commit is contained in:
parent
8d46eb4dda
commit
940c5ae159
|
@ -1130,8 +1130,15 @@ namespace SparkleShare {
|
||||||
System.Windows.Forms.Application.Exit ();
|
System.Windows.Forms.Application.Exit ();
|
||||||
|
|
||||||
// Also kill the SSH_AGENT
|
// Also kill the SSH_AGENT
|
||||||
int pid = Int32.Parse (System.Environment.GetEnvironmentVariable ("SSH_AGENT_PID"));
|
try {
|
||||||
Process.GetProcessById (pid).Kill ();
|
// 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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,34 +158,44 @@ namespace SparkleShare {
|
||||||
|
|
||||||
private void StartSshAgent ()
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ProcessStartInfo processInfo = new ProcessStartInfo ();
|
// If it wasn't running we start it
|
||||||
|
if (String.IsNullOrEmpty (System.Environment.GetEnvironmentVariable ("SSH_AGENT_PID"))) {
|
||||||
|
|
||||||
|
ProcessStartInfo processInfo = new ProcessStartInfo ();
|
||||||
Process process;
|
Process process;
|
||||||
|
|
||||||
processInfo.FileName = "ssh-agent";
|
processInfo.FileName = "ssh-agent";
|
||||||
processInfo.UseShellExecute = false;
|
processInfo.UseShellExecute = false;
|
||||||
processInfo.RedirectStandardOutput = true;
|
processInfo.RedirectStandardOutput = true;
|
||||||
|
|
||||||
process = Process.Start (processInfo);
|
process = Process.Start (processInfo);
|
||||||
string Output = process.StandardOutput.ReadToEnd ();
|
string Output = process.StandardOutput.ReadToEnd ();
|
||||||
process.WaitForExit();
|
process.WaitForExit ();
|
||||||
process.Close ();
|
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) {
|
||||||
System.Environment.SetEnvironmentVariable ("SSH_AUTH_SOCK", AuthSock.Groups[1].Value);
|
System.Environment.SetEnvironmentVariable ("SSH_AUTH_SOCK", AuthSock.Groups [1].Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Match AgentPid = new Regex (@"SSH_AGENT_PID=([^;\n\r]*)").Match (Output);
|
Match AgentPid = new Regex (@"SSH_AGENT_PID=([^;\n\r]*)").Match (Output);
|
||||||
if (AgentPid.Success) {
|
if (AgentPid.Success) {
|
||||||
System.Environment.SetEnvironmentVariable ("SSH_AGENT_PID", AgentPid.Groups[1].Value);
|
System.Environment.SetEnvironmentVariable ("SSH_AGENT_PID", AgentPid.Groups [1].Value);
|
||||||
SparkleHelpers.DebugInfo ("SSH", "ssh-agent started, 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");
|
||||||
SparkleHelpers.DebugInfo ("SSH", "ssh-agent started, PID=unknown");
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue