From: mikelle-rogers <45022607+mikelle-rogers@users.noreply.github.com> Date: Wed, 25 Jan 2023 04:28:42 +0000 (-0800) Subject: Dev/mirogers/kudu console (#3083) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055542~44^2^2~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1671b50a5c12315a9373b641355c0f6673e48f33;p=platform%2Fcore%2Fdotnet%2Fdiagnostics.git Dev/mirogers/kudu console (#3083) * added some logging to debug in Kudu * refined the placement of the try catch statement * Create NamedPipeEnumerationUnauthorizedException and catch it * fixing suggestions from code review * stick with current exception type and specific message --- diff --git a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs index c4cb1eab0..22a89e45c 100644 --- a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs +++ b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs @@ -305,9 +305,9 @@ namespace Microsoft.Diagnostics.NETCore.Client /// public static IEnumerable GetPublishedProcesses() { - static IEnumerable GetAllPublishedProcesses() + static IEnumerable GetAllPublishedProcesses(string[] files) { - foreach (var port in Directory.GetFiles(PidIpcEndpoint.IpcRootPath)) + foreach (var port in files) { var fileName = new FileInfo(port).Name; var match = Regex.Match(fileName, PidIpcEndpoint.DiagnosticsPortPattern); @@ -319,8 +319,22 @@ namespace Microsoft.Diagnostics.NETCore.Client yield return processId; } } - - return GetAllPublishedProcesses().Distinct(); + try + { + string[] files = Directory.GetFiles(PidIpcEndpoint.IpcRootPath); + return GetAllPublishedProcesses(files).Distinct(); + } + catch ( UnauthorizedAccessException ex) + { + if (PidIpcEndpoint.IpcRootPath.StartsWith(@"\\.\pipe")) + { + throw new DiagnosticsClientException($"Enumerating {PidIpcEndpoint.IpcRootPath} is not authorized", ex); + } + else + { + throw; + } + } } internal ProcessInfo GetProcessInfo() diff --git a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClientExceptions.cs b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClientExceptions.cs index fa9aec630..efcea1c43 100644 --- a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClientExceptions.cs +++ b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClientExceptions.cs @@ -8,6 +8,7 @@ namespace Microsoft.Diagnostics.NETCore.Client public class DiagnosticsClientException : Exception { public DiagnosticsClientException(string msg) : base(msg) {} + public DiagnosticsClientException(string msg, Exception exception) : base(msg, exception) {} } // When a certian command is not supported by either the library or the target process' runtime diff --git a/src/Tools/Common/Commands/ProcessStatus.cs b/src/Tools/Common/Commands/ProcessStatus.cs index 9a83d7c71..72ea2f45d 100644 --- a/src/Tools/Common/Commands/ProcessStatus.cs +++ b/src/Tools/Common/Commands/ProcessStatus.cs @@ -142,7 +142,6 @@ namespace Microsoft.Internal.Common.Commands String cmdLineArgs = GetArgs(process); cmdLineArgs = cmdLineArgs == process.MainModule?.FileName ? string.Empty : cmdLineArgs; string fileName = process.MainModule?.FileName ?? string.Empty; - var commandInfo = new ProcessDetails() { ProcessId = process.Id, @@ -174,7 +173,7 @@ namespace Microsoft.Internal.Common.Commands FormatTableRows(printInfo, sb); console.Out.WriteLine(sb.ToString()); } - catch (InvalidOperationException ex) + catch (Exception ex) { console.Out.WriteLine(ex.ToString()); }