-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fcba78
commit 5147fb2
Showing
2 changed files
with
51 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//SPDX-FileCopyrightText: 2024 Ryuichi Ueda ryuichiueda@gmail.com | ||
//SPDX-License-Identifier: BSD-3-Clause | ||
|
||
use std::{thread, time}; | ||
use std::sync::Arc; | ||
use std::sync::atomic::Ordering::Relaxed; | ||
use crate::core::ShellCore; | ||
use crate::feeder::Feeder; | ||
use signal_hook::consts; | ||
use signal_hook::iterator::Signals; | ||
|
||
pub fn run_signal_check(core: &mut ShellCore) { | ||
for fd in 3..10 { //use FD 3~9 to prevent signal-hool from using these FDs | ||
nix::unistd::dup2(2, fd).expect("sush(fatal): init error"); | ||
} | ||
|
||
let sigint = Arc::clone(&core.sigint); //追加 | ||
|
||
thread::spawn(move || { | ||
let mut signals = Signals::new(vec![consts::SIGINT]) | ||
.expect("sush(fatal): cannot prepare signal data"); | ||
|
||
for fd in 3..10 { // release FD 3~9 | ||
nix::unistd::close(fd).expect("sush(fatal): init error"); | ||
} | ||
|
||
loop { | ||
thread::sleep(time::Duration::from_millis(100)); //0.1秒周期に変更 | ||
for signal in signals.pending() { | ||
if signal == consts::SIGINT { | ||
sigint.store(true, Relaxed); | ||
} | ||
} | ||
} | ||
}); | ||
} //thanks: https://dev.to/talzvon/handling-unix-kill-signals-in-rust-55g6 | ||
|
||
pub fn input_interrupt_check(feeder: &mut Feeder, core: &mut ShellCore) -> bool { | ||
if ! core.sigint.load(Relaxed) { //core.input_interrupt { | ||
return false; | ||
} | ||
|
||
core.sigint.store(false, Relaxed); //core.input_interrupt = false; | ||
core.data.set_param("?", "130"); | ||
feeder.consume(feeder.len()); | ||
true | ||
} |