Skip to content

Commit e860b9d

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

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/uu/stdbuf/src/stdbuf.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use clap::{Arg, ArgAction, ArgMatches, Command};
99
use std::ffi::OsString;
1010
#[cfg(unix)]
1111
use std::os::unix::process::CommandExt;
12-
use std::path::PathBuf;
12+
use std::path::{Path, PathBuf};
1313
use std::process;
1414
use tempfile::TempDir;
1515
use tempfile::tempdir;
@@ -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(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)