Skip to content

Commit

Permalink
[WASI] Skip signal handler registration on WASI
Browse files Browse the repository at this point in the history
WASI does not support POSIX signals, but `Microsoft.Extensions.Hosting` works
fine as long as we don't try to register or deregister signal handlers.

Signed-off-by: Joel Dice <[email protected]>
  • Loading branch information
dicej committed Nov 14, 2024
1 parent 099bf1e commit b45da08
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ public partial class ConsoleLifetime : IHostLifetime

private partial void RegisterShutdownHandlers()
{
Action<PosixSignalContext> handler = HandlePosixSignal;
_sigIntRegistration = PosixSignalRegistration.Create(PosixSignal.SIGINT, handler);
_sigQuitRegistration = PosixSignalRegistration.Create(PosixSignal.SIGQUIT, handler);
_sigTermRegistration = PosixSignalRegistration.Create(PosixSignal.SIGTERM, handler);
if (!OperatingSystem.IsWasi())
{
Action<PosixSignalContext> handler = HandlePosixSignal;
_sigIntRegistration = PosixSignalRegistration.Create(PosixSignal.SIGINT, handler);
_sigQuitRegistration = PosixSignalRegistration.Create(PosixSignal.SIGQUIT, handler);
_sigTermRegistration = PosixSignalRegistration.Create(PosixSignal.SIGTERM, handler);
}
}

private void HandlePosixSignal(PosixSignalContext context)
Expand All @@ -31,9 +34,12 @@ private void HandlePosixSignal(PosixSignalContext context)

private partial void UnregisterShutdownHandlers()
{
_sigIntRegistration?.Dispose();
_sigQuitRegistration?.Dispose();
_sigTermRegistration?.Dispose();
if (!OperatingSystem.IsWasi())
{
_sigIntRegistration?.Dispose();
_sigQuitRegistration?.Dispose();
_sigTermRegistration?.Dispose();
}
}
}
}

0 comments on commit b45da08

Please sign in to comment.