Skip to content

Commit

Permalink
Fix a bug in existing process detection
Browse files Browse the repository at this point in the history
  • Loading branch information
RaeesBhatti committed Oct 23, 2016
1 parent 24efe7f commit 26d3bb9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void Main(string[] args)
{
existingProcess = Process.GetProcessById(Convert.ToInt32(AgentPID));
} catch (Exception) {}
if (String.IsNullOrEmpty(AgentPID) || (existingProcess != null && existingProcess.Id < 1))
if (String.IsNullOrEmpty(AgentPID) || existingProcess == null || existingProcess.Id < 1)
{
AgentPID = Environment.GetEnvironmentVariable(SSH_AGENT_PID, EnvironmentVariableTarget.User);
}
Expand Down Expand Up @@ -201,7 +201,7 @@ static void KillSSHAgent()
existingProcess = Process.GetProcessById(Convert.ToInt32(AgentPID));
}
catch (Exception) { }
if (String.IsNullOrEmpty(AgentPID) || (existingProcess != null && existingProcess.Id < 1))
if (String.IsNullOrEmpty(AgentPID) || existingProcess == null || existingProcess.Id < 1)
{
Console.Error.WriteLine("Either the environment is currently not configured for ssh-agent or it " +
"has already been killed.");
Expand Down Expand Up @@ -284,7 +284,7 @@ static bool TestSSHAgent()
}
catch (Exception) { }

return !(String.IsNullOrEmpty(AgentPID) || (existingProcess != null && existingProcess.Id < 1));
return !(String.IsNullOrEmpty(AgentPID) || existingProcess == null || existingProcess.Id < 1);
}

static string FindProgram(string name)
Expand Down

0 comments on commit 26d3bb9

Please sign in to comment.