pakr-signals 1.0.0

A set of functions to wrap Linux' sigset_t functionality and to do a rudimentary signals managemet.

A set of tools wrapping Linux' [libc::sigset_t] functionality and supporting Rust-firendly signals and pids definition.


use pakr_signals::*;

// Create empty SigSet
let mut sigset = SigSet::new();

// Add SIGUSR1 to SigSet

// Tests of presence

// SIGUSR1 is present

// SIGUSR2 is not present

// Has at least one of SIGUSR1/SIGUSR2

// Doesn't have every of SIGUSR1/SIGUSR2

// Hide from runtime. SIGINT (aka ^C) won't be handled by runtime anymore (^C won't break the
// program). It may be then handled by user-defined handler down the code.

let sigint = SigSet::from(&[Sig::INT]);
sigint.disable_default_handler().expect("Can't disable default handler for SIGINT");

let my_pid =  Pid::own().expect("Cant't get own PID");

// Send SIGINT to self (should be ignored)
Sig::INT.send_to(my_pid).expect("Can't send SIGINT");

// other syntax:
my_pid.send(Sig::INT).expect("Can't send SIGINT");

// Mark as processed by runtime. SIGQUIT (aka ^\) will be handled by runtime and would break the
// program with a core dump (if enabled in system).
// This is the default state - initally all signals are delivered to runtime, regardless of
// whether runtime ignores them (like SIGUSR1) or not (like SIGQUIT)
let sigquit = SigSet::from(&[Sig::QUIT]);
sigquit.enable_default_handler().expect("Can't enable default handler for SIGQUIT");