1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-27 15:37:29 +03:00

skip_close_confirmation_for_processes_named now also works on macos

refs: https://github.com/wez/wezterm/issues/562
This commit is contained in:
Wez Furlong 2021-03-22 12:57:36 -07:00
parent 1b7c980646
commit 4d4fa35557
2 changed files with 33 additions and 2 deletions

View File

@ -2,7 +2,7 @@
*Since: nightly*
This currently only applies to linux systems.
This only applies to linux and macOS systems.
This configuration specifies a list of process names that are
considered to be "stateless" and that are safe to close without

View File

@ -11,6 +11,7 @@ use portable_pty::{Child, MasterPty, PtySize};
use rangeset::RangeSet;
use std::cell::{RefCell, RefMut};
use std::ops::Range;
use std::path::Path;
use std::sync::Arc;
use termwiz::escape::DeviceControlMode;
use termwiz::surface::Line;
@ -244,7 +245,6 @@ impl Pane for LocalPane {
fn can_close_without_prompting(&self) -> bool {
if let Some(proc) = self.divine_foreground_proc() {
log::info!("can_close_without_prompting: proc is {}", proc);
configuration()
.skip_close_confirmation_for_processes_named
.iter()
@ -593,12 +593,43 @@ impl LocalPane {
None
}
#[cfg(target_os = "macos")]
fn divine_foreground_proc_macos(&self) -> Option<String> {
if let Some(pid) = self.pty.borrow().process_group_leader() {
extern "C" {
fn proc_pidpath(
pid: libc::pid_t,
buffer: *mut u8,
buffersize: libc::c_int,
) -> libc::c_int;
}
let mut buf = [0u8; 4096];
let ret = unsafe { proc_pidpath(pid, buf.as_mut_ptr(), buf.len() as libc::c_int) };
if ret > 0 {
use std::ffi::OsStr;
use std::os::unix::ffi::OsStrExt;
let buf = &buf[..ret as usize];
let path = Path::new(OsStr::from_bytes(buf));
let name = path.file_name()?;
return name.to_str().map(|s| s.to_string());
}
}
None
}
fn divine_foreground_proc(&self) -> Option<String> {
#[cfg(target_os = "linux")]
{
return self.divine_foreground_proc_linux();
}
#[cfg(target_os = "macos")]
{
return self.divine_foreground_proc_macos();
}
#[allow(unreachable_code)]
None
}