summaryrefslogtreecommitdiff
path: root/source/dw/app/inisig.rs
blob: 12e80619b903129040e6e47e41df614d8235e45c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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));
		}
	}
}