Skip to content

Commit 76b27ae

Browse files
committed
fix: posix_spawn returns errno when on error, not -1
1 parent c2a7b25 commit 76b27ae

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/spawn.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ pub fn posix_spawn<SA: AsRef<CStr>, SE: AsRef<CStr>>(
370370
) -> Result<Pid> {
371371
let mut pid = 0;
372372

373-
let res = unsafe {
373+
let ret = unsafe {
374374
let args_p = to_exec_array(args);
375375
let env_p = to_exec_array(envp);
376376

@@ -384,7 +384,10 @@ pub fn posix_spawn<SA: AsRef<CStr>, SE: AsRef<CStr>>(
384384
)
385385
};
386386

387-
Errno::result(res)?;
387+
if ret != 0 {
388+
return Err(Errno::from_raw(ret));
389+
}
390+
388391
Ok(Pid::from_raw(pid))
389392
}
390393

@@ -399,7 +402,7 @@ pub fn posix_spawnp<SA: AsRef<CStr>, SE: AsRef<CStr>>(
399402
) -> Result<Pid> {
400403
let mut pid = 0;
401404

402-
let res = unsafe {
405+
let ret = unsafe {
403406
let args_p = to_exec_array(args);
404407
let env_p = to_exec_array(envp);
405408

@@ -413,6 +416,9 @@ pub fn posix_spawnp<SA: AsRef<CStr>, SE: AsRef<CStr>>(
413416
)
414417
};
415418

416-
Errno::result(res)?;
419+
if ret != 0 {
420+
return Err(Errno::from_raw(ret));
421+
}
422+
417423
Ok(Pid::from_raw(pid))
418424
}

0 commit comments

Comments
 (0)