diff options
Diffstat (limited to 'source/dw/app/inisig.rs')
-rw-r--r-- | source/dw/app/inisig.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/source/dw/app/inisig.rs b/source/dw/app/inisig.rs new file mode 100644 index 0000000..12e8061 --- /dev/null +++ b/source/dw/app/inisig.rs @@ -0,0 +1,28 @@ +// Copyright 2023 Gabriel Jensen. + +use crate::dw::app::{App,GOTINT}; + +extern crate libc; + +use libc::{c_int,sighandler_t,signal,SIGINT,SIGTERM}; +use std::mem::transmute; +use std::sync::atomic::Ordering; + +fn hnd(sig: c_int) { + unsafe { + signal(sig,transmute::<fn(c_int),sighandler_t>(hnd)); + + GOTINT.store(true,Ordering::Relaxed); + } +} + +impl App { + pub fn inisig(&mut self) { + eprintln!("initialising signal handlers"); + + unsafe { + signal(SIGINT, transmute::<fn(c_int),sighandler_t>(hnd)); + signal(SIGTERM,transmute::<fn(c_int),sighandler_t>(hnd)); + } + } +} |