mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-26 11:23:37 +04:00
add usr app: sig_ctrlc for sig testing
This commit is contained in:
parent
40c84071c0
commit
32098d61d3
42
user/src/bin/sig_ctrlc.rs
Normal file
42
user/src/bin/sig_ctrlc.rs
Normal file
@ -0,0 +1,42 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
use user_lib::*;
|
||||
use user_lib::console::getchar;
|
||||
|
||||
const LF: u8 = 0x0au8;
|
||||
const CR: u8 = 0x0du8;
|
||||
|
||||
fn func() {
|
||||
println!("signal_handler: caught signal SIGINT, and exit(1)");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn main() -> i32 {
|
||||
println!("sig_ctrlc starting.... Press 'ctrl-c' or 'ENTER' will quit.");
|
||||
|
||||
let mut new = SignalAction::default();
|
||||
let old = SignalAction::default();
|
||||
new.handler = func as usize;
|
||||
|
||||
println!("sig_ctrlc: sigaction");
|
||||
if sigaction(SIGINT, &new, &old) < 0 {
|
||||
panic!("Sigaction failed!");
|
||||
}
|
||||
println!("sig_ctrlc: getchar....");
|
||||
loop {
|
||||
let c = getchar();
|
||||
|
||||
println!("Got Char {}", c);
|
||||
if c == LF || c==CR {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
println!("sig_ctrlc: Done");
|
||||
0
|
||||
}
|
Loading…
Reference in New Issue
Block a user