Hard throw with bad noShellExecute calls

This commit is contained in:
Jordan Brown
2020-05-14 13:30:28 -04:00
parent e96296448b
commit fe33421c6f
5 changed files with 30 additions and 9 deletions
@@ -119,7 +119,10 @@ namespace Tgstation.Server.Host.Components.Byond
IProcess directXInstaller;
try
{
directXInstaller = processExecutor.LaunchProcess(IOManager.ConcatPath(rbdx, "DXSETUP.exe"), rbdx, "/silent", noShellExecute: true);
directXInstaller = processExecutor.LaunchProcess(
IOManager.ConcatPath(rbdx, "DXSETUP.exe"),
rbdx, "/silent",
noShellExecute: true);
}
catch (Exception e)
{
@@ -244,6 +244,7 @@ namespace Tgstation.Server.Host.Components.Deployment
ADirectoryName)),
$"-clean {job.DmeName}.{DmeExtension}",
true,
true,
true);
int exitCode;
using (cancellationToken.Register(() => dm.Terminate()))
@@ -213,7 +213,11 @@ namespace Tgstation.Server.Host.Components.Session
var noShellExecute = !platformIdentifier.IsWindows;
// launch dd
var process = processExecutor.LaunchProcess(byondLock.DreamDaemonPath, basePath, arguments, noShellExecute: noShellExecute);
var process = processExecutor.LaunchProcess(
byondLock.DreamDaemonPath,
basePath,
arguments,
noShellExecute: noShellExecute);
try
{
networkPromptReaper.RegisterProcess(process);
@@ -456,7 +456,11 @@ namespace Tgstation.Server.Host.Components.StaticFiles
var resolvedScriptsDir = ioManager.ResolvePath(EventScriptsSubdirectory);
foreach (var I in files.Select(x => ioManager.GetFileName(x)).Where(x => x.StartsWith(scriptName, StringComparison.Ordinal)))
using (var script = processExecutor.LaunchProcess(ioManager.ConcatPath(resolvedScriptsDir, I), resolvedScriptsDir, String.Join(' ', parameters), noShellExecute: true))
using (var script = processExecutor.LaunchProcess(
ioManager.ConcatPath(resolvedScriptsDir, I),
resolvedScriptsDir,
String.Join(' ', parameters),
noShellExecute: true))
using (cancellationToken.Register(() => script.Terminate()))
{
var exitCode = await script.Lifetime.ConfigureAwait(false);
@@ -102,14 +102,23 @@ namespace Tgstation.Server.Host.System
}
/// <inheritdoc />
public IProcess LaunchProcess(string fileName, string workingDirectory, string arguments, bool readOutput, bool readError, bool noShellExecute)
public IProcess LaunchProcess(
string fileName,
string workingDirectory,
string arguments,
bool readOutput,
bool readError,
bool noShellExecute)
{
if (!noShellExecute && (readOutput || readError))
{
logger.LogWarning("CODE ERROR: Requesting output/error reading requires noShellExecute to be true! Setting it now...");
if (fileName == null)
throw new ArgumentNullException(nameof(fileName));
if (workingDirectory == null)
throw new ArgumentNullException(nameof(workingDirectory));
if (arguments == null)
throw new ArgumentNullException(nameof(arguments));
noShellExecute = true;
}
if (!noShellExecute && (readOutput || readError))
throw new InvalidOperationException("Requesting output/error reading requires noShellExecute to be true!");
logger.LogDebug("{3}aunching process in {0}: {1} {2}", workingDirectory, fileName, arguments, noShellExecute ? "L" : "Shell l");
var handle = new global::System.Diagnostics.Process();