0 | module System.Posix.Signal
 1 |
 2 | import Data.C.Ptr
 3 |
 4 | import System.Posix.Signal.Prim as P
 5 |
 6 | import public Data.C.Integer
 7 | import public System.Posix.Errno
 8 | import public System.Posix.Signal.Struct
 9 | import public System.Posix.Signal.Types
10 |
11 | %default total
12 |
13 | --------------------------------------------------------------------------------
14 | -- API
15 | --------------------------------------------------------------------------------
16 |
17 | ||| Sends a signal to a running process or a group of processes.
18 | export %inline
19 | kill : Has Errno es => EIO1 f => PidT -> Signal -> f es ()
20 | kill p s = elift1 (P.kill p s)
21 |
22 | ||| Sends a signal to the calling thread.
23 | export %inline
24 | raise : HasIO io => Signal -> io ()
25 | raise s = primIO (P.raise s)
26 |
27 | ||| Sends a realtime signal plus data word to a running process.
28 | |||
29 | ||| Note that `sig` must be in the range [SIGRTMIN, SIGRTMAX].
30 | export %inline
31 | sigqueue : Has Errno es => EIO1 f => PidT -> Signal -> (word : CInt) -> f es ()
32 | sigqueue p s word = elift1 (P.sigqueue p s word)
33 |
34 | ||| Adjust the process signal mask according to the given `How`
35 | ||| and signal set.
36 | export %inline
37 | sigprocmask : Has Errno es => EIO1 f => How -> List Signal -> f es ()
38 | sigprocmask h ss = elift1 (P.sigprocmask h ss)
39 |
40 | ||| Terminates the application by raising `SIGABRT` and dumps core.
41 | |||
42 | ||| While `SIGABRT` can be handled with a signal handler, `abort` is
43 | ||| still guaranteed successfully terminate the process.
44 | export %inline
45 | abort : HasIO io => io ()
46 | abort = primIO P.abort
47 |
48 | ||| Suspends the current thread until a non-blocked signal is encountered.
49 | export %inline
50 | pause : Has Errno es => EIO1 f => f es ()
51 | pause = elift1 P.pause
52 |
53 | ||| Returns the current signal mask of the process.
54 | export %inline
55 | siggetprocmask : HasIO io => io (List Signal)
56 | siggetprocmask = primIO P.siggetprocmask
57 |
58 | ||| Returns the set of currently pending signals.
59 | export %inline
60 | sigpending : HasIO io => io (List Signal)
61 | sigpending = primIO P.sigpending
62 |
63 | ||| Atomically blocks the signals in `set`, then
64 | ||| pauses the thread (see `pause`) and restores the signal set
65 | ||| afterwards.
66 | export %inline
67 | sigsuspend : Has Errno es => EIO1 f => List Signal -> f es ()
68 | sigsuspend ss = elift1 (P.sigsuspend ss)
69 |
70 | ||| Synchronously awaits one of the signals in `set`.
71 | |||
72 | ||| This is like `sigwaitinfo` but with a simpler API.
73 | export %inline
74 | sigwait : Has Errno es => EIO1 f => List Signal -> f es Signal
75 | sigwait ss = elift1 (P.sigwait ss)
76 |
77 | ||| Synchronously awaits one of the signals in `set`.
78 | |||
79 | ||| Note: Usually, the signals in `set` should first be blocked via
80 | |||       `sigprocmask`.
81 | export
82 | sigwaitinfo : Has Errno es => EIO1 f => List Signal -> f es Siginfo
83 | sigwaitinfo ss = elift1 (P.sigwaitinfo ss)
84 |