summaryrefslogtreecommitdiffstats
path: root/src/recite.rs
diff options
context:
space:
mode:
authorRory Dudley2024-02-29 01:40:27 -0700
committerRory Dudley2024-02-29 01:40:27 -0700
commit718f45492a4b2c31a67458c13c4cd4b3268703bc (patch)
treed577bc14368319adac8bf24e0a757b5eccd24df8 /src/recite.rs
parent2be80340afbc457f22f8c4cc441ef572b0acfda1 (diff)
downloaddwarvish-718f45492a4b2c31a67458c13c4cd4b3268703bc.tar.gz
Fix handling of SIGINT
Keep track of a new atomic variable: at_prompt, which is set to true just before blocking on io::stdin.read_line, and set to false just calling Poem::read. Additionally, for background tasks, there is a new ps macro called btask, which changes the process group of commands that are forked into the background, so that they don't receive SIGINT from the keyboard.
Notes
Notes: Changing the process group on the Command is done via CommandExt. More details here: https://doc.rust-lang.org/std/os/unix/process/trait.CommandExt.html#tymethod.process_group
Diffstat (limited to 'src/recite.rs')
-rw-r--r--src/recite.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/recite.rs b/src/recite.rs
index bd72b67..1aa1a62 100644
--- a/src/recite.rs
+++ b/src/recite.rs
@@ -1,10 +1,11 @@
pub mod path;
mod ps;
-use crate::{ctask, task};
+use crate::{btask, ctask, task};
use core::fmt;
use libc::{waitpid, WNOHANG};
use path::prefresh;
use std::io::{self, Write};
+use std::os::unix::process::CommandExt;
use std::path::Path;
use std::process::{exit, Command, Stdio};
use std::sync::{Arc, Mutex};
@@ -125,7 +126,7 @@ impl Meter {
out: &mut String,
pids: &mut Arc<Mutex<Vec<i32>>>,
) -> Result<i32, io::Error> {
- let child = task!(verse, out);
+ let child = btask!(verse, out);
println!("[&] {}", child.id());
pids.lock().unwrap().push(child.id() as i32);