From 096c51992b1c32695c0e17329d1eeda45e026a9d Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Wed, 17 Apr 2024 22:39:13 -0500 Subject: [PATCH] Don't set ignore status for SIGTERM and SIGINT on Linux (#3174) --- Sources/Vapor/Commands/ServeCommand.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/Vapor/Commands/ServeCommand.swift b/Sources/Vapor/Commands/ServeCommand.swift index a089fd3c98..2947bfe635 100644 --- a/Sources/Vapor/Commands/ServeCommand.swift +++ b/Sources/Vapor/Commands/ServeCommand.swift @@ -85,6 +85,11 @@ public final class ServeCommand: Command, Sendable { // setup signal sources for shutdown let signalQueue = DispatchQueue(label: "codes.vapor.server.shutdown") func makeSignalSource(_ code: Int32) { + #if canImport(Darwin) + /// https://github.com/swift-server/swift-service-lifecycle/blob/main/Sources/UnixSignals/UnixSignalsSequence.swift#L77-L82 + signal(code, SIG_IGN) + #endif + let source = DispatchSource.makeSignalSource(signal: code, queue: signalQueue) source.setEventHandler { print() // clear ^C @@ -92,7 +97,6 @@ public final class ServeCommand: Command, Sendable { } source.resume() box.signalSources.append(source) - signal(code, SIG_IGN) } makeSignalSource(SIGTERM) makeSignalSource(SIGINT)