-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #991 from tgstation/FourTwentyTwo [TGSDeploy][APID…
…eploy][NugetDeploy] v4.2.2
- Loading branch information
Showing
22 changed files
with
370 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Tgstation.Server.Host.System | ||
{ | ||
/// <summary> | ||
/// Abstraction for suspending and resuming processes. | ||
/// </summary> | ||
interface IProcessFeatures | ||
{ | ||
/// <summary> | ||
/// Get the name of the user executing a given <paramref name="process"/>. | ||
/// </summary> | ||
/// <param name="process">The <see cref="global::System.Diagnostics.Process"/>.</param> | ||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param> | ||
/// <returns>The name of the user executing <paramref name="process"/>.</returns> | ||
Task<string> GetExecutingUsername(global::System.Diagnostics.Process process, CancellationToken cancellationToken); | ||
|
||
/// <summary> | ||
/// Suspend a given <see cref="Process"/>. | ||
/// </summary> | ||
/// <param name="process">The <see cref="Process"/> to suspend.</param> | ||
void SuspendProcess(global::System.Diagnostics.Process process); | ||
|
||
/// <summary> | ||
/// Resume a given suspended <see cref="Process"/>. | ||
/// </summary> | ||
/// <param name="process">The <see cref="Process"/> to susperesumend.</param> | ||
void ResumeProcess(global::System.Diagnostics.Process process); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Mono.Unix; | ||
using Mono.Unix.Native; | ||
using System; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Tgstation.Server.Host.IO; | ||
|
||
namespace Tgstation.Server.Host.System | ||
{ | ||
/// <inheritdoc /> | ||
sealed class PosixProcessFeatures : IProcessFeatures | ||
{ | ||
/// <summary> | ||
/// The <see cref="IIOManager"/> for the <see cref="PosixProcessFeatures"/>. | ||
/// </summary> | ||
readonly IIOManager ioManager; | ||
|
||
/// <summary> | ||
/// The <see cref="ILogger{TCategoryName}"/> for the <see cref="PosixProcessFeatures"/>. | ||
/// </summary> | ||
readonly ILogger<PosixProcessFeatures> logger; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="PosixProcessFeatures"/> <see langword="class"/>. | ||
/// </summary> | ||
/// <param name="ioManager">The value of <see cref="ioManager"/>.</param> | ||
/// <param name="logger">The value of <see cref="logger"/>.</param> | ||
public PosixProcessFeatures(IIOManager ioManager, ILogger<PosixProcessFeatures> logger) | ||
{ | ||
this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager)); | ||
this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
} | ||
|
||
/// <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; | ||
} | ||
} | ||
|
||
/// <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; | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<string> GetExecutingUsername(global::System.Diagnostics.Process process, CancellationToken cancellationToken) | ||
{ | ||
if (process == null) | ||
throw new ArgumentNullException(nameof(process)); | ||
|
||
// Need to read /proc/[pid]/status | ||
// http://man7.org/linux/man-pages/man5/proc.5.html | ||
// https://unix.stackexchange.com/questions/102676/why-is-uid-information-not-in-proc-x-stat | ||
var pid = process.Id; | ||
var statusFile = ioManager.ConcatPath("/proc", pid.ToString(CultureInfo.InvariantCulture), "status"); | ||
var statusBytes = await ioManager.ReadAllBytes(statusFile, cancellationToken).ConfigureAwait(false); | ||
var statusText = Encoding.UTF8.GetString(statusBytes); | ||
var splits = statusText.Split('\n', StringSplitOptions.RemoveEmptyEntries); | ||
var entry = splits.FirstOrDefault(x => x.Trim().StartsWith("Uid:", StringComparison.Ordinal)); | ||
if (entry == default) | ||
return "UNKNOWN"; | ||
|
||
return entry | ||
.Substring(4) | ||
.Split(' ', StringSplitOptions.RemoveEmptyEntries) | ||
.FirstOrDefault(x => !String.IsNullOrWhiteSpace(x)) | ||
?? "UNPARSABLE"; | ||
} | ||
} | ||
} |
Oops, something went wrong.