Skip to content

Commit

Permalink
unistd: add fexecve()
Browse files Browse the repository at this point in the history
This adds fexecve(3). It is available in libc since 0.2.29.

Ref: http://pubs.opengroup.org/onlinepubs/9699919799/functions/fexecve.html
  • Loading branch information
lucab committed Aug 9, 2017
1 parent 087aece commit ee9b289
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,33 @@ pub fn execvp(filename: &CString, args: &[CString]) -> Result<Void> {
Err(Error::Sys(Errno::last()))
}

/// Replace the current process image with a new one (see
/// [fexecve(3)](http://man7.org/linux/man-pages/man3/fexecve.3.html)).
///
/// The `fexecve` function allows for another process to be "called" which will
/// replace the current process image. That is, this process becomes the new
/// command that is run. On success, this function will not return. Instead,
/// the new program will run until it exits.
///
/// If an error occurs, this function will return with an indication of the
/// cause of failure. See
/// [fexecve(3)#errors](http://man7.org/linux/man-pages/man3/fexecve.3.html#ERRORS)
/// for a list of potential problems that maight cause execv to fail.
///
/// This function is similar to `execve`, except that the program to be executed
/// is referenced as a file descriptor instead of a path.
#[inline]
pub fn fexecve(fd: RawFd, args: &[CString], env: &[CString]) -> Result<Void> {
let args_p = to_exec_array(args);
let env_p = to_exec_array(env);

unsafe {
libc::fexecve(fd, args_p.as_ptr(), env_p.as_ptr())
};

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

/// Daemonize this process by detaching from the controlling terminal (see
/// [daemon(3)](http://man7.org/linux/man-pages/man3/daemon.3.html)).
///
Expand Down

0 comments on commit ee9b289

Please sign in to comment.