Skip to content

Commit 0f0fb5a

Browse files
committed
Fix potential take over of sigaction by libdispatch on Linux
1 parent f36ab53 commit 0f0fb5a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

Readme.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ should not either). However, it has been noticed that changing the sigaction
136136
_after_ the signal source has been installed is enough to avoid this problem. So
137137
we save the sigaction before installing the signal source, then restore it after
138138
the source is installed, and we’re good. This solution seems fragile though, and
139-
might break in the future.
139+
might break in the future, or not even work reliably right now.

Sources/SignalHandling/DelayedSigaction/SigactionDelayer_Block.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,17 @@ public enum SigactionDelayer_Block {
256256

257257
#if os(Linux)
258258
/* On Linux, the sigaction must be reset after a dispatch source signal
259-
 * is registerd because libdispatch _does_ modify the sigaction.
259+
 * is registerd because libdispatch _does_ modify the sigaction. It
260+
 * turns out we cannot update the sigaction synchronously here though,
261+
 * because libdispatch does not update the sigaction directly, so we do
262+
 * it asynchronously.
263+
 * This is sooooo fragile (and introduces a race condition too).
260264
 * https://github.com/apple/swift-corelibs-libdispatch/pull/560 */
261-
do {try currentSigaction.install(on: signal)}
262-
catch {
263-
dispatchSourceSignal.cancel()
264-
throw error
265+
signalProcessingQueue.async{
266+
do {try currentSigaction.install(on: signal)}
267+
catch {
268+
SignalHandlingConfig.logger?.error("Cannot set original sigaction back for signal \(signal) after signal source activation. You might never be called in the sigaction handler and get an infinite loop of signal calls once this signal has been sent once.")
269+
}
265270
}
266271
#endif
267272

0 commit comments

Comments
 (0)