Skip to content

Commit ee9b289

Browse files
committed
unistd: add fexecve()
This adds fexecve(3). It is available in libc since 0.2.29. Ref: http://pubs.opengroup.org/onlinepubs/9699919799/functions/fexecve.html
1 parent 087aece commit ee9b289

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/unistd.rs

+27
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,33 @@ pub fn execvp(filename: &CString, args: &[CString]) -> Result<Void> {
593593
Err(Error::Sys(Errno::last()))
594594
}
595595

596+
/// Replace the current process image with a new one (see
597+
/// [fexecve(3)](http://man7.org/linux/man-pages/man3/fexecve.3.html)).
598+
///
599+
/// The `fexecve` function allows for another process to be "called" which will
600+
/// replace the current process image. That is, this process becomes the new
601+
/// command that is run. On success, this function will not return. Instead,
602+
/// the new program will run until it exits.
603+
///
604+
/// If an error occurs, this function will return with an indication of the
605+
/// cause of failure. See
606+
/// [fexecve(3)#errors](http://man7.org/linux/man-pages/man3/fexecve.3.html#ERRORS)
607+
/// for a list of potential problems that maight cause execv to fail.
608+
///
609+
/// This function is similar to `execve`, except that the program to be executed
610+
/// is referenced as a file descriptor instead of a path.
611+
#[inline]
612+
pub fn fexecve(fd: RawFd, args: &[CString], env: &[CString]) -> Result<Void> {
613+
let args_p = to_exec_array(args);
614+
let env_p = to_exec_array(env);
615+
616+
unsafe {
617+
libc::fexecve(fd, args_p.as_ptr(), env_p.as_ptr())
618+
};
619+
620+
Err(Error::Sys(Errno::last()))
621+
}
622+
596623
/// Daemonize this process by detaching from the controlling terminal (see
597624
/// [daemon(3)](http://man7.org/linux/man-pages/man3/daemon.3.html)).
598625
///

0 commit comments

Comments
 (0)