@@ -593,6 +593,35 @@ 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(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/fexecve.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
+ /// This function is similar to `execve`, except that the program to be executed
605
+ /// is referenced as a file descriptor instead of a path.
606
+ ///
607
+ /// # Errors
608
+ ///
609
+ /// If an error occurs, this function will return with an indication of the
610
+ /// cause of failure. See
611
+ /// [fexecve(2)#errors](http://pubs.opengroup.org/onlinepubs/9699919799/functions/fexecve.html#tag_16_111_05)
612
+ /// for a list of error conditions.
613
+ #[ inline]
614
+ pub fn fexecve ( fd : RawFd , args : & [ CString ] , env : & [ CString ] ) -> Result < Void > {
615
+ let args_p = to_exec_array ( args) ;
616
+ let env_p = to_exec_array ( env) ;
617
+
618
+ unsafe {
619
+ libc:: fexecve ( fd, args_p. as_ptr ( ) , env_p. as_ptr ( ) )
620
+ } ;
621
+
622
+ Err ( Error :: Sys ( Errno :: last ( ) ) )
623
+ }
624
+
596
625
/// Daemonize this process by detaching from the controlling terminal (see
597
626
/// [daemon(3)](http://man7.org/linux/man-pages/man3/daemon.3.html)).
598
627
///
0 commit comments