Skip to content

Commit

Permalink
Merge #975
Browse files Browse the repository at this point in the history
975: Add execvpe support, conditional on platform r=asomers a=F1rst-Unicorn

This closes #682 

Co-authored-by: F1rst-Unicorn <f1rst_unicorn@njsm.de>
  • Loading branch information
bors[bot] and F1rst-Unicorn committed Nov 23, 2018
2 parents 3f9548a + 35c0d63 commit 6920394
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
([#952](https://github.com/nix-rust/nix/pull/952))
- Added the `time_t` and `suseconds_t` public aliases within `sys::time`.
([#968](https://github.com/nix-rust/nix/pull/968))
- Added `unistd::execvpe` for Haiku, Linux and OpenBSD
([#975](https://github.com/nix-rust/nix/pull/975))

### Changed
- Increased required Rust version to 1.24.1
Expand Down
21 changes: 21 additions & 0 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,27 @@ pub fn execvp(filename: &CString, args: &[CString]) -> Result<Void> {
Err(Error::Sys(Errno::last()))
}

/// Replace the current process image with a new one and replicate shell `PATH`
/// searching behavior (see
/// [`execvpe(3)`](http://man7.org/linux/man-pages/man3/exec.3.html)).
///
/// This functions like a combination of `execvp(2)` and `execve(2)` to pass an
/// environment and have a search path. See these two for additional
/// information.
#[cfg(any(target_os = "haiku",
target_os = "linux",
target_os = "openbsd"))]
pub fn execvpe(filename: &CString, args: &[CString], env: &[CString]) -> Result<Void> {
let args_p = to_exec_array(args);
let env_p = to_exec_array(env);

unsafe {
libc::execvpe(filename.as_ptr(), args_p.as_ptr(), env_p.as_ptr())
};

Err(Error::Sys(Errno::last()))
}

/// Replace the current process image with a new one (see
/// [fexecve(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/fexecve.html)).
///
Expand Down
3 changes: 3 additions & 0 deletions test/test_unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ cfg_if!{
}
}

#[cfg(any(target_os = "haiku", target_os = "linux", target_os = "openbsd"))]
execve_test_factory!(test_execvpe, execvpe, &CString::new("sh").unwrap());

cfg_if!{
if #[cfg(target_os = "android")] {
use nix::fcntl::AtFlags;
Expand Down

0 comments on commit 6920394

Please sign in to comment.