Skip to content

Commit 7fd2ea2

Browse files
committed
Adjust CommandSignals to be strings
1 parent 45794dc commit 7fd2ea2

File tree

2 files changed

+25
-39
lines changed

2 files changed

+25
-39
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,73 @@
11
namespace Renci.SshNet
22
{
33
/// <summary>
4-
/// The ssh compatible POSIX/ANSI signals with their libc compatible values.
4+
/// The ssh compatible standard POSIX/ANSI signals.
55
/// </summary>
6-
#pragma warning disable CA1720 // Identifier contains type name
7-
public enum CommandSignal
6+
public static class CommandSignals
87
{
98
/// <summary>
109
/// Hangup (POSIX).
1110
/// </summary>
12-
HUP = 1,
11+
public const string SIGHUP = "HUP";
1312

1413
/// <summary>
1514
/// Interrupt (ANSI).
1615
/// </summary>
17-
INT = 2,
16+
public const string SIGINT = "INT";
1817

1918
/// <summary>
2019
/// Quit (POSIX).
2120
/// </summary>
22-
QUIT = 3,
21+
public const string SIGQUIT = "QUIT";
2322

2423
/// <summary>
2524
/// Illegal instruction (ANSI).
2625
/// </summary>
27-
ILL = 4,
26+
public const string SIGILL = "ILL";
2827

2928
/// <summary>
3029
/// Abort (ANSI).
3130
/// </summary>
32-
ABRT = 6,
31+
public const string SIGABRT = "ABRT";
3332

3433
/// <summary>
3534
/// Floating-point exception (ANSI).
3635
/// </summary>
37-
FPE = 8,
36+
public const string SIGFPE = "FPE";
3837

3938
/// <summary>
4039
/// Kill, unblockable (POSIX).
4140
/// </summary>
42-
KILL = 9,
41+
public const string SIGKILL = "KILL";
4342

4443
/// <summary>
4544
/// User-defined signal 1 (POSIX).
4645
/// </summary>
47-
USR1 = 10,
46+
public const string SIGUSR1 = "USR1";
4847

4948
/// <summary>
5049
/// Segmentation violation (ANSI).
5150
/// </summary>
52-
SEGV = 11,
51+
public const string SIGSEGV = "SEGV";
5352

5453
/// <summary>
5554
/// User-defined signal 2 (POSIX).
5655
/// </summary>
57-
USR2 = 12,
56+
public const string SIGUSR2 = "USR2";
5857

5958
/// <summary>
6059
/// Broken pipe (POSIX).
6160
/// </summary>
62-
PIPE = 13,
61+
public const string SIGPIPE = "PIPE";
6362

6463
/// <summary>
6564
/// Alarm clock (POSIX).
6665
/// </summary>
67-
ALRM = 14,
66+
public const string SIGALRM = "ALRM";
6867

6968
/// <summary>
7069
/// Termination (ANSI).
7170
/// </summary>
72-
TERM = 15,
71+
public const string SIGTERM = "TERM";
7372
}
7473
}

src/Renci.SshNet/SshCommand.cs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -478,26 +478,14 @@ public void CancelAsync(bool forceKill = false, int millisecondsTimeout = 500)
478478
}
479479
}
480480

481-
private static string? GetSignalName(CommandSignal signal)
482-
{
483-
#if NETCOREAPP
484-
return Enum.GetName(signal);
485-
#else
486-
487-
// Boxes signal, but Enum.GetName does not have a non-boxing overload prior to .NET Core.
488-
return Enum.GetName(typeof(CommandSignal), signal);
489-
#endif
490-
}
491-
492481
/// <summary>
493-
/// Tries to send a POSIX/ANSI signal to the remote process executing the command, such as SIGINT or SIGTERM.
482+
/// Tries to send a POSIX/ANSI signal to the remote process executing the command, such as SIGTERM or any of the <see cref="CommandSignals"/>.
494483
/// </summary>
495-
/// <param name="signal">The signal to send.</param>
484+
/// <param name="signal">The signal to send. See <see cref="CommandSignals"/> for a standard list of signals.</param>
496485
/// <returns>If the signal was sent.</returns>
497-
public bool TrySendSignal(CommandSignal signal)
486+
public bool TrySendSignal(string signal)
498487
{
499-
var signalName = GetSignalName(signal);
500-
if (signalName is null)
488+
if (signal is null)
501489
{
502490
return false;
503491
}
@@ -510,7 +498,7 @@ public bool TrySendSignal(CommandSignal signal)
510498
try
511499
{
512500
// Try to send the cancellation signal.
513-
return _channel.SendSignalRequest(signalName);
501+
return _channel.SendSignalRequest(signal);
514502
}
515503
catch (Exception)
516504
{
@@ -522,18 +510,17 @@ public bool TrySendSignal(CommandSignal signal)
522510
}
523511

524512
/// <summary>
525-
/// Tries to send a POSIX/ANSI signal to the remote process executing the command, such as SIGINT or SIGTERM.
513+
/// Tries to send a POSIX/ANSI signal to the remote process executing the command, such as SIGTERM or any of the <see cref="CommandSignals"/>.
526514
/// </summary>
527-
/// <param name="signal">The signal to send.</param>
515+
/// <param name="signal">The signal to send. See <see cref="CommandSignals"/> for a standard list of signals.</param>
528516
/// <exception cref="ArgumentException">Signal was not a valid CommandSignal.</exception>
529517
/// <exception cref="SshConnectionException">The client is not connected.</exception>
530518
/// <exception cref="SshOperationTimeoutException">The operation timed out.</exception>
531519
/// <exception cref="InvalidOperationException">The size of the packet exceeds the maximum size defined by the protocol.</exception>
532520
/// <exception cref="InvalidOperationException">Command has not been started.</exception>
533-
public void SendSignal(CommandSignal signal)
521+
public void SendSignal(string signal)
534522
{
535-
var signalName = GetSignalName(signal);
536-
if (signalName is null)
523+
if (signal is null)
537524
{
538525
throw new ArgumentException("Signal was not a valid CommandSignal.");
539526
}
@@ -543,7 +530,7 @@ public void SendSignal(CommandSignal signal)
543530
throw new InvalidOperationException("Command has not been started.");
544531
}
545532

546-
_ = _channel.SendSignalRequest(signalName);
533+
_ = _channel.SendSignalRequest(signal);
547534
}
548535

549536
/// <summary>

0 commit comments

Comments
 (0)