Skip to content

Commit a05c20a

Browse files
committed
Pass test_signal on Linux
1 parent ebda47f commit a05c20a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/core/IronPython.Modules/signal.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Runtime.InteropServices;
1313
using System.Runtime.Versioning;
1414

15+
using IronPython.Hosting;
1516
using IronPython.Runtime;
1617
using IronPython.Runtime.Exceptions;
1718
using IronPython.Runtime.Operations;
@@ -370,10 +371,15 @@ public static object default_int_handlerImpl(int signalnum, TraceBackFrame? fram
370371
}
371372
}
372373

374+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
375+
// These signals cannot be handled
376+
if (signalnum == SIGKILL || signalnum == SIGSTOP) throw PythonNT.GetOsError(PythonErrno.EINVAL);
377+
}
373378
object? last_handler = null;
374379
lock (GetPythonSignalState(context).PySignalToPyHandler) {
375380
// CPython returns the previous handler for the signal
376381
last_handler = getsignal(context, signalnum);
382+
if (last_handler is null) throw PythonNT.GetOsError(PythonErrno.EINVAL);
377383
// Set the new action
378384
GetPythonSignalState(context).PySignalToPyHandler[signalnum] = action;
379385
}
@@ -432,6 +438,10 @@ public PythonSignalState(PythonContext pc) {
432438
PySignalToPyHandler[sig] = SIG_DFL;
433439
}
434440
PySignalToPyHandler[SIGINT] = default_int_handler;
441+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) {
442+
PySignalToPyHandler[SIGPIPE] = SIG_IGN;
443+
PySignalToPyHandler[SIGXFSZ] = SIG_IGN;
444+
}
435445
}
436446
}
437447

0 commit comments

Comments
 (0)