diff --git a/src/builtins/ulimit.rs b/src/builtins/ulimit.rs index c8dd35ee7..6c5e30207 100644 --- a/src/builtins/ulimit.rs +++ b/src/builtins/ulimit.rs @@ -71,13 +71,13 @@ pub mod bsd { use libc; pub const SBSIZE: libc::c_int = libc::RLIMIT_SBSIZE; - pub const NICE: libc::c_int = libc::RLIMIT_NICE; pub const RSS: libc::c_int = libc::RLIMIT_RSS; - pub const NTHR: libc::c_int = libc::RLIMIT_NTHR; pub const SWAP: libc::c_int = libc::RLIMIT_SWAP; pub const KQUEUES: libc::c_int = libc::RLIMIT_KQUEUES; pub const NPTS: libc::c_int = libc::RLIMIT_NPTS; + pub const NICE: libc::c_int = -1; + pub const NTHR: libc::c_int = -1; pub const SIGPENDING: libc::c_int = -1; pub const MSGQUEUE: libc::c_int = -1; pub const RTPRIO: libc::c_int = -1; diff --git a/src/env/environment.rs b/src/env/environment.rs index 3c357bbf1..16f749c7a 100644 --- a/src/env/environment.rs +++ b/src/env/environment.rs @@ -26,7 +26,7 @@ use crate::wcstringutil::join_strings; use crate::wutil::{fish_wcstol, wgetcwd, wgettext}; -use libc::{c_int, confstr, uid_t}; +use libc::{c_int, uid_t}; use once_cell::sync::{Lazy, OnceCell}; use std::collections::HashMap; use std::ffi::CStr; @@ -566,25 +566,29 @@ fn setup_user(vars: &EnvStack) { } pub(crate) static FALLBACK_PATH: Lazy<&[WString]> = Lazy::new(|| { - // _CS_PATH: colon-separated paths to find POSIX utilities - let buf_size = unsafe { confstr(libc::_CS_PATH, std::ptr::null_mut(), 0) }; - Box::leak( - (if buf_size > 0 { - let mut buf = vec![b'\0' as libc::c_char; buf_size]; - unsafe { confstr(libc::_CS_PATH, buf.as_mut_ptr(), buf_size) }; - let buf = buf; - // safety: buf should contain a null-byte, and is not mutable unless we move ownership - let cstr = unsafe { CStr::from_ptr(buf.as_ptr()) }; - colon_split(&[str2wcstring(cstr.to_bytes())]) - } else { - vec![ - WString::from_str(env!("PREFIX")) + L!("/bin"), - L!("/usr/bin").to_owned(), - L!("/bin").to_owned(), - ] - }) - .into_boxed_slice(), - ) + // _CS_PATH: colon-separated paths to find POSIX utilities. Same as USER_CS_PATH. + // BSDs only have the "USER_" form, while Linux only has the "CS_" form. + #[cfg(any(apple, bsd))] + let cs_path = libc::USER_CS_PATH; + #[cfg(not(any(apple, bsd)))] + let cs_path = libc::_CS_PATH; + + let buf_size = unsafe { libc::confstr(cs_path, std::ptr::null_mut(), 0) }; + let paths: Vec = if buf_size > 0 { + let mut buf = vec![b'\0' as libc::c_char; buf_size]; + unsafe { libc::confstr(cs_path, buf.as_mut_ptr(), buf_size) }; + let buf = buf; + // safety: buf should contain a null-byte, and is not mutable unless we move ownership + let cstr = unsafe { CStr::from_ptr(buf.as_ptr()) }; + colon_split(&[str2wcstring(cstr.to_bytes())]) + } else { + vec![ + WString::from_str(env!("PREFIX")) + L!("/bin"), + WString::from_str("/usr/bin"), + WString::from_str("/bin"), + ] + }; + Box::leak(paths.into_boxed_slice()) }); /// Make sure the PATH variable contains something.