Skip to content

Commit c270fd2

Browse files
committed
unistd: add docs for exec* functions
Signed-off-by: Paul Osborne <osbpau@gmail.com>
1 parent ff4484d commit c270fd2

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/unistd.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,12 @@ fn to_exec_array(args: &[CString]) -> Vec<*const c_char> {
344344
args_p
345345
}
346346

347+
/// Replace the current process image with a new one (see
348+
/// [exec(3)](http://man7.org/linux/man-pages/man3/exec.3.html)).
349+
///
350+
/// See the `::nix::unistd::execve` system call for additional details. `execv`
351+
/// performs the same action but does not allow for customization of the
352+
/// environment for the new process.
347353
#[inline]
348354
pub fn execv(path: &CString, argv: &[CString]) -> Result<Void> {
349355
let args_p = to_exec_array(argv);
@@ -355,6 +361,24 @@ pub fn execv(path: &CString, argv: &[CString]) -> Result<Void> {
355361
Err(Error::Sys(Errno::last()))
356362
}
357363

364+
365+
/// Replace the current process image with a new one (see
366+
/// [execve(2)](http://man7.org/linux/man-pages/man2/execve.2.html)).
367+
///
368+
/// The execve system call allows for another process to be "called" which will
369+
/// replace the current process image. That is, this process becomes the new
370+
/// command that is run. On success, this function will not return. Instead,
371+
/// the new program will run until it exits.
372+
///
373+
/// If an error occurs, this function will return with an indication of the
374+
/// cause of failure. See
375+
/// [execve(2)#errors](http://man7.org/linux/man-pages/man2/execve.2.html#ERRORS)
376+
/// for a list of potential problems that maight cause execv to fail.
377+
///
378+
/// Both `::nix::unistd::execv` and `::nix::unistd::execve` take as arguments a
379+
/// slice of `::std::ffi::CString`s for `args` and `env`. Each element in
380+
/// the `args` list is an argument to the new process. Each element in the
381+
/// `env` list should be a string in the form "key=value".
358382
#[inline]
359383
pub fn execve(path: &CString, args: &[CString], env: &[CString]) -> Result<Void> {
360384
let args_p = to_exec_array(args);
@@ -367,6 +391,15 @@ pub fn execve(path: &CString, args: &[CString], env: &[CString]) -> Result<Void>
367391
Err(Error::Sys(Errno::last()))
368392
}
369393

394+
/// Replace the current process image with a new one and replicate shell `PATH`
395+
/// searching behavior (see
396+
/// [exec(3)](http://man7.org/linux/man-pages/man3/exec.3.html)).
397+
///
398+
/// See `::nix::unistd::execve` for additoinal details. `execvp` behaves the
399+
/// sme as execv except that it will examine the `PATH` environment variables
400+
/// for file names not specified with a leading slash. For example, `execv`
401+
/// would not work if I specified "bash" for the path argument, but `execvp`
402+
/// would assuming that I had a bash executable on my `PATH`.
370403
#[inline]
371404
pub fn execvp(filename: &CString, args: &[CString]) -> Result<Void> {
372405
let args_p = to_exec_array(args);

0 commit comments

Comments
 (0)