sig/macros.rs
1// @adjivas - github.com/adjivas. See the LICENSE
2// file at the top-level directory of this distribution and at
3// https://github.com/adjivas/sig
4//
5// This file may not be copied, modified, or distributed
6// except according to those terms.
7
8/// The `getpid` macro returns the PID of
9/// program.
10
11#[macro_export]
12macro_rules! getpid {
13 () => ({
14 unsafe { $crate::ffi::getpid() }
15 });
16}
17
18/// The `signal` macro receives a signal to
19/// a PID program.
20
21#[macro_export]
22macro_rules! signal {
23 ($sig: expr, $fnc: expr) => ({
24 unsafe {
25 $crate::set_signal_handler (
26 $sig as $crate::ffi::c_int,
27 $fnc
28 )
29 }
30 });
31}
32
33/// The `signal` macro sends a signal to
34/// a PID program.
35
36#[macro_export]
37macro_rules! kill {
38 ($pid: expr) => ({
39 kill!($pid, sig::ffi::Sig::KILL)
40 });
41 ($pid: expr, $sig: expr) => ({
42 match unsafe {
43 sig::ffi::kill (
44 $pid as $crate::ffi::pid_t,
45 $sig as $crate::ffi::c_int,
46 )
47 } {
48 -1 => true,
49 _ => false,
50 }
51 });
52}