Skip to content

Commit c975e87

Browse files
github-actions[bot]JamesWTruhertmds
authored
[release/6.0] The signal enum in the native library should match the managed code. (#58682)
* The signal enum in the native library should match the managed code. * PosixSignalRegistrationTests.Unix: validate signal pal mapping (#58711) * PosixSignalRegistrationTests.Unix: validate signal pal mapping * Use InvariantCulture for pid ToString * Invoke kill through shell. * Remove InvariantCulture Co-authored-by: James Truher <jimtru@microsoft.com> Co-authored-by: Tom Deseyn <tom.deseyn@gmail.com>
1 parent 6eca241 commit c975e87

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/libraries/Native/Unix/System.Native/pal_signal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ typedef enum
4040
PosixSignalSIGQUIT = -3,
4141
PosixSignalSIGTERM = -4,
4242
PosixSignalSIGCHLD = -5,
43-
PosixSignalSIGWINCH = -6,
44-
PosixSignalSIGCONT = -7,
43+
PosixSignalSIGCONT = -6,
44+
PosixSignalSIGWINCH = -7,
4545
PosixSignalSIGTTIN = -8,
4646
PosixSignalSIGTTOU = -9,
4747
PosixSignalSIGTSTP = -10

src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/PosixSignalRegistrationTests.Unix.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Xunit;
5+
using System.Diagnostics;
6+
using System.Globalization;
57
using System.Threading;
68
using System.Runtime.InteropServices;
79
using System.Runtime.CompilerServices;
@@ -57,7 +59,16 @@ public void SignalHandlerCalledForKnownSignals(PosixSignal s)
5759
semaphore.Release();
5860
});
5961

60-
kill(signal);
62+
// Use 'kill' command with signal name to validate the signal pal mapping.
63+
string sigArg = signalStr.StartsWith("SIG") ? signalStr.Substring(3) : signalStr;
64+
using var process = Process.Start(new ProcessStartInfo
65+
{
66+
FileName = "/bin/sh", // Use a shell because not all platforms include a 'kill' executable.
67+
ArgumentList = { "-c", $"kill -s {sigArg} {Environment.ProcessId.ToString()}" }
68+
});
69+
process.WaitForExit();
70+
Assert.Equal(0, process.ExitCode);
71+
6172
bool entered = semaphore.Wait(SuccessTimeout);
6273
Assert.True(entered);
6374
}, s.ToString()).Dispose();

0 commit comments

Comments
 (0)