Skip to content

Commit 6920394

Browse files
Merge #975
975: Add execvpe support, conditional on platform r=asomers a=F1rst-Unicorn This closes #682 Co-authored-by: F1rst-Unicorn <[email protected]>
2 parents 3f9548a + 35c0d63 commit 6920394

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
3636
([#952](https://github.com/nix-rust/nix/pull/952))
3737
- Added the `time_t` and `suseconds_t` public aliases within `sys::time`.
3838
([#968](https://github.com/nix-rust/nix/pull/968))
39+
- Added `unistd::execvpe` for Haiku, Linux and OpenBSD
40+
([#975](https://github.com/nix-rust/nix/pull/975))
3941

4042
### Changed
4143
- Increased required Rust version to 1.24.1

src/unistd.rs

+21
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,27 @@ pub fn execvp(filename: &CString, args: &[CString]) -> Result<Void> {
701701
Err(Error::Sys(Errno::last()))
702702
}
703703

704+
/// Replace the current process image with a new one and replicate shell `PATH`
705+
/// searching behavior (see
706+
/// [`execvpe(3)`](http://man7.org/linux/man-pages/man3/exec.3.html)).
707+
///
708+
/// This functions like a combination of `execvp(2)` and `execve(2)` to pass an
709+
/// environment and have a search path. See these two for additional
710+
/// information.
711+
#[cfg(any(target_os = "haiku",
712+
target_os = "linux",
713+
target_os = "openbsd"))]
714+
pub fn execvpe(filename: &CString, args: &[CString], env: &[CString]) -> Result<Void> {
715+
let args_p = to_exec_array(args);
716+
let env_p = to_exec_array(env);
717+
718+
unsafe {
719+
libc::execvpe(filename.as_ptr(), args_p.as_ptr(), env_p.as_ptr())
720+
};
721+
722+
Err(Error::Sys(Errno::last()))
723+
}
724+
704725
/// Replace the current process image with a new one (see
705726
/// [fexecve(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/fexecve.html)).
706727
///

test/test_unistd.rs

+3
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ cfg_if!{
243243
}
244244
}
245245

246+
#[cfg(any(target_os = "haiku", target_os = "linux", target_os = "openbsd"))]
247+
execve_test_factory!(test_execvpe, execvpe, &CString::new("sh").unwrap());
248+
246249
cfg_if!{
247250
if #[cfg(target_os = "android")] {
248251
use nix::fcntl::AtFlags;

0 commit comments

Comments
 (0)