Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ pub fn posix_spawn<SA: AsRef<CStr>, SE: AsRef<CStr>>(
) -> Result<Pid> {
let mut pid = 0;

let res = unsafe {
let ret = unsafe {
let args_p = to_exec_array(args);
let env_p = to_exec_array(envp);

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

Errno::result(res)?;
if ret != 0 {
return Err(Errno::from_raw(ret));
}

Ok(Pid::from_raw(pid))
}

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

let res = unsafe {
let ret = unsafe {
let args_p = to_exec_array(args);
let env_p = to_exec_array(envp);

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

Errno::result(res)?;
if ret != 0 {
return Err(Errno::from_raw(ret));
}

Ok(Pid::from_raw(pid))
}
8 changes: 6 additions & 2 deletions test/test_spawn.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::ffi::CString;

use super::FORK_MTX;
use nix::spawn::{self, PosixSpawnAttr, PosixSpawnFileActions};
use nix::sys::signal;
use nix::sys::wait::{waitpid, WaitPidFlag, WaitStatus};
use std::ffi::CString;

#[test]
fn spawn_true() {
let _guard = FORK_MTX.lock();

let bin = &CString::new("true").unwrap();
let args = &[
CString::new("true").unwrap(),
Expand All @@ -32,6 +34,8 @@ fn spawn_true() {

#[test]
fn spawn_sleep() {
let _guard = FORK_MTX.lock();

let bin = &CString::new("sleep").unwrap();
let args = &[CString::new("sleep").unwrap(), CString::new("30").unwrap()];
let vars: &[CString] = &[];
Expand Down