From e94d09da9449cabd7ece2acd98d52b1946a922a4 Mon Sep 17 00:00:00 2001 From: Rory Dudley Date: Tue, 27 Feb 2024 03:49:01 -0700 Subject: Remove custom errors and fix background forking Removes the custom errors in src/recite/erro.rs, and replaces them with std::io::Errors throughout (recite(), incant_, macros). Fixed a bug with the way forking to the background is handled, where registering the signal handler in main for all processes would break couplets (i.e. pipes). Instead, this sets up a new signal handler each time a process is forked into the background. It uses a Vec to keep track of all the background processes. --- src/main.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 44f2726..b87089a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,4 @@ mod recite; -use libc::{waitpid, WNOHANG}; use recite::path::prefresh; use recite::Poem; use std::io::{self, Write}; @@ -43,6 +42,16 @@ fn repl(path: &Vec<&Path>, prompt: &str) { break; } + // Kill zombies + // TODO: Remove this (since it was implemented in incant_quiet()) + // unsafe { + // let mut status = -1; + // let mut pid = waitpid(-1, &mut status, WNOHANG); + // while pid > 0 { + // pid = waitpid(-1, &mut status, WNOHANG); + // } + // } + // Trim the input let poetry = String::from(poetry.trim()); @@ -56,7 +65,7 @@ fn repl(path: &Vec<&Path>, prompt: &str) { match poem { Some(poem) => match poem.recite(path, &mut bins) { Ok(_) => {} - Err(e) => eprintln!("dwvsh: {}", e), + Err(e) => eprintln!("dwvsh: {}", e.to_string().to_lowercase()), }, None => {} }; @@ -89,16 +98,6 @@ fn main() { io::stdout().flush().unwrap(); }) .unwrap(); - - signal_hook::low_level::register(signal_hook::consts::SIGCHLD, move || { - let mut status: i32 = -1; - let pid: i32 = waitpid(-1, &mut status, WNOHANG); - if pid != -1 { - print!("[&] + done {}", pid); - io::stdout().flush().unwrap(); - } - }) - .unwrap(); }; // Begin evaluating commands -- cgit v1.2.3