@@ -593,6 +593,33 @@ pub fn execvp(filename: &CString, args: &[CString]) -> Result<Void> {
593
593
Err ( Error :: Sys ( Errno :: last ( ) ) )
594
594
}
595
595
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
+
596
623
/// Daemonize this process by detaching from the controlling terminal (see
597
624
/// [daemon(3)](http://man7.org/linux/man-pages/man3/daemon.3.html)).
598
625
///
0 commit comments