#[cfg(unix)]
pub(super) fn terminate_owned_session(pty: &dyn portable_pty::MasterPty, leader: u32) {
let leader = leader as libc::pid_t;
if let Some(tty) = pty.tty_name().map(|path| {
path.strip_prefix("/dev")
.map(std::path::PathBuf::from)
.unwrap_or(path)
}) {
if let Ok(output) = std::process::Command::new("/bin/ps")
.args(["-t", &tty.to_string_lossy(), "-o", "pid="])
.output()
{
if output.status.success() {
for pid in String::from_utf8_lossy(&output.stdout)
.split_whitespace()
.filter_map(|word| word.parse::<libc::pid_t>().ok())
{
unsafe {
if pid > 1 && pid != leader && libc::getsid(pid) == leader {
libc::kill(pid, libc::SIGKILL);
}
}
}
}
}
}
unsafe {
if libc::getsid(leader) == leader {
libc::kill(-leader, libc::SIGKILL);
}
}
}