From 99fccac9a27bb5550d7a74561b9db9ba3909c52e Mon Sep 17 00:00:00 2001 From: Aleksandar Milicevic Date: Thu, 16 May 2019 09:34:17 -0700 Subject: [PATCH] [.NET Core] Add a reference to System.Management and use it for querying child processes (#314) - add System.Management nuget - remove define constants: - DISABLE_FEATURE_MEMORYMAP_SECURITY - DISABLE_FEATURE_SYSTEM_MANAGEMENT AB#1521781 --- Public/Sdk/Public/Managed/Shared/frameworks.dsc | 2 +- Public/Sdk/SelfHost/BuildXL/BuildXLSdk.dsc | 2 -- Public/Src/Engine/Processes/BuildXL.Processes.dsc | 10 ++++++++++ Public/Src/Engine/Processes/ProcessDumper.cs | 13 +++---------- .../UnitTests/Processes/Test.BuildXL.Processes.dsc | 2 +- .../UnitTests/Storage/FileContentTableUnitTests.cs | 3 --- .../UnitTests/Storage/FileUtilitiesTests.cs | 3 --- config.dsc | 1 + 8 files changed, 16 insertions(+), 20 deletions(-) diff --git a/Public/Sdk/Public/Managed/Shared/frameworks.dsc b/Public/Sdk/Public/Managed/Shared/frameworks.dsc index 7fcd188d6..f017dc409 100644 --- a/Public/Sdk/Public/Managed/Shared/frameworks.dsc +++ b/Public/Sdk/Public/Managed/Shared/frameworks.dsc @@ -6,7 +6,7 @@ import * as Deployment from "Sdk.Deployment"; @@public export interface Framework { /** - * The minimum rumtime version supported. + * The minimum runtime version supported. * See: https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/startup/supportedruntime-element */ supportedRuntimeVersion: string, diff --git a/Public/Sdk/SelfHost/BuildXL/BuildXLSdk.dsc b/Public/Sdk/SelfHost/BuildXL/BuildXLSdk.dsc index 1a5e547d3..ea7583c49 100644 --- a/Public/Sdk/SelfHost/BuildXL/BuildXLSdk.dsc +++ b/Public/Sdk/SelfHost/BuildXL/BuildXLSdk.dsc @@ -379,8 +379,6 @@ function processArguments(args: Arguments, targetType: Csc.TargetType) : Argumen ...addIf(isDotNetCoreBuild, "FEATURE_CORECLR", "FEATURE_SAFE_PROCESS_HANDLE", - "DISABLE_FEATURE_MEMORYMAP_SECURITY", - "DISABLE_FEATURE_SYSTEM_MANAGEMENT", "DISABLE_FEATURE_HTTPEXCEPTION", "DISABLE_FEATURE_VSEXTENSION_INSTALL_CHECK", "DISABLE_FEATURE_SECURITY_ATTRIBUTES", diff --git a/Public/Src/Engine/Processes/BuildXL.Processes.dsc b/Public/Src/Engine/Processes/BuildXL.Processes.dsc index 4db51787c..b6a65297d 100644 --- a/Public/Src/Engine/Processes/BuildXL.Processes.dsc +++ b/Public/Src/Engine/Processes/BuildXL.Processes.dsc @@ -2,6 +2,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. import * as Managed from "Sdk.Managed"; +import * as Shared from "Sdk.Managed.Shared"; +import * as SysMng from "System.Management"; + namespace Processes { export declare const qualifier : BuildXLSdk.DefaultQualifierWithNet461; @@ -16,6 +19,13 @@ namespace Processes { BuildXLSdk.NetFx.System.IO.Compression.dll, BuildXLSdk.NetFx.System.Management.dll ), + ...addIf(BuildXLSdk.isDotNetCoreBuild, + SysMng.pkg.override({ + runtime: Context.getCurrentHost().os === "win" ? [ + Shared.Factory.createBinaryFromFiles(SysMng.Contents.all.getFile(r`runtimes/win/lib/netcoreapp2.0/System.Management.dll`)) + ] : [] + }) + ), ...importFrom("BuildXL.Utilities").Native.securityDlls, importFrom("BuildXL.Pips").dll, importFrom("BuildXL.Utilities").dll, diff --git a/Public/Src/Engine/Processes/ProcessDumper.cs b/Public/Src/Engine/Processes/ProcessDumper.cs index 74789f04f..98df5b024 100644 --- a/Public/Src/Engine/Processes/ProcessDumper.cs +++ b/Public/Src/Engine/Processes/ProcessDumper.cs @@ -10,13 +10,11 @@ using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; +using System.Management; using System.Runtime.InteropServices; using BuildXL.Native.IO; using BuildXL.Native.Processes.Windows; using BuildXL.Utilities; -#if !DISABLE_FEATURE_SYSTEM_MANAGEMENT -using System.Management; -#endif namespace BuildXL.Processes { @@ -266,28 +264,24 @@ namespace BuildXL.Processes Process p = maybeProcess.Result; result.Add(new KeyValuePair("1_" + p.ProcessName + ".exe", p.Id)); -#if !DISABLE_FEATURE_SYSTEM_MANAGEMENT foreach (var child in GetChildProcessTreeIds(parentProcessId, maxTreeDepth - 1)) { result.Add(new KeyValuePair("1_" + child.Key, child.Value)); } -#endif // If we don't have access to get the process tree, we'll still at least get the root process. But we need to - // figure out a way to get the process tree under CoreCLR return result; } -#if !DISABLE_FEATURE_SYSTEM_MANAGEMENT internal static List> GetChildProcessTreeIds(int parentProcessId, int maxTreeDepth) { List> result = new List>(); + // If we don't have access to get the process tree, we'll still at least get the root process. try { if (maxTreeDepth > 0) { - var query = new ObjectQuery("select * from win32_process where ParentProcessId=" + parentProcessId); - using (var searcher = new ManagementObjectSearcher(query)) + using (var searcher = new ManagementObjectSearcher("select * from win32_process where ParentProcessId=" + parentProcessId)) { var childProcesses = searcher.Get(); @@ -317,7 +311,6 @@ namespace BuildXL.Processes throw new BuildXLException("Failed to enumerate child processes", ex); } } -#endif private static Possible TryGetProcesById(int processId) { diff --git a/Public/Src/Engine/UnitTests/Processes/Test.BuildXL.Processes.dsc b/Public/Src/Engine/UnitTests/Processes/Test.BuildXL.Processes.dsc index ab111a1ec..4ffdc51f4 100644 --- a/Public/Src/Engine/UnitTests/Processes/Test.BuildXL.Processes.dsc +++ b/Public/Src/Engine/UnitTests/Processes/Test.BuildXL.Processes.dsc @@ -32,7 +32,7 @@ namespace Processes { importFrom("BuildXL.Utilities").Storage.dll, importFrom("BuildXL.Utilities.Instrumentation").Common.dll, importFrom("BuildXL.Utilities.UnitTests").TestProcess.exe, - ...importFrom("BuildXL.Utilities").Native.securityDlls, + ...importFrom("BuildXL.Utilities").Native.securityDlls ], runtimeContent: [ ...addIfLazy(qualifier.targetRuntime === "win-x64", () => [ diff --git a/Public/Src/Utilities/UnitTests/Storage/FileContentTableUnitTests.cs b/Public/Src/Utilities/UnitTests/Storage/FileContentTableUnitTests.cs index 76ed0928a..e53894473 100644 --- a/Public/Src/Utilities/UnitTests/Storage/FileContentTableUnitTests.cs +++ b/Public/Src/Utilities/UnitTests/Storage/FileContentTableUnitTests.cs @@ -380,9 +380,6 @@ namespace Test.BuildXL.Storage mapName: null, capacity: 0, access: MemoryMappedFileAccess.ReadWrite, -#if !DISABLE_FEATURE_MEMORYMAP_SECURITY - memoryMappedFileSecurity: null, -#endif inheritability: HandleInheritability.None, leaveOpen: false)) { diff --git a/Public/Src/Utilities/UnitTests/Storage/FileUtilitiesTests.cs b/Public/Src/Utilities/UnitTests/Storage/FileUtilitiesTests.cs index 02f08cf52..4d80c5b27 100644 --- a/Public/Src/Utilities/UnitTests/Storage/FileUtilitiesTests.cs +++ b/Public/Src/Utilities/UnitTests/Storage/FileUtilitiesTests.cs @@ -1104,9 +1104,6 @@ namespace Test.BuildXL.Storage mapName: null, capacity: 0, access: MemoryMappedFileAccess.ReadWrite, -#if !DISABLE_FEATURE_MEMORYMAP_SECURITY - memoryMappedFileSecurity: null, -#endif inheritability: HandleInheritability.None, leaveOpen: false)) { diff --git a/config.dsc b/config.dsc index 6b9303a85..204bfc665 100644 --- a/config.dsc +++ b/config.dsc @@ -318,6 +318,7 @@ config({ { id: "System.Linq.Expressions", version: "4.3.0" }, { id: "System.Linq.Parallel", version: "4.3.0" }, { id: "System.Linq.Queryable", version: "4.3.0" }, + { id: "System.Management", version: "4.6.0-preview5.19224.8" }, { id: "System.Net.Http", version: "4.3.0" }, { id: "System.Net.NameResolution", version: "4.3.0" }, { id: "System.Net.NetworkInformation", version: "4.3.0" },