@@ -165,8 +165,6 @@ internal static int Start(
165165 // improve startup performance.
166166 }
167167
168- uint exitCode = ExitCodeSuccess ;
169-
170168 Thread . CurrentThread . Name = "ConsoleHost main thread" ;
171169
172170 try
@@ -192,7 +190,7 @@ internal static int Start(
192190 // or start up the engine and retrieve the information via $psversiontable.GitCommitId
193191 // but this returns the semantic version and avoids executing a script
194192 s_theConsoleHost . UI . WriteLine ( $ "PowerShell { PSVersionInfo . GitCommitId } ") ;
195- return 0 ;
193+ return ExitCodeSuccess ;
196194 }
197195
198196 // Servermode parameter validation check.
@@ -223,6 +221,14 @@ internal static int Start(
223221 return ExitCodeBadCommandLineParameter ;
224222 }
225223
224+ if ( serverModeCount is 1 && CommandLineParameterParser . IsFileOnlyEntryEnabled )
225+ {
226+ // User facing error message should already be written by the parser,
227+ // so just trace and exit.
228+ s_tracer . TraceError ( "Server mode cannot be specified when FileOnlyEntry policy is in place." ) ;
229+ return ExitCodeBadCommandLineParameter ;
230+ }
231+
226232#if ! UNIX
227233 TaskbarJumpList . CreateRunAsAdministratorJumpList ( ) ;
228234#endif
@@ -237,9 +243,10 @@ internal static int Start(
237243 configurationName : null ,
238244 configurationFile : s_cpp . ConfigurationFile ,
239245 combineErrOutStream : false ) ;
240- exitCode = 0 ;
246+ return ExitCodeSuccess ;
241247 }
242- else if ( s_cpp . SSHServerMode )
248+
249+ if ( s_cpp . SSHServerMode )
243250 {
244251 ApplicationInsightsTelemetry . SendPSCoreStartupTelemetry ( "SSHServer" , s_cpp . ParametersUsedAsDouble ) ;
245252 ProfileOptimization . StartProfile ( "StartupProfileData-SSHServerMode" ) ;
@@ -249,18 +256,20 @@ internal static int Start(
249256 configurationName : null ,
250257 configurationFile : s_cpp . ConfigurationFile ,
251258 combineErrOutStream : true ) ;
252- exitCode = 0 ;
259+ return ExitCodeSuccess ;
253260 }
254- else if ( s_cpp . NamedPipeServerMode )
261+
262+ if ( s_cpp . NamedPipeServerMode )
255263 {
256264 ApplicationInsightsTelemetry . SendPSCoreStartupTelemetry ( "NamedPipe" , s_cpp . ParametersUsedAsDouble ) ;
257265 ProfileOptimization . StartProfile ( "StartupProfileData-NamedPipeServerMode" ) ;
258266 RemoteSessionNamedPipeServer . RunServerMode (
259267 configurationName : s_cpp . ConfigurationName ) ;
260- exitCode = 0 ;
268+ return ExitCodeSuccess ;
261269 }
262270#if ! UNIX
263- else if ( s_cpp . V2SocketServerMode )
271+
272+ if ( s_cpp . V2SocketServerMode )
264273 {
265274 if ( s_cpp . Token == null )
266275 {
@@ -284,50 +293,49 @@ internal static int Start(
284293 token : s_cpp . Token ,
285294 tokenCreationTime : s_cpp . UTCTimestamp . Value ) ;
286295
287- exitCode = 0 ;
296+ return ExitCodeSuccess ;
288297 }
289298#endif
290- else if ( s_cpp . SocketServerMode )
299+
300+ if ( s_cpp . SocketServerMode )
291301 {
292302 ApplicationInsightsTelemetry . SendPSCoreStartupTelemetry ( "SocketServerMode" , s_cpp . ParametersUsedAsDouble ) ;
293303 ProfileOptimization . StartProfile ( "StartupProfileData-SocketServerMode" ) ;
294304 HyperVSocketMediator . Run (
295305 initialCommand : s_cpp . InitialCommand ,
296306 configurationName : s_cpp . ConfigurationName ) ;
297- exitCode = 0 ;
307+ return ExitCodeSuccess ;
298308 }
299- else
309+
310+ // Run PowerShell in normal console mode.
311+ if ( hostException != null )
300312 {
301- // Run PowerShell in normal console mode.
302- if ( hostException != null )
303- {
304- // Unable to create console host.
305- throw hostException ;
306- }
313+ // Unable to create console host.
314+ throw hostException ;
315+ }
307316
308- if ( LoadPSReadline ( ) )
309- {
310- ProfileOptimization . StartProfile ( "StartupProfileData-Interactive" ) ;
317+ if ( LoadPSReadline ( ) )
318+ {
319+ ProfileOptimization . StartProfile ( "StartupProfileData-Interactive" ) ;
311320
312- if ( UpdatesNotification . CanNotifyUpdates )
313- {
314- // Start a task in the background to check for the update release.
315- _ = UpdatesNotification . CheckForUpdates ( ) ;
316- }
317- }
318- else
321+ if ( UpdatesNotification . CanNotifyUpdates )
319322 {
320- ProfileOptimization . StartProfile ( "StartupProfileData-NonInteractive" ) ;
323+ // Start a task in the background to check for the update release.
324+ _ = UpdatesNotification . CheckForUpdates ( ) ;
321325 }
326+ }
327+ else
328+ {
329+ ProfileOptimization . StartProfile ( "StartupProfileData-NonInteractive" ) ;
330+ }
322331
323- s_theConsoleHost . BindBreakHandler ( ) ;
324- IsStdOutputRedirected = Console . IsOutputRedirected ;
332+ s_theConsoleHost . BindBreakHandler ( ) ;
333+ IsStdOutputRedirected = Console . IsOutputRedirected ;
325334
326- // Send startup telemetry for ConsoleHost startup
327- ApplicationInsightsTelemetry . SendPSCoreStartupTelemetry ( "Normal" , s_cpp . ParametersUsedAsDouble ) ;
335+ // Send startup telemetry for ConsoleHost startup
336+ ApplicationInsightsTelemetry . SendPSCoreStartupTelemetry ( "Normal" , s_cpp . ParametersUsedAsDouble ) ;
328337
329- exitCode = s_theConsoleHost . Run ( s_cpp , false ) ;
330- }
338+ return unchecked ( ( int ) s_theConsoleHost . Run ( s_cpp , false ) ) ;
331339 }
332340 finally
333341 {
@@ -349,11 +357,6 @@ internal static int Start(
349357 }
350358#pragma warning restore IDE0031
351359 }
352-
353- unchecked
354- {
355- return ( int ) exitCode ;
356- }
357360 }
358361
359362 internal static void ParseCommandLine ( string [ ] args )
0 commit comments