diff --git a/src/Tgstation.Server.Host/System/IProcess.cs b/src/Tgstation.Server.Host/System/IProcess.cs index 8df102b2b2..f9f35e5c66 100644 --- a/src/Tgstation.Server.Host/System/IProcess.cs +++ b/src/Tgstation.Server.Host/System/IProcess.cs @@ -29,7 +29,7 @@ namespace Tgstation.Server.Host.System /// the result of this function must be ed before is called. /// May call internally if the process has exited. /// - ValueTask GetCombinedOutput(CancellationToken cancellationToken); + ValueTask GetCombinedOutput(CancellationToken cancellationToken); /// /// Asycnhronously terminates the process. diff --git a/src/Tgstation.Server.Host/System/IProcessExecutor.cs b/src/Tgstation.Server.Host/System/IProcessExecutor.cs index fe51ce451b..aae807eec2 100644 --- a/src/Tgstation.Server.Host/System/IProcessExecutor.cs +++ b/src/Tgstation.Server.Host/System/IProcessExecutor.cs @@ -18,7 +18,7 @@ IProcess LaunchProcess( string fileName, string workingDirectory, - string? arguments = null, + string arguments, string? fileRedirect = null, bool readStandardHandles = false, bool noShellExecute = false); @@ -34,13 +34,13 @@ /// /// The . /// The represented by on success, on failure. - IProcess GetProcess(int id); + IProcess? GetProcess(int id); /// /// Get a with a given . /// /// The name of the process executable without the extension. /// The represented by on success, on failure. - IProcess GetProcessByName(string name); + IProcess? GetProcessByName(string name); } } diff --git a/src/Tgstation.Server.Host/System/PosixProcessFeatures.cs b/src/Tgstation.Server.Host/System/PosixProcessFeatures.cs index b45c845fa4..8077577aaf 100644 --- a/src/Tgstation.Server.Host/System/PosixProcessFeatures.cs +++ b/src/Tgstation.Server.Host/System/PosixProcessFeatures.cs @@ -86,7 +86,7 @@ namespace Tgstation.Server.Host.System throw new JobException(ErrorCode.GameServerOffline, ex); } - string output; + string? output; int exitCode; await using (var gcoreProc = lazyLoadedProcessExecutor.Value.LaunchProcess( GCorePath, diff --git a/src/Tgstation.Server.Host/System/Process.cs b/src/Tgstation.Server.Host/System/Process.cs index 003f3b12e4..4b91aef6ac 100644 --- a/src/Tgstation.Server.Host/System/Process.cs +++ b/src/Tgstation.Server.Host/System/Process.cs @@ -57,7 +57,7 @@ namespace Tgstation.Server.Host.System /// /// The resulting in the process' standard output/error text. /// - readonly Task readTask; + readonly Task? readTask; /// /// If the was disposed. @@ -78,8 +78,8 @@ namespace Tgstation.Server.Host.System IProcessFeatures processFeatures, IAsyncDelayer asyncDelayer, global::System.Diagnostics.Process handle, - CancellationTokenSource readerCts, - Task readTask, + CancellationTokenSource? readerCts, + Task? readTask, ILogger logger, bool preExisting) { @@ -144,7 +144,7 @@ namespace Tgstation.Server.Host.System } /// - public async ValueTask GetCombinedOutput(CancellationToken cancellationToken) + public async ValueTask GetCombinedOutput(CancellationToken cancellationToken) { if (readTask == null) throw new InvalidOperationException("Output/Error stream reading was not enabled!"); diff --git a/src/Tgstation.Server.Host/System/ProcessExecutor.cs b/src/Tgstation.Server.Host/System/ProcessExecutor.cs index 94e4af31b7..fd411153f0 100644 --- a/src/Tgstation.Server.Host/System/ProcessExecutor.cs +++ b/src/Tgstation.Server.Host/System/ProcessExecutor.cs @@ -9,8 +9,6 @@ using Microsoft.Extensions.Logging; using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Utils; -#nullable disable - namespace Tgstation.Server.Host.System { /// @@ -86,7 +84,7 @@ namespace Tgstation.Server.Host.System } /// - public IProcess GetProcess(int id) + public IProcess? GetProcess(int id) { logger.LogDebug("Attaching to process {pid}...", id); global::System.Diagnostics.Process handle; @@ -116,7 +114,7 @@ namespace Tgstation.Server.Host.System string fileName, string workingDirectory, string arguments, - string fileRedirect, + string? fileRedirect, bool readStandardHandles, bool noShellExecute) { @@ -143,11 +141,11 @@ namespace Tgstation.Server.Host.System handle.StartInfo.UseShellExecute = !noShellExecute; - Task readTask = null; - CancellationTokenSource disposeCts = null; + Task? readTask = null; + CancellationTokenSource? disposeCts = null; try { - TaskCompletionSource processStartTcs = null; + TaskCompletionSource? processStartTcs = null; if (readStandardHandles) { processStartTcs = new TaskCompletionSource(); @@ -203,11 +201,11 @@ namespace Tgstation.Server.Host.System } /// - public IProcess GetProcessByName(string name) + public IProcess? GetProcessByName(string name) { logger.LogTrace("GetProcessByName: {processName}...", name ?? throw new ArgumentNullException(nameof(name))); var procs = global::System.Diagnostics.Process.GetProcessesByName(name); - global::System.Diagnostics.Process handle = null; + global::System.Diagnostics.Process? handle = null; foreach (var proc in procs) if (handle == null) handle = proc; @@ -231,7 +229,7 @@ namespace Tgstation.Server.Host.System /// The optional path to redirect the streams to. /// The that triggers when the is disposed. /// A resulting in the program's output/error text if is , otherwise. - async Task ConsumeReaders(global::System.Diagnostics.Process handle, Task startTask, string fileRedirect, CancellationToken disposeToken) + async Task ConsumeReaders(global::System.Diagnostics.Process handle, Task startTask, string? fileRedirect, CancellationToken disposeToken) { await startTask; @@ -241,9 +239,9 @@ namespace Tgstation.Server.Host.System // once we obtain these handles we're responsible for them using var stdOutHandle = handle.StandardOutput; using var stdErrHandle = handle.StandardError; - Task outputReadTask = null, errorReadTask = null; + Task? outputReadTask = null, errorReadTask = null; bool outputOpen = true, errorOpen = true; - async Task GetNextLine() + async Task GetNextLine() { if (outputOpen && outputReadTask == null) outputReadTask = stdOutHandle.ReadLineAsync(disposeToken).AsTask(); @@ -251,7 +249,7 @@ namespace Tgstation.Server.Host.System if (errorOpen && errorReadTask == null) errorReadTask = stdErrHandle.ReadLineAsync(disposeToken).AsTask(); - var completedTask = await Task.WhenAny(outputReadTask ?? errorReadTask, errorReadTask ?? outputReadTask); + var completedTask = await Task.WhenAny(outputReadTask ?? errorReadTask!, errorReadTask ?? outputReadTask!); var line = await completedTask; if (completedTask == outputReadTask) { @@ -275,7 +273,7 @@ namespace Tgstation.Server.Host.System await using var fileStream = fileRedirect != null ? ioManager.CreateAsyncSequentialWriteStream(fileRedirect) : null; await using var writer = fileStream != null ? new StreamWriter(fileStream) : null; - string text; + string? text; var stringBuilder = fileStream == null ? new StringBuilder() : null; try { @@ -283,11 +281,11 @@ namespace Tgstation.Server.Host.System { if (fileStream != null) { - await writer.WriteLineAsync(text.AsMemory(), disposeToken); + await writer!.WriteLineAsync(text.AsMemory(), disposeToken); await writer.FlushAsync(disposeToken); } else - stringBuilder.AppendLine(text); + stringBuilder!.AppendLine(text); } logger.LogTrace("Finished read for PID {pid}", pid); @@ -296,7 +294,7 @@ namespace Tgstation.Server.Host.System { logger.LogWarning(ex, "PID {pid} stream reading interrupted!", pid); if (fileStream != null) - await writer.WriteLineAsync("-- Process detached, log truncated. This is likely due a to TGS restart --"); + await writer!.WriteLineAsync("-- Process detached, log truncated. This is likely due a to TGS restart --"); } return stringBuilder?.ToString();