| 1098 | } |
| 1099 | |
| 1100 | pub fn kill_child(child: &mut Child) { |
| 1101 | let r = unsafe { libc::kill(child.id() as i32, libc::SIGTERM) }; |
| 1102 | if r != 0 { |
| 1103 | let e = io::Error::last_os_error(); |
| 1104 | if e.raw_os_error().unwrap() == libc::ESRCH { |
| 1105 | return; |
| 1106 | } |
| 1107 | eprintln!("Failed to kill child with SIGTERM: {e:?}"); |
| 1108 | } |
| 1109 | |
| 1110 | // The timeout period elapsed without the child exiting |
| 1111 | if child.wait_timeout(Duration::new(10, 0)).unwrap().is_none() { |
| 1112 | let _ = child.kill(); |
| 1113 | let rust_flags = env::var("RUSTFLAGS").unwrap_or_default(); |
| 1114 | if rust_flags.contains("-Cinstrument-coverage") { |
| 1115 | panic!("Wait child timeout, please check the reason.") |
| 1116 | } |
| 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | #[derive(Debug)] |
| 1121 | pub struct MetaEvent { |