0 | module System.Linux.Signalfd.Prim
 1 |
 2 | import System.Posix.File.Prim
 3 | import System.Posix.Signal.Prim
 4 |
 5 | import public Data.C.Ptr
 6 | import public System.Linux.Signalfd.Flags
 7 | import public System.Linux.Signalfd.Struct
 8 |
 9 | %default total
10 |
11 | --------------------------------------------------------------------------------
12 | -- FFI
13 | --------------------------------------------------------------------------------
14 |
15 | %foreign "C:li_signalfd, linux-idris"
16 | prim__signalfd : AnyPtr -> Bits32 -> PrimIO CInt
17 |
18 | ||| Opens a new `signalfd` file descriptor for observing the
19 | ||| signals specified in the given `SigsetT`.
20 | |||
21 | |||
22 | ||| Notes:
23 | ||| * Usually, the signals in `set` should first be blocked via `sigprocmask`.
24 | ||| * A `signalfd` should be closed using `close` just like other file
25 | |||   descriptors.
26 | ||| * In general, use `readSignalfd` instead of the `read` functions
27 | |||   from `System.Posix.File` to read from a `signalfd`.
28 | export %inline
29 | signalfd_ : (set : SigsetT) -> SignalfdFlags -> EPrim Signalfd
30 | signalfd_ set (F f) = toVal cast $ prim__signalfd (unwrap set) f
31 |
32 | --------------------------------------------------------------------------------
33 | -- Convenience API
34 | --------------------------------------------------------------------------------
35 |
36 | ||| Convenience alias for `signalfd_`.
37 | export %inline
38 | signalfd : List Signal -> SignalfdFlags -> EPrim Signalfd
39 | signalfd ss fs = withSignals ss $ \set => signalfd_ set fs
40 |
41 | ||| Reads at most `n` values of type `Siginfo` from a `Signalfd`.
42 | export %inline
43 | readSignalfd : Signalfd -> Nat -> EPrim (List Siginfo)
44 | readSignalfd fd n = read fd _ (cast n * sizeof SiginfoT)
45 |