pub fn setup() {
unsafe { imp::setup() }
}
#[cfg(unix)]
mod imp {
use std::env;
use libc;
pub unsafe fn setup() {
if env::var("__CARGO_TEST_SETSID_PLEASE_DONT_USE_ELSEWHERE").is_ok() {
libc::setsid();
}
}
}
#[cfg(windows)]
mod imp {
extern crate kernel32;
extern crate winapi;
use std::mem;
pub unsafe fn setup() {
let job = kernel32::CreateJobObjectW(0 as *mut _, 0 as *const _);
if job.is_null() {
return
}
let mut info: winapi::JOBOBJECT_EXTENDED_LIMIT_INFORMATION;
info = mem::zeroed();
info.BasicLimitInformation.LimitFlags =
winapi::JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
let r = kernel32::SetInformationJobObject(job,
winapi::JobObjectExtendedLimitInformation,
&mut info as *mut _ as winapi::LPVOID,
mem::size_of_val(&info) as winapi::DWORD);
if r == 0 {
kernel32::CloseHandle(job);
return
}
let me = kernel32::GetCurrentProcess();
let r = kernel32::AssignProcessToJobObject(job, me);
if r == 0 {
kernel32::CloseHandle(job);
return
}
}
}