Skip to content

Commit f36ab53

Browse files
committed
Update Readme for Linux compatibility
1 parent 3b201cc commit f36ab53

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

Readme.adoc

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ François Lamboley <[email protected]>
44
This package provides a Swift syntax for the low-level C `sigaction` function
55
and a way to delay or cancel sigaction handlers.
66

7-
It is only compatible with macOS for now. The package does compile on Linux, but
8-
crashes when used with an Illegal Instruction error which seems to be caused by
9-
`NSConditionLock`, which apparently simply does not work on Linux.
7+
It is compatible with macOS and Linux. Read the documentation carefully before
8+
using the sigaction handler delaying capabilities.
109

1110
== Example of Use
1211

@@ -99,7 +98,9 @@ not notify `libdispatch`.
9998

10099
* There is a non-avoidable race-condition (AFAICT) between the time the signal
101100
is sent and set back to ignored;
102-
* The signal that is sent back has lost the siginfo of the original signal.
101+
* The signal that is sent back has lost the siginfo of the original signal;
102+
* On Linux signal delaying is fragile. See Linux caveat of the blocking strategy
103+
for more information.
103104

104105
=== Details of the Blocking Strategy (`SigactionDelayer_Block`)
105106

@@ -119,11 +120,20 @@ unblock the signal, thus allowing it to be delivered.
119120

120121
**Caveats of this method**:
121122

122-
- On macOS, when a signal blocked on all threads is received, it seems to be
123+
* On macOS, when a signal blocked on all threads is received, it seems to be
123124
assigned to an arbitrary thread. Unblocking the signal on another thread will
124125
not unblock it at all. To workaround this problem we check if the signal is
125126
pending on the dedicated thread before unblocking it. If it is not, we send the
126127
signal to our thread, thus losing the sigaction again, exactly like when using
127128
the unsigaction strategy. Plus the original signal will stay pending on the
128129
affected thread forever.
129-
- On Linux this strategy cannot really work. See comments in the source.
130+
* On Linux, there is an issue where contrary to what the man page says,
131+
`libdispatch` https://github.com/apple/swift-corelibs-libdispatch/pull/560[does
132+
modify the sigaction of a signal when a dispatch source for this signal is first
133+
installed].
134+
So in theory this strategy should not work (and to be honest, the other one
135+
should not either). However, it has been noticed that changing the sigaction
136+
_after_ the signal source has been installed is enough to avoid this problem. So
137+
we save the sigaction before installing the signal source, then restore it after
138+
the source is installed, and we’re good. This solution seems fragile though, and
139+
might break in the future.

0 commit comments

Comments
 (0)