mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-07-16 18:43:43 +01:00
Log message cleanup
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -231,7 +231,7 @@ namespace Tgstation.Server.Host.Watchdog
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogWarning("Unable to delete exception dump file at {0}! Exception: {1}", updateDirectory, e);
|
||||
logger.LogWarning(e, "Unable to delete exception dump file at {0}!", updateDirectory);
|
||||
}
|
||||
|
||||
#pragma warning disable CA2201 // Do not raise reserved exception types
|
||||
@@ -277,12 +277,12 @@ namespace Tgstation.Server.Host.Watchdog
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogWarning("Error deleting old server at {0}! Exception: {1}", tempPath, e);
|
||||
logger.LogWarning(e, "Error deleting old server at {0}!", tempPath);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError("Error moving updated server directory, attempting revert! Exception: {0}", e);
|
||||
logger.LogError(e, "Error moving updated server directory, attempting revert!");
|
||||
Directory.Delete(defaultAssemblyPath, true);
|
||||
Directory.Move(tempPath, defaultAssemblyPath);
|
||||
logger.LogInformation("Revert successful!");
|
||||
@@ -290,22 +290,22 @@ namespace Tgstation.Server.Host.Watchdog
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogWarning("Failed to move out active host assembly! Exception: {0}", e);
|
||||
logger.LogWarning(e, "Failed to move out active host assembly!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
catch (OperationCanceledException ex)
|
||||
{
|
||||
logger.LogDebug("Exiting due to cancellation...");
|
||||
logger.LogDebug(ex, "Exiting due to cancellation...");
|
||||
if (!Directory.Exists(updateDirectory))
|
||||
File.Delete(updateDirectory);
|
||||
else
|
||||
Directory.Delete(updateDirectory, true);
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogCritical("Watchdog error! Exception: {0}", e);
|
||||
logger.LogCritical(ex, "Host watchdog error!");
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
@@ -69,7 +69,7 @@ namespace Tgstation.Server.Host.Components.Byond
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogWarning("Error deleting BYOND cache! Exception: {0}", e);
|
||||
Logger.LogWarning(e, "Error deleting BYOND cache!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -373,15 +373,15 @@ namespace Tgstation.Server.Host.Components.Chat
|
||||
if (result != null)
|
||||
await SendMessage(result, new List<ulong> { message.User.Channel.RealId }, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
catch (OperationCanceledException ex)
|
||||
{
|
||||
logger.LogTrace("Command processing canceled!");
|
||||
logger.LogTrace(ex, "Command processing canceled!");
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// error bc custom commands should reply about why it failed
|
||||
logger.LogError("Error processing chat command: {0}", e);
|
||||
logger.LogError(e, "Error processing chat command");
|
||||
await SendMessage(
|
||||
"TGS: Internal error processing command! Check server logs!",
|
||||
new List<ulong> { message.User.Channel.RealId },
|
||||
@@ -440,13 +440,13 @@ namespace Tgstation.Server.Host.Components.Chat
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
catch (OperationCanceledException ex)
|
||||
{
|
||||
logger.LogTrace("Message processing loop cancelled!");
|
||||
logger.LogTrace(ex, "Message processing loop cancelled!");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError("Message loop crashed! Exception: {0}", e);
|
||||
logger.LogError(e, "Message loop crashed!");
|
||||
}
|
||||
|
||||
logger.LogTrace("Leaving message processing loop");
|
||||
@@ -694,9 +694,9 @@ namespace Tgstation.Server.Host.Components.Chat
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogWarning(
|
||||
"Error sending deploy message to provider {0}! Exception: {1}",
|
||||
channelMapping.ProviderId,
|
||||
ex);
|
||||
ex,
|
||||
"Error sending deploy message to provider {0}!",
|
||||
channelMapping.ProviderId);
|
||||
}
|
||||
}))
|
||||
.ConfigureAwait(false);
|
||||
|
||||
@@ -194,7 +194,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogWarning("Error disconnecting from discord: {0}", e);
|
||||
Logger.LogWarning(e, "Error disconnecting from discord!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogWarning("Error sending discord message: {0}", e);
|
||||
Logger.LogWarning(e, "Error sending discord message!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,7 +391,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogWarning("Updating deploy embed {0} failed, attempting new post! Exception: {1}", message.Id, ex);
|
||||
Logger.LogWarning(ex, "Updating deploy embed {0} failed, attempting new post!", message.Id);
|
||||
try
|
||||
{
|
||||
await channel.SendMessageAsync(
|
||||
@@ -402,7 +402,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
}
|
||||
catch (Exception ex2)
|
||||
{
|
||||
Logger.LogWarning("Posting completion deploy embed failed! Exception: {0}", ex2);
|
||||
Logger.LogWarning(ex2, "Posting completion deploy embed failed!");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -296,7 +296,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogWarning("IRC Listen Error: {0}", ex);
|
||||
Logger.LogWarning(ex, "IRC Main Listen Exception!");
|
||||
}
|
||||
|
||||
Logger.LogTrace("Exiting listening task...");
|
||||
@@ -334,7 +334,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogWarning("IRC Listen Error: {0}", ex);
|
||||
Logger.LogWarning(ex, "IRC Non-Blocking Listen Exception!");
|
||||
}
|
||||
},
|
||||
cancellationToken,
|
||||
@@ -426,7 +426,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogWarning("Error quitting IRC: {0}", e);
|
||||
Logger.LogWarning(e, "Error quitting IRC!");
|
||||
}
|
||||
},
|
||||
cancellationToken,
|
||||
@@ -441,7 +441,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogWarning("Error disconnecting from IRC! Exception: {0}", e);
|
||||
Logger.LogWarning(e, "Error disconnecting from IRC!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -468,7 +468,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogWarning("Error disconnecting IRC: {0}", e);
|
||||
Logger.LogWarning(e, "Error disconnecting IRC!");
|
||||
}
|
||||
},
|
||||
cancellationToken,
|
||||
@@ -571,7 +571,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogWarning("Unable to send to channel: {0}", e);
|
||||
Logger.LogWarning(e, "Unable to send to channel {0}!", channelName);
|
||||
}
|
||||
}, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);
|
||||
|
||||
|
||||
@@ -358,7 +358,7 @@ namespace Tgstation.Server.Host.Components.Deployment
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogWarning("Error deleting directory {0}! Exception: {1}", x, e);
|
||||
logger.LogWarning(e, "Error deleting directory {0}!", x);
|
||||
}
|
||||
}).ToList();
|
||||
if (deleting > 0)
|
||||
|
||||
@@ -365,7 +365,7 @@ namespace Tgstation.Server.Host.Components.Deployment
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogWarning("Error cleaning up compile directory {0}! Exception: {1}", ioManager.ResolvePath(jobPath), e);
|
||||
logger.LogWarning(e, "Error cleaning up compile directory {0}!", ioManager.ResolvePath(jobPath));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -825,7 +825,7 @@ namespace Tgstation.Server.Host.Components.Deployment
|
||||
}
|
||||
catch (ApiException e)
|
||||
{
|
||||
logger.LogWarning("Error posting GitHub comment! Exception: {0}", e);
|
||||
logger.LogWarning(e, "Error posting GitHub comment!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -382,7 +382,7 @@ namespace Tgstation.Server.Host.Components
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogWarning("Error in auto update loop! Exception: {0}", e);
|
||||
logger.LogWarning(e, "Error in auto update loop!");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,9 +232,9 @@ namespace Tgstation.Server.Host.Components
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(
|
||||
"Error moving instance {0}! Exception: {2}",
|
||||
instance.Id,
|
||||
ex);
|
||||
ex,
|
||||
"Error moving instance {0}!",
|
||||
instance.Id);
|
||||
try
|
||||
{
|
||||
logger.LogDebug("Reverting instance {0}'s path to {1} in the DB...", instance.Id, oldPath);
|
||||
@@ -254,8 +254,8 @@ namespace Tgstation.Server.Host.Components
|
||||
catch (Exception innerEx)
|
||||
{
|
||||
logger.LogCritical(
|
||||
"Error reverting database after failing to move instance {0}! Attempting to detach. Exception: {1}",
|
||||
ex);
|
||||
innerEx,
|
||||
"Error reverting database after failing to move instance {0}! Attempting to detach...");
|
||||
|
||||
try
|
||||
{
|
||||
@@ -269,8 +269,8 @@ namespace Tgstation.Server.Host.Components
|
||||
catch (Exception tripleEx)
|
||||
{
|
||||
logger.LogCritical(
|
||||
"Okay, what gamma radiation are you under? Failed to write instance attach file! Exception: {0}",
|
||||
tripleEx);
|
||||
tripleEx,
|
||||
"Okay, what gamma radiation are you under? Failed to write instance attach file!");
|
||||
|
||||
throw new AggregateException(tripleEx, innerEx, ex);
|
||||
}
|
||||
@@ -366,12 +366,15 @@ namespace Tgstation.Server.Host.Components
|
||||
logger.LogError("Unable to commit onlined instance {0} into service, offlining!", metadata.Id);
|
||||
try
|
||||
{
|
||||
// DCT: Must always run
|
||||
await instance.StopAsync(default).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception innerEx)
|
||||
{
|
||||
throw new AggregateException(innerEx, ex);
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
catch
|
||||
@@ -419,7 +422,7 @@ namespace Tgstation.Server.Host.Components
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError("Failed to online instance {0}! Exception: {0}", ex);
|
||||
logger.LogError(ex, "Failed to online instance {0}!");
|
||||
}
|
||||
})
|
||||
.ToList();
|
||||
@@ -436,7 +439,7 @@ namespace Tgstation.Server.Host.Components
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogCritical("Instance manager startup error! Exception: {0}", e);
|
||||
logger.LogCritical(e, "Instance manager startup error!");
|
||||
try
|
||||
{
|
||||
await serverControl.Die(e).ConfigureAwait(false);
|
||||
@@ -444,7 +447,7 @@ namespace Tgstation.Server.Host.Components
|
||||
}
|
||||
catch (Exception e2)
|
||||
{
|
||||
logger.LogCritical("Failed to kill server! Exception: {0}", e2);
|
||||
logger.LogCritical(e2, "Failed to kill server!");
|
||||
}
|
||||
|
||||
throw;
|
||||
@@ -467,7 +470,7 @@ namespace Tgstation.Server.Host.Components
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError("Instance manager stop exception: {0}", ex);
|
||||
logger.LogError(ex, "Instance manager stop exception!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using LibGit2Sharp;
|
||||
using LibGit2Sharp;
|
||||
using LibGit2Sharp.Handlers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
@@ -30,17 +30,7 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
public LibGit2Sharp.IRepository CreateInMemory()
|
||||
{
|
||||
logger.LogTrace("Creating in-memory libgit2 repository...");
|
||||
var repo = new LibGit2Sharp.Repository();
|
||||
try
|
||||
{
|
||||
logger.LogTrace("Successfully created in-memory libgit2 repository.");
|
||||
return repo;
|
||||
}
|
||||
catch
|
||||
{
|
||||
repo.Dispose();
|
||||
throw;
|
||||
}
|
||||
return new LibGit2Sharp.Repository();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -70,7 +60,7 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
}
|
||||
catch (UserCancelledException ex)
|
||||
{
|
||||
logger.LogTrace("Suppressing clone cancellation exception: {0}", ex);
|
||||
logger.LogTrace(ex, "Suppressing clone cancellation exception");
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
}
|
||||
}, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using LibGit2Sharp;
|
||||
using LibGit2Sharp;
|
||||
using LibGit2Sharp.Handlers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
@@ -475,7 +475,7 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
}
|
||||
catch(LibGit2SharpException e)
|
||||
{
|
||||
logger.LogWarning("Unable to push to temporary branch! Exception: {0}", e);
|
||||
logger.LogWarning(e, "Unable to push to temporary branch!");
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -683,7 +683,7 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
}
|
||||
catch (LibGit2SharpException e)
|
||||
{
|
||||
logger.LogWarning("Unable to make synchronization push! Exception: {0}", e);
|
||||
logger.LogWarning(e, "Unable to make synchronization push!");
|
||||
return false;
|
||||
}
|
||||
}, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using LibGit2Sharp;
|
||||
using LibGit2Sharp;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Threading;
|
||||
@@ -154,7 +154,7 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogDebug("Error deleting partially cloned repository! Exception: {0}", e);
|
||||
logger.LogDebug(e, "Error deleting partially cloned repository!");
|
||||
}
|
||||
|
||||
throw;
|
||||
@@ -209,8 +209,7 @@ namespace Tgstation.Server.Host.Components.Repository
|
||||
}
|
||||
catch (RepositoryNotFoundException e)
|
||||
{
|
||||
logger.LogDebug("Repository not found!");
|
||||
logger.LogTrace("Exception: {0}", e);
|
||||
logger.LogTrace(e, "Repository not found!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -566,16 +566,17 @@ namespace Tgstation.Server.Host.Components.Session
|
||||
|
||||
logger.LogTrace("Interop response: {0}", topicReturn);
|
||||
}
|
||||
catch
|
||||
catch(Exception ex)
|
||||
{
|
||||
logger.LogWarning("Invalid interop response: {0}", topicReturn);
|
||||
logger.LogWarning(ex, "Invalid interop response: {0}", topicReturn);
|
||||
}
|
||||
|
||||
return new CombinedTopicResponse(topicResponse, interopResponse);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
catch (OperationCanceledException ex)
|
||||
{
|
||||
logger.LogTrace(
|
||||
ex,
|
||||
"Topic request {0}!",
|
||||
cancellationToken.IsCancellationRequested
|
||||
? "aborted"
|
||||
@@ -584,7 +585,7 @@ namespace Tgstation.Server.Host.Components.Session
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogWarning("Send command exception:{0}{1}", Environment.NewLine, e);
|
||||
logger.LogWarning(e, "Send command exception!");
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -289,7 +289,7 @@ namespace Tgstation.Server.Host.Components.Session
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogWarning("Failed to delete DreamDaemon log file {0}: {1}", logFilePath, ex);
|
||||
logger.LogWarning(ex, "Failed to delete DreamDaemon log file {0}!", logFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -306,7 +306,7 @@ namespace Tgstation.Server.Host.Components.Session
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogWarning("Error reading DreamDaemon output: {0}", ex);
|
||||
logger.LogWarning(ex, "Error reading DreamDaemon output!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Linq;
|
||||
@@ -136,7 +136,7 @@ namespace Tgstation.Server.Host.Components.Session
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogWarning("Failed to kill process! Exception: {0}", ex);
|
||||
logger.LogWarning(ex, "Failed to kill process!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -211,7 +211,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
logger.LogDebug("IOException while writing {0}: {1}", path, e);
|
||||
logger.LogDebug(e, "IOException while writing {0}!", path);
|
||||
result = null;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -384,7 +384,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// don't try to send chat tasks or warning logs if were suppressing exceptions or cancelled
|
||||
Logger.LogWarning(e, "Failed to start watchdog!");
|
||||
var originalChatTask = announceTask;
|
||||
async Task ChainChatTaskWithErrorMessage()
|
||||
{
|
||||
@@ -394,7 +394,6 @@ namespace Tgstation.Server.Host.Components.Watchdog
|
||||
}
|
||||
|
||||
announceTask = ChainChatTaskWithErrorMessage();
|
||||
Logger.LogWarning("Failed to start watchdog: {0}", e.ToString());
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
@@ -404,9 +403,9 @@ namespace Tgstation.Server.Host.Components.Watchdog
|
||||
{
|
||||
await announceTask.ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
catch (OperationCanceledException ex)
|
||||
{
|
||||
Logger.LogTrace("Announcement task canceled!");
|
||||
Logger.LogTrace(ex, "Announcement task canceled!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,7 +553,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
|
||||
await chatTask.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
Logger.LogWarning("Failed to automatically restart the watchdog! Attempt: {0}, Exception: {1}", retryAttempts, launchException);
|
||||
Logger.LogWarning(launchException, "Failed to automatically restart the watchdog! Attempt: {0}", retryAttempts);
|
||||
Status = WatchdogStatus.DelayedRestart;
|
||||
|
||||
var retryDelay = Math.Min(
|
||||
@@ -698,9 +697,9 @@ namespace Tgstation.Server.Host.Components.Watchdog
|
||||
{
|
||||
// really, this should NEVER happen
|
||||
Logger.LogError(
|
||||
"Monitor crashed! Iteration: {0}, Exception: {1}",
|
||||
iteration,
|
||||
e);
|
||||
e,
|
||||
"Monitor crashed! Iteration: {0}",
|
||||
iteration);
|
||||
|
||||
var nextActionMessage = nextAction != MonitorAction.Exit
|
||||
? "Recovering"
|
||||
@@ -917,8 +916,8 @@ namespace Tgstation.Server.Host.Components.Watchdog
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogCritical(
|
||||
"Failed to persist session reattach information! To repair this, DreamDaemon will need to be manully stopped and then relaunched with TGS. Exception: {0}",
|
||||
ex);
|
||||
ex,
|
||||
"Failed to persist session reattach information! To repair this, DreamDaemon will need to be manully stopped and then relaunched with TGS.");
|
||||
}
|
||||
|
||||
releasedReattachInformation = null;
|
||||
|
||||
@@ -181,14 +181,14 @@ namespace Tgstation.Server.Host.Components.Watchdog
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogWarning("Exception while suspending server: {0}", ex);
|
||||
Logger.LogWarning(ex, "Exception while suspending server!");
|
||||
}
|
||||
|
||||
await windowsProvider.MakeActive(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError("Exception while swapping: {0}", ex);
|
||||
Logger.LogError(ex, "Exception while swapping");
|
||||
IDmbProvider providerToDispose = windowsProvider ?? compileJobProvider;
|
||||
providerToDispose.Dispose();
|
||||
throw;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
@@ -30,7 +30,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
[Route(Routes.Administration)]
|
||||
public sealed class AdministrationController : ApiController
|
||||
{
|
||||
const string OctokitException = "Bad GitHub API response, check configuration! Exception: {0}";
|
||||
const string OctokitException = "Bad GitHub API response, check configuration!";
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="IGitHubClientFactory"/> for the <see cref="AdministrationController"/>
|
||||
@@ -116,7 +116,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
ObjectResult RateLimit(RateLimitExceededException exception)
|
||||
{
|
||||
Logger.LogWarning("Exceeded GitHub rate limit! Exception {0}", exception);
|
||||
Logger.LogWarning(exception, "Exceeded GitHub rate limit!");
|
||||
var secondsString = Math.Ceiling((exception.Reset - DateTimeOffset.Now).TotalSeconds).ToString(CultureInfo.InvariantCulture);
|
||||
Response.Headers.Add("Retry-After", new StringValues(secondsString));
|
||||
return StatusCode(HttpStatusCode.TooManyRequests, new ErrorMessage(ErrorCode.GitHubApiRateLimit));
|
||||
@@ -148,7 +148,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
}
|
||||
catch (ApiException e)
|
||||
{
|
||||
Logger.LogWarning(OctokitException, e);
|
||||
Logger.LogWarning(e, OctokitException);
|
||||
return StatusCode(HttpStatusCode.FailedDependency);
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
}
|
||||
catch (NotFoundException e)
|
||||
{
|
||||
Logger.LogWarning("Not found exception while retrieving upstream repository info: {0}", e);
|
||||
Logger.LogWarning(e, "Not found exception while retrieving upstream repository info!");
|
||||
}
|
||||
|
||||
return Json(new Administration
|
||||
@@ -242,7 +242,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
}
|
||||
catch (ApiException e)
|
||||
{
|
||||
Logger.LogWarning(OctokitException, e);
|
||||
Logger.LogWarning(e, OctokitException);
|
||||
return StatusCode(HttpStatusCode.FailedDependency, new ErrorMessage(ErrorCode.GitHubApiError)
|
||||
{
|
||||
AdditionalData = e.Message
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
@@ -62,8 +62,12 @@ namespace Tgstation.Server.Host.Controllers
|
||||
public async Task<IActionResult> Process([FromQuery]string data, CancellationToken cancellationToken)
|
||||
{
|
||||
// Nothing to see here
|
||||
if (!IPAddress.IsLoopback(Request.HttpContext.Connection.RemoteIpAddress))
|
||||
var remoteIP = Request.HttpContext.Connection.RemoteIpAddress;
|
||||
if (!IPAddress.IsLoopback(remoteIP))
|
||||
{
|
||||
logger.LogTrace("Ignoring remote bridge request from {0}", remoteIP);
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
using (LogContext.PushProperty("Bridge", Interlocked.Increment(ref requestsProcessed)))
|
||||
{
|
||||
@@ -72,9 +76,9 @@ namespace Tgstation.Server.Host.Controllers
|
||||
{
|
||||
request = JsonConvert.DeserializeObject<BridgeParameters>(data, DMApiConstants.SerializerSettings);
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogWarning("Error deserializing bridge request: {0}", data);
|
||||
logger.LogWarning(ex, "Error deserializing bridge request: {0}", data);
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
|
||||
@@ -497,7 +497,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
catch (Exception e)
|
||||
{
|
||||
if(!(e is OperationCanceledException))
|
||||
Logger.LogError("Error changing instance online state! Exception: {0}", e);
|
||||
Logger.LogError(e, "Error changing instance online state!");
|
||||
originalModel.Online = originalOnline;
|
||||
originalModel.DreamDaemonSettings.AutoStart = oldAutoStart;
|
||||
if (originalModelPath != null)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
@@ -817,7 +817,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
}
|
||||
|
||||
if (exception != null)
|
||||
Logger.LogWarning("Error retrieving pull request metadata: {0}", exception);
|
||||
Logger.LogWarning(exception, "Error retrieving pull request metadata!");
|
||||
|
||||
// we want to take the earliest truth possible to prevent RCEs, if this fails AddTestMerge will set it
|
||||
if (I.PullRequestRevision == null && pr != null)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -400,7 +400,7 @@ namespace Tgstation.Server.Host.Database
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogCritical("Failed to migrate! Exception: {0}", e);
|
||||
logger.LogCritical(e, "Failed to migrate!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
@@ -165,10 +165,8 @@ namespace Tgstation.Server.Host.Database
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (tgsUser != null)
|
||||
{
|
||||
logger.LogError(
|
||||
"A user named TGS (Canonically) exists but isn't marked as the admin's creator. This may be because it was created manually. This user is going to be adapted to use as the starter of system jobs.");
|
||||
}
|
||||
|
||||
tgsUser = SeedSystemUser(databaseContext, tgsUser);
|
||||
admin.CreatedBy = tgsUser;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -42,11 +42,11 @@ namespace Tgstation.Server.Host.Extensions
|
||||
{
|
||||
if (e.InnerException is OperationCanceledException)
|
||||
{
|
||||
logger.LogTrace("Rethrowing DbUpdateException as OperationCanceledException: {0}", e);
|
||||
logger.LogTrace(e, "Rethrowing DbUpdateException as OperationCanceledException");
|
||||
throw e.InnerException;
|
||||
}
|
||||
|
||||
logger.LogDebug("Database conflict: {0}", e.Message);
|
||||
logger.LogDebug(e, "Database conflict!");
|
||||
await new ConflictObjectResult(new ErrorMessage(ErrorCode.DatabaseIntegrityConflict)
|
||||
{
|
||||
AdditionalData = String.Format(CultureInfo.InvariantCulture, (e.InnerException ?? e).Message)
|
||||
@@ -73,9 +73,9 @@ namespace Tgstation.Server.Host.Extensions
|
||||
{
|
||||
await next().ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
catch (OperationCanceledException ex)
|
||||
{
|
||||
logger.LogDebug("Request cancelled!");
|
||||
logger.LogDebug(ex, "Request cancelled!");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -97,7 +97,7 @@ namespace Tgstation.Server.Host.Extensions
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError("Failed request: {0}", e);
|
||||
logger.LogError(e, "Failed request!");
|
||||
await new ObjectResult(
|
||||
new ErrorMessage(ErrorCode.InternalServerError)
|
||||
{
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace Tgstation.Server.Host.Jobs
|
||||
using (LogContext.PushProperty("Job", job.Id))
|
||||
try
|
||||
{
|
||||
void LogException() => logger.LogDebug("Job {0} exited with error! Exception: {1}", job.Id, job.ExceptionDetails);
|
||||
void LogException(Exception ex) => logger.LogDebug(ex, "Job {0} exited with error!", job.Id);
|
||||
try
|
||||
{
|
||||
var oldJob = job;
|
||||
@@ -122,21 +122,21 @@ namespace Tgstation.Server.Host.Jobs
|
||||
|
||||
logger.LogDebug("Job {0} completed!", job.Id);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
catch (OperationCanceledException ex)
|
||||
{
|
||||
logger.LogDebug("Job {0} cancelled!", job.Id);
|
||||
logger.LogDebug(ex, "Job {0} cancelled!", job.Id);
|
||||
job.Cancelled = true;
|
||||
}
|
||||
catch (JobException e)
|
||||
{
|
||||
job.ErrorCode = e.ErrorCode;
|
||||
job.ExceptionDetails = String.IsNullOrWhiteSpace(e.Message) ? e.InnerException?.Message : e.Message;
|
||||
LogException();
|
||||
LogException(e);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
job.ExceptionDetails = e.ToString();
|
||||
LogException();
|
||||
LogException(e);
|
||||
}
|
||||
|
||||
await databaseContextFactory.UseContext(async databaseContext =>
|
||||
@@ -220,10 +220,8 @@ namespace Tgstation.Server.Host.Jobs
|
||||
});
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
logger.LogTrace("Starting job manager...");
|
||||
await databaseContextFactory.UseContext(async databaseContext =>
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
=> databaseContextFactory.UseContext(async databaseContext =>
|
||||
{
|
||||
// mark all jobs as cancelled
|
||||
var badJobs = await databaseContext
|
||||
@@ -246,9 +244,7 @@ namespace Tgstation.Server.Host.Jobs
|
||||
|
||||
await databaseContext.Save(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}).ConfigureAwait(false);
|
||||
logger.LogDebug("Job manager started!");
|
||||
}
|
||||
});
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task StopAsync(CancellationToken cancellationToken)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
using System;
|
||||
using System.DirectoryServices.AccountManagement;
|
||||
@@ -70,7 +70,7 @@ namespace Tgstation.Server.Host.Security
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogWarning("Error loading user for context type {0}! Exception: {1}", contextType, e);
|
||||
logger.LogWarning(e, "Error loading user for context type {0}!", contextType);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -110,8 +110,10 @@ namespace Tgstation.Server.Host.Security
|
||||
|
||||
logger.LogTrace("Authenticated username {0} using system identity!", originalUsername);
|
||||
|
||||
using (var handle = new SafeAccessTokenHandle(token)) // checked internally, windows identity always duplicates the handle when constructed with a userToken
|
||||
return (ISystemIdentity)new WindowsSystemIdentity(new WindowsIdentity(handle.DangerousGetHandle())); // https://github.com/dotnet/corefx/blob/6ed61acebe3214fcf79b4274f2bb9b55c0604a4d/src/System.Security.Principal.Windows/src/System/Security/Principal/WindowsIdentity.cs#L271
|
||||
// checked internally, windows identity always duplicates the handle when constructed
|
||||
using var handle = new SafeAccessTokenHandle(token);
|
||||
return (ISystemIdentity)new WindowsSystemIdentity(
|
||||
new WindowsIdentity(handle.DangerousGetHandle())); // https://github.com/dotnet/corefx/blob/6ed61acebe3214fcf79b4274f2bb9b55c0604a4d/src/System.Security.Principal.Windows/src/System/Security/Principal/WindowsIdentity.cs#L271
|
||||
}, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ namespace Tgstation.Server.Host
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError("Error updating server! Exception: {0}", e);
|
||||
logger.LogError(e, "Error updating server!");
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -304,13 +304,15 @@ namespace Tgstation.Server.Host
|
||||
{
|
||||
await eventsTask.ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
catch (OperationCanceledException ex)
|
||||
{
|
||||
logger.LogError("Restart timeout hit! Existing DreamDaemon processes will be lost and must be killed manually before being restarted with TGS!");
|
||||
logger.LogError(
|
||||
ex,
|
||||
"Restart timeout hit! Existing DreamDaemon processes will be lost and must be killed manually before being restarted with TGS!");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError("Restart handlers error! Exception: {0}", e);
|
||||
logger.LogError(e, "Restart handlers error!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,35 +44,17 @@ namespace Tgstation.Server.Host.System
|
||||
/// <inheritdoc />
|
||||
public void ResumeProcess(global::System.Diagnostics.Process process)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = Syscall.kill(process.Id, Signum.SIGCONT);
|
||||
if (result != 0)
|
||||
throw new UnixIOException(result);
|
||||
logger.LogTrace("Resumed PID {0}", process.Id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e, "Failed to resume PID {0}!", process.Id);
|
||||
throw;
|
||||
}
|
||||
var result = Syscall.kill(process.Id, Signum.SIGCONT);
|
||||
if (result != 0)
|
||||
throw new UnixIOException(result);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void SuspendProcess(global::System.Diagnostics.Process process)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = Syscall.kill(process.Id, Signum.SIGSTOP);
|
||||
if (result != 0)
|
||||
throw new UnixIOException(result);
|
||||
logger.LogTrace("Resumed PID {0}", process.Id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e, "Failed to suspend PID {0}!", process.Id);
|
||||
throw;
|
||||
}
|
||||
var result = Syscall.kill(process.Id, Signum.SIGSTOP);
|
||||
if (result != 0)
|
||||
throw new UnixIOException(result);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -105,7 +105,11 @@ namespace Tgstation.Server.Host.System
|
||||
{
|
||||
await Task.WhenAny(lifetimeTask, emergencyLifetimeTcs.Task).ConfigureAwait(false);
|
||||
if (lifetimeTask.IsCompleted)
|
||||
return await lifetimeTask.ConfigureAwait(false);
|
||||
{
|
||||
var exitCode = await lifetimeTask.ConfigureAwait(false);
|
||||
logger.LogTrace("PID {0} exited with code {1}", Id, exitCode);
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
logger.LogTrace("Using exit code -1 for hung PID {0}.", Id);
|
||||
return -1;
|
||||
@@ -156,7 +160,7 @@ namespace Tgstation.Server.Host.System
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogDebug("Process termination exception: {0}", e);
|
||||
logger.LogDebug(e, "Process termination exception!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,17 +174,41 @@ namespace Tgstation.Server.Host.System
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogWarning("Unable to raise process priority for PID {0}! Exception: {1}", Id, e);
|
||||
logger.LogWarning(e, "Unable to raise process priority for PID {0}!", Id);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Suspend() => processFeatures.SuspendProcess(handle);
|
||||
public void Suspend()
|
||||
{
|
||||
try
|
||||
{
|
||||
processFeatures.SuspendProcess(handle);
|
||||
logger.LogTrace("Suspended PID {0}", Id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e, "Failed to suspend PID {0}!", Id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Resume() => processFeatures.ResumeProcess(handle);
|
||||
public void Resume()
|
||||
{
|
||||
try
|
||||
{
|
||||
processFeatures.ResumeProcess(handle);
|
||||
logger.LogTrace("Resumed PID {0}", Id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e, "Failed to resume PID {0}!", Id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <inheritdoc />
|
||||
public async Task<string> GetExecutingUsername(CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await processFeatures.GetExecutingUsername(handle, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
@@ -77,9 +77,9 @@ namespace Tgstation.Server.Host.System
|
||||
{
|
||||
handle = global::System.Diagnostics.Process.GetProcessById(id);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogDebug("Unable to get process {0}! Exception: {1}", id, e);
|
||||
logger.LogDebug(e, "Unable to get process {0}!", id);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ namespace Tgstation.Server.Host.System
|
||||
handle = proc;
|
||||
else
|
||||
{
|
||||
logger.LogTrace("Disposing extra found PID: {0}", proc.Id);
|
||||
logger.LogTrace("Disposing extra found PID: {0}...", proc.Id);
|
||||
proc.Dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using BetterWin32Errors;
|
||||
using BetterWin32Errors;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
@@ -134,7 +134,7 @@ namespace Tgstation.Server.Host.System
|
||||
|
||||
if (NativeMethods.GetWindowText(I, stringBuilder, MaxLength) == 0)
|
||||
{
|
||||
logger.LogWarning("Error calling GetWindowText! Exception: {0}", new Win32Exception());
|
||||
logger.LogWarning(new Win32Exception(), "Error calling GetWindowText!");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -158,9 +158,9 @@ namespace Tgstation.Server.Host.System
|
||||
logger.LogDebug("Unable to find \"Yes\" button for \"Network Accessibility\" window in owned process {0}!", processId);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
catch (OperationCanceledException ex)
|
||||
{
|
||||
logger.LogTrace("Cancelled!");
|
||||
logger.LogTrace(ex, "Cancelled!");
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using BetterWin32Errors;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using BetterWin32Errors;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
@@ -13,46 +12,27 @@ namespace Tgstation.Server.Host.System
|
||||
/// <inheritdoc />
|
||||
sealed class WindowsProcessFeatures : IProcessFeatures
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="ILogger{TCategoryName}"/> for the <see cref="WindowsProcessFeatures"/>.
|
||||
/// </summary>
|
||||
readonly ILogger<WindowsProcessFeatures> logger;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="WindowsProcessFeatures"/> <see langword="class"/>.
|
||||
/// </summary>
|
||||
/// <param name="logger">The value of <see cref="logger"/>.</param>
|
||||
public WindowsProcessFeatures(ILogger<WindowsProcessFeatures> logger)
|
||||
{
|
||||
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ResumeProcess(global::System.Diagnostics.Process process)
|
||||
{
|
||||
if (process == null)
|
||||
throw new ArgumentNullException(nameof(process));
|
||||
|
||||
try
|
||||
foreach (ProcessThread thread in process.Threads)
|
||||
{
|
||||
foreach (ProcessThread thread in process.Threads)
|
||||
{
|
||||
var pOpenThread = NativeMethods.OpenThread(NativeMethods.ThreadAccess.SuspendResume, false, (uint)thread.Id);
|
||||
if (pOpenThread == IntPtr.Zero)
|
||||
continue;
|
||||
var pOpenThread = NativeMethods.OpenThread(NativeMethods.ThreadAccess.SuspendResume, false, (uint)thread.Id);
|
||||
if (pOpenThread == IntPtr.Zero)
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
if (NativeMethods.ResumeThread(pOpenThread) == UInt32.MaxValue)
|
||||
throw new Win32Exception();
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
NativeMethods.CloseHandle(pOpenThread);
|
||||
}
|
||||
|
||||
logger.LogTrace("Resumed PID {0}", process.Id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e, "Failed to resume PID {0}!", process.Id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,26 +42,20 @@ namespace Tgstation.Server.Host.System
|
||||
if (process == null)
|
||||
throw new ArgumentNullException(nameof(process));
|
||||
|
||||
try
|
||||
foreach (ProcessThread thread in process.Threads)
|
||||
{
|
||||
foreach (ProcessThread thread in process.Threads)
|
||||
var pOpenThread = NativeMethods.OpenThread(NativeMethods.ThreadAccess.SuspendResume, false, (uint)thread.Id);
|
||||
if (pOpenThread == IntPtr.Zero)
|
||||
continue;
|
||||
try
|
||||
{
|
||||
var pOpenThread = NativeMethods.OpenThread(NativeMethods.ThreadAccess.SuspendResume, false, (uint)thread.Id);
|
||||
if (pOpenThread == IntPtr.Zero)
|
||||
continue;
|
||||
|
||||
if (NativeMethods.SuspendThread(pOpenThread) == UInt32.MaxValue)
|
||||
throw new Win32Exception();
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
NativeMethods.CloseHandle(pOpenThread);
|
||||
}
|
||||
|
||||
logger.LogTrace("Suspended PID {0}", process.Id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e, "Failed to suspend PID {0}!", process.Id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Castle.Core.Logging;
|
||||
using Castle.Core.Logging;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
@@ -20,7 +20,7 @@ namespace Tgstation.Server.Host.System.Tests
|
||||
public void Init()
|
||||
{
|
||||
features = new PlatformIdentifier().IsWindows
|
||||
? (IProcessFeatures)new WindowsProcessFeatures(Mock.Of<ILogger<WindowsProcessFeatures>>())
|
||||
? (IProcessFeatures)new WindowsProcessFeatures()
|
||||
: new PosixProcessFeatures(new Lazy<IProcessExecutor>(() => null), new DefaultIOManager(), Mock.Of<ILogger<PosixProcessFeatures>>());
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ namespace Tgstation.Server.Tests.Instance
|
||||
IProcessExecutor executor = null;
|
||||
executor = new ProcessExecutor(
|
||||
new PlatformIdentifier().IsWindows
|
||||
? (IProcessFeatures)new WindowsProcessFeatures(Mock.Of<ILogger<WindowsProcessFeatures>>())
|
||||
? (IProcessFeatures)new WindowsProcessFeatures()
|
||||
: new PosixProcessFeatures(new Lazy<IProcessExecutor>(() => executor), Mock.Of<IIOManager>(), Mock.Of<ILogger<PosixProcessFeatures>>()),
|
||||
Mock.Of<ILogger<ProcessExecutor>>(),
|
||||
LoggerFactory.Create(x => { }));
|
||||
|
||||
Reference in New Issue
Block a user