* Correctly determine argv[0]
- If the function called is `posix_spawnp`, and the passed program name **does not** contain a slash, the path is used unmodified, and the path to the directory containing the program on $PATH is prepended to the program's path and assigned to `argv[0]. If the program name **does** contain a slash, the path is absolutised relative to CWD, and assigned to argv[0]
- If the function called is `posix_spawn`, the behaviour is as described above in the case where path contains a slash
* Add initial tests
This commit is contained in:
@@ -47,6 +47,7 @@ unsafe fn spawn(
|
||||
ERRNO.get()
|
||||
);
|
||||
|
||||
let mut path_path = None;
|
||||
if use_path {
|
||||
let path = unsafe { getenv(c"PATH".as_ptr()) };
|
||||
let path_env = unsafe { CStr::from_nullable_ptr(path).unwrap().to_str().unwrap() };
|
||||
@@ -70,10 +71,12 @@ unsafe fn spawn(
|
||||
CStr::from_ptr(dir_ent.d_name.as_ptr() as *const c_char)
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
};
|
||||
if dir_ent_name == program {
|
||||
flag = true;
|
||||
program = format!("{}/{}", path_element, program);
|
||||
path_path = Some(path_element.to_string());
|
||||
break 'a;
|
||||
}
|
||||
}
|
||||
@@ -93,7 +96,7 @@ unsafe fn spawn(
|
||||
spawn_attr,
|
||||
argv,
|
||||
envp,
|
||||
use_path,
|
||||
path_path,
|
||||
)
|
||||
.map(|v| {
|
||||
if let Some(pid) = pid {
|
||||
|
||||
Reference in New Issue
Block a user