add command name as first argument

This commit is contained in:
Ryan Heywood 2025-07-12 14:46:44 -04:00
parent 8bd07cccaa
commit 32570cc3b9
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
1 changed files with 2 additions and 3 deletions

View File

@ -198,7 +198,8 @@ pub fn execv(command: impl AsRef<Path>, args: &[&str]) -> Result<()> {
let command_cstr = CString::new(command.as_os_str().as_encoded_bytes())
.context(format_args!("bad command: {}", command.display()))?;
let mut args_cstr = vec![];
// NOTE: command should be the first string, according to execve() documentation.
let mut args_cstr = vec![command_cstr.clone()];
for arg in args {
let cur_arg_cstr = CString::new(arg.as_bytes()).context(format_args!("bad arg: {arg}"))?;
args_cstr.push(cur_arg_cstr);
@ -212,8 +213,6 @@ pub fn execv(command: impl AsRef<Path>, args: &[&str]) -> Result<()> {
.chain(std::iter::once(std::ptr::null()))
.collect();
dbg!(&command_cstr, &args_ptrs);
if unsafe { libc::execv(command_cstr.as_ptr().cast(), args_ptrs.as_ptr().cast()) } == -1 {
return ctx_os_error(format_args!(
"error calling exec({command}, {args:?})",