execle takes a variable number of parameters: file, each program arg0 through argN, NULL ending arguments, then the environment -- and that needs to be an array of c-strings also terminated by NULL.
env has to be a pointer to an array of pointers. First create an array of pointers, then pass a pointer to it:
let shell = CString::new("/bin/bash").unwrap();
let term = CString::new("TERM=dumb").unwrap();
let env = [term.as_ptr(), ptr::null()]; // null-terminated array
libc::execle(shell.as_ptr(), ptr::null(), env.as_ptr())
Still doesn't work.
Tried this code (yours but with an argument)
let shell = CString::new("/bin/bash").unwrap();
let arg0 = shell.clone();
let term = CString::new("TERM=dumb").unwrap();
let args = [arg0.as_ptr(), ptr::null()];
let env = [term.as_ptr(), ptr::null()];
if libc::execle(shell.as_ptr(), args.as_ptr() as *const i8, env.as_ptr()) == -1 {
println!("ERROR execle() ({})", errno::errno());
}
And this (a copy of yours)
let shell = CString::new("/bin/bash").unwrap();
let term = CString::new("TERM=dumb").unwrap();
let env = [term.as_ptr(), ptr::null()];
if libc::execle(shell.as_ptr(), ptr::null(), env.as_ptr()) == -1 {
println!("ERROR execle() ({})", errno::errno());
}
let shell = CString::new("/bin/bash").unwrap();
let arg0 = shell.clone();
let term = CString::new("TERM=dumb").unwrap();
let env = [term.as_ptr(), ptr::null()];
if libc::execle(shell.as_ptr(), arg0.as_ptr(), ptr::null() as *const c_void, env.as_ptr()) == -1 {
println!("ERROR execle() ({})", errno::errno());
}