add command name as first argument
This commit is contained in:
parent
8bd07cccaa
commit
32570cc3b9
|
@ -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())
|
let command_cstr = CString::new(command.as_os_str().as_encoded_bytes())
|
||||||
.context(format_args!("bad command: {}", command.display()))?;
|
.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 {
|
for arg in args {
|
||||||
let cur_arg_cstr = CString::new(arg.as_bytes()).context(format_args!("bad arg: {arg}"))?;
|
let cur_arg_cstr = CString::new(arg.as_bytes()).context(format_args!("bad arg: {arg}"))?;
|
||||||
args_cstr.push(cur_arg_cstr);
|
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()))
|
.chain(std::iter::once(std::ptr::null()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
dbg!(&command_cstr, &args_ptrs);
|
|
||||||
|
|
||||||
if unsafe { libc::execv(command_cstr.as_ptr().cast(), args_ptrs.as_ptr().cast()) } == -1 {
|
if unsafe { libc::execv(command_cstr.as_ptr().cast(), args_ptrs.as_ptr().cast()) } == -1 {
|
||||||
return ctx_os_error(format_args!(
|
return ctx_os_error(format_args!(
|
||||||
"error calling exec({command}, {args:?})",
|
"error calling exec({command}, {args:?})",
|
||||||
|
|
Loading…
Reference in New Issue