summaryrefslogtreecommitdiff
path: root/src/luma/app/ini.rs
blob: 2c4e86f28306a3fb375d230cf683115187098a70 (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 2021-2023 Gabriel Jensen.

use crate::luma::app::{App, GOTSIG};

extern crate libc;

use libc::{c_int, sighandler_t, SIGINT, signal, SIGTERM};
use std::mem::transmute;
use std::sync::atomic::Ordering;

fn sighnd(sig: c_int) {
	unsafe {
		signal(sig, transmute::<fn(c_int), sighandler_t>(sighnd));

		GOTSIG.store(true, Ordering::Relaxed);
	}
}

impl App {
	pub fn ini(&mut self) {
		eprintln!("initialising");

		unsafe {
			signal(SIGINT,  transmute::<fn(c_int), sighandler_t>(sighnd));
			signal(SIGTERM, transmute::<fn(c_int), sighandler_t>(sighnd));
		}
	}
}