Function set_unsafe_handler

Source
pub unsafe fn set_unsafe_handler(
    signal_type: SignalType,
    handler: SignalHandler,
) -> Result<(), SetHandlerError>
Available on Unix and crate feature signals only.
Expand description

Installs the specified handler for the specified unsafe signal, using the default values for the flags.

See HandlerOptions builder if you’d like to customize the flags.

§Safety

See the set_unsafe safety notes.

§Example

use interprocess::os::unix::signal::{self, SignalType, SignalHandler};

let handler = unsafe {
    // Since signal handlers are restricted to a specific set of C functions, creating a
    // handler from an arbitrary function is unsafe because it might call a function
    // outside the list, and there's no real way to know that at compile time with the
    // current version of Rust. Since we're only using the write() system call here, this
    // is safe.
    SignalHandler::from_fn(|| {
        println!("Oh no, the motherboard broke!");
        std::process::abort();
    })
};

unsafe {
    // Install our handler for the MemoryBusError signal type.
    signal::set_unsafe_handler(SignalType::MemoryBusError, handler)?;
}