diff options
| author | Laurence Tratt <laurie@tratt.net> | 2025-11-02 02:18:09 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-02 02:18:09 +0000 |
| commit | fff942ac54e2b8dd78ced619413565601f2ac1ea (patch) | |
| tree | 6ebb5264b57a28a8d50ab296f13671967f7904de | |
| parent | 1399545f48f3a7ec558377a7b935b9a94482d22b (diff) | |
| download | r-alacritty-fff942ac54e2b8dd78ced619413565601f2ac1ea.tar.gz r-alacritty-fff942ac54e2b8dd78ced619413565601f2ac1ea.tar.bz2 r-alacritty-fff942ac54e2b8dd78ced619413565601f2ac1ea.zip | |
Add foreground CWD implementation for OpenBSD
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | alacritty/src/daemon.rs | 37 |
2 files changed, 36 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index debd429c..b5460ce9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ Notable changes to the `alacritty_terminal` crate are documented in its ### Fixed - Brief error popup when saving the config file with some editors +- Subprocesses on OpenBSD now run with their CWD set to that of the shell's foreground process. ## 0.16.1 diff --git a/alacritty/src/daemon.rs b/alacritty/src/daemon.rs index fa530fa0..a6cf56d9 100644 --- a/alacritty/src/daemon.rs +++ b/alacritty/src/daemon.rs @@ -1,10 +1,14 @@ +#[cfg(target_os = "openbsd")] +use std::ffi::CStr; use std::ffi::OsStr; -#[cfg(not(any(target_os = "macos", windows)))] +#[cfg(not(any(target_os = "macos", target_os = "openbsd", windows)))] use std::fs; use std::io; #[cfg(windows)] use std::os::windows::process::CommandExt; use std::process::{Command, Stdio}; +#[cfg(target_os = "openbsd")] +use std::ptr; #[rustfmt::skip] #[cfg(not(windows))] @@ -88,7 +92,7 @@ where } /// Get working directory of controlling process. -#[cfg(not(windows))] +#[cfg(not(any(windows, target_os = "openbsd")))] pub fn foreground_process_path( master_fd: RawFd, shell_pid: u32, @@ -111,3 +115,32 @@ pub fn foreground_process_path( Ok(cwd) } + +#[cfg(target_os = "openbsd")] +pub fn foreground_process_path( + master_fd: RawFd, + shell_pid: u32, +) -> Result<PathBuf, Box<dyn Error>> { + let mut pid = unsafe { libc::tcgetpgrp(master_fd) }; + if pid < 0 { + pid = shell_pid as pid_t; + } + let name = [libc::CTL_KERN, libc::KERN_PROC_CWD, pid]; + let mut buf = [0u8; libc::PATH_MAX as usize]; + let result = unsafe { + libc::sysctl( + name.as_ptr(), + name.len().try_into().unwrap(), + buf.as_mut_ptr() as *mut _, + &mut buf.len() as *mut _, + ptr::null_mut(), + 0, + ) + }; + if result != 0 { + Err(io::Error::last_os_error().into()) + } else { + let foreground_path = unsafe { CStr::from_ptr(buf.as_ptr().cast()) }.to_str()?; + Ok(PathBuf::from(foreground_path)) + } +} |