Skip to content

Instantly share code, notes, and snippets.

@jackpot51
Created July 11, 2017 02:37
Show Gist options
  • Save jackpot51/0802c06202f5499c9141c9122246b9fe to your computer and use it in GitHub Desktop.
Save jackpot51/0802c06202f5499c9141c9122246b9fe to your computer and use it in GitHub Desktop.
extern crate syscall;
use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering};
static RUNNING: AtomicBool = ATOMIC_BOOL_INIT;
extern "C" fn handler(sig: usize) {
println!("handler: signal {:X}", sig);
RUNNING.store(false, Ordering::SeqCst);
}
fn main() {
let mut action = syscall::data::SigAction::default();
action.sa_handler = handler;
let mut old_action = syscall::data::SigAction::default();
syscall::sigaction(syscall::flag::SIGINT, &action, &mut old_action).unwrap();
println!("sigaction {:X}, {:?} => {:?}", syscall::flag::SIGINT, old_action, action);
RUNNING.store(true, Ordering::SeqCst);
syscall::kill(syscall::getpid().unwrap(), syscall::flag::SIGINT).unwrap();
while RUNNING.load(Ordering::SeqCst) {
std::thread::sleep(std::time::Duration::new(5, 0));
}
println!("Exiting");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment