Function execveat
pub unsafe fn execveat<P>(
fd: i32,
filename: P,
argv: &[P],
env: &[P],
flags: i32,
) -> Result<(), i32> ⓘ
Available on crate feature
dep_nc
only.Expand description
Execute a new program relative to a directory file descriptor.
§Examples
Specify program file via filename
:
let args = ["ls", "-l", "-a"];
let env = ["DISPLAY=:0"];
let ret = unsafe { nc::execveat(nc::AT_FDCWD, "/bin/ls", &args, &env, 0) };
assert!(ret.is_ok());
Or via an opened file descriptor fd
, leaving filename
empty:
let args = ["ls", "-l", "-a"];
let env = ["DISPLAY=:0"];
let ret = unsafe { nc::openat(nc::AT_FDCWD, "/bin/ls", nc::O_RDONLY | nc::O_CLOEXEC, 0) };
assert!(ret.is_ok());
let fd = ret.unwrap();
let ret = unsafe { nc::execveat(fd, "", &args, &env, nc::AT_EMPTY_PATH) };
assert!(ret.is_ok());