Skip to content

Commit

Permalink
Platforms: remove unused active process check
Browse files Browse the repository at this point in the history
The last caller of the IsProcessActive() methods in the
ScalarPlatform classes was removed in commit
cedeeaa in PR microsoft#29.

Therefore we can remove this method as well as the native
Windows system call wrappers and enums which were used only
by the WindowPlatform implementation of this method.
  • Loading branch information
chrisd8088 committed Oct 11, 2020
1 parent be0b5db commit 726e277
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 84 deletions.
28 changes: 0 additions & 28 deletions Scalar.Common/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,6 @@ public enum FileAccess : uint
GENERIC_READ = 2147483648
}

[Flags]
public enum ProcessAccessFlags : uint
{
All = 0x001F0FFF,
Terminate = 0x00000001,
CreateThread = 0x00000002,
VirtualMemoryOperation = 0x00000008,
VirtualMemoryRead = 0x00000010,
VirtualMemoryWrite = 0x00000020,
DuplicateHandle = 0x00000040,
CreateProcess = 0x000000080,
SetQuota = 0x00000100,
SetInformation = 0x00000200,
QueryInformation = 0x00000400,
QueryLimitedInformation = 0x00001000,
Synchronize = 0x00100000
}

[Flags]
public enum MoveFileFlags : uint
{
Expand Down Expand Up @@ -190,16 +172,6 @@ public static void ThrowLastWin32Exception(string message)
throw new Win32Exception(Marshal.GetLastWin32Error(), message);
}

[DllImport("kernel32.dll", SetLastError = true)]
public static extern SafeFileHandle OpenProcess(
ProcessAccessFlags processAccess,
bool bInheritHandle,
int processId);

[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetExitCodeProcess(SafeFileHandle hProcess, out uint lpExitCode);

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern SafeFileHandle CreateFile(
[In] string lpFileName,
Expand Down
14 changes: 0 additions & 14 deletions Scalar.Common/Platforms/POSIX/POSIXPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,6 @@ public override bool TryVerifyAuthenticodeSignature(string path, out string subj
throw new NotImplementedException();
}

public override bool IsProcessActive(int processId)
{
try
{
Process process = Process.GetProcessById(processId);
}
catch (ArgumentException)
{
return false;
}

return true;
}

public override void IsServiceInstalledAndRunning(string name, out bool installed, out bool running)
{
throw new NotImplementedException();
Expand Down
34 changes: 0 additions & 34 deletions Scalar.Common/Platforms/Windows/WindowsPlatform.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Win32;
using Microsoft.Win32.SafeHandles;
using Scalar.Common;
using Scalar.Common.FileSystem;
using Scalar.Common.Git;
Expand All @@ -25,8 +24,6 @@ public class WindowsPlatform : ScalarPlatform
private const string BuildLabRegistryValue = "BuildLab";
private const string BuildLabExRegistryValue = "BuildLabEx";

private const int StillActive = 259; /* from Win32 STILL_ACTIVE */

public WindowsPlatform() : base(underConstruction: new UnderConstructionFlags())
{
}
Expand Down Expand Up @@ -203,37 +200,6 @@ public override bool IsElevated()
}
}

public override bool IsProcessActive(int processId)
{
using (SafeFileHandle process = NativeMethods.OpenProcess(NativeMethods.ProcessAccessFlags.QueryLimitedInformation, false, processId))
{
if (!process.IsInvalid)
{
uint exitCode;
if (NativeMethods.GetExitCodeProcess(process, out exitCode) && exitCode == StillActive)
{
return true;
}
}
else
{
// The process.IsInvalid may be true when the process doesn't have access to call
// OpenProcess for the specified processId. Fallback to slow way of finding process.
try
{
Process.GetProcessById(processId);
return true;
}
catch (ArgumentException)
{
return false;
}
}

return false;
}
}

public override void IsServiceInstalledAndRunning(string name, out bool installed, out bool running)
{
ServiceController service = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName.Equals(name, StringComparison.Ordinal));
Expand Down
1 change: 0 additions & 1 deletion Scalar.Common/ScalarPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public static void Register(ScalarPlatform platform)
/// </exception>
public abstract void PrepareProcessToRunInBackground();

public abstract bool IsProcessActive(int processId);
public abstract void IsServiceInstalledAndRunning(string name, out bool installed, out bool running);
public abstract string GetScalarServiceNamedPipeName(string serviceName);
public abstract NamedPipeServerStream CreatePipeByName(string pipeName);
Expand Down
7 changes: 0 additions & 7 deletions Scalar.UnitTests/Mock/Common/MockPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public class MockPlatform : ScalarPlatform

public override ScalarPlatformConstants Constants { get; } = new MockPlatformConstants();

public HashSet<int> ActiveProcesses { get; } = new HashSet<int>();

public override void ConfigureVisualStudio(string gitBinPath, ITracer tracer)
{
throw new NotSupportedException();
Expand Down Expand Up @@ -110,11 +108,6 @@ public override bool IsElevated()
throw new NotSupportedException();
}

public override bool IsProcessActive(int processId)
{
return this.ActiveProcesses.Contains(processId);
}

public override void IsServiceInstalledAndRunning(string name, out bool installed, out bool running)
{
throw new NotSupportedException();
Expand Down

0 comments on commit 726e277

Please sign in to comment.