0 | module System.Linux.Signalfd
 1 |
 2 | import System.Linux.Signalfd.Prim as P
 3 |
 4 | import public Data.C.Ptr
 5 | import public System.Linux.Signalfd.Flags
 6 | import public System.Linux.Signalfd.Struct
 7 | import public System.Posix.File
 8 | import public System.Posix.Signal
 9 |
10 | %default total
11 |
12 | --------------------------------------------------------------------------------
13 | -- API
14 | --------------------------------------------------------------------------------
15 |
16 | ||| Opens a new `signalfd` file descriptor for observing the
17 | ||| signals specified in the given `SigsetT`.
18 | |||
19 | |||
20 | ||| Notes:
21 | ||| * Usually, the signals in `set` should first be blocked via `sigprocmask`.
22 | ||| * A `signalfd` should be closed using `close` just like other file
23 | |||   descriptors.
24 | ||| * In general, use `readSignalfd` instead of the `read` functions
25 | |||   from `System.Posix.File` to read from a `signalfd`.
26 | export %inline
27 | signalfd_ : Has Errno es => EIO1 f => (set : SigsetT) -> SignalfdFlags -> f es Signalfd
28 | signalfd_ set fs = elift1 (P.signalfd_ set fs)
29 |
30 | --------------------------------------------------------------------------------
31 | -- Convenience API
32 | --------------------------------------------------------------------------------
33 |
34 | ||| Convenience alias for `signalfd_`.
35 | export %inline
36 | signalfd : Has Errno es => EIO1 f => List Signal -> SignalfdFlags -> f es Signalfd
37 | signalfd ss fs = elift1 (P.signalfd ss fs)
38 |
39 | ||| Reads data from a `signalfd` into a pre-allocated array.
40 | |||
41 | ||| Note: This will overwrite the data stored in `arr` and the
42 | |||       result is a wrapper around the same pointer.
43 | export
44 | readSignalfd : Has Errno es => EIO1 f => Signalfd -> Nat -> f es (List Siginfo)
45 | readSignalfd fd n = elift1 (P.readSignalfd fd n)
46 |