Skip to content

Commit 1b0181b

Browse files
committed
stdbuf: Search libstdbuf without /proc
1 parent bed3108 commit 1b0181b

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/uu/stdbuf/src/stdbuf.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,15 @@ fn get_preload_env(_tmp_dir: &TempDir) -> UResult<(String, PathBuf)> {
183183
// Search paths in order:
184184
// 1. Directory where stdbuf is located (program_path)
185185
// 2. Compile-time directory from LIBSTDBUF_DIR
186-
let mut search_paths: Vec<PathBuf> = Vec::new();
186+
let mut search_paths: Vec<PathBuf> = Vec::with_capacity(2);
187187

188188
// First, try to get the directory where stdbuf is running from
189-
if let Ok(exe_path) = std::env::current_exe() {
190-
if let Some(exe_dir) = exe_path.parent() {
191-
search_paths.push(exe_dir.to_path_buf());
192-
}
189+
// use argv[0] to support masked /proc
190+
if let Some(exe_dir) = std::env::args_os()
191+
.next()
192+
.and_then(|a| PathBuf::from(a).parent().map(std::path::Path::to_path_buf))
193+
{
194+
search_paths.push(exe_dir);
193195
}
194196

195197
// Add the compile-time directory as fallback

0 commit comments

Comments
 (0)