Skip to content

Commit e9883c4

Browse files
committed
style(cli/job): fix unsafe-op-in-unsafe-fn
1 parent 90f4482 commit e9883c4

File tree

1 file changed

+41
-39
lines changed

1 file changed

+41
-39
lines changed

src/cli/job.rs

+41-39
Original file line numberDiff line numberDiff line change
@@ -58,47 +58,49 @@ mod imp {
5858
}
5959

6060
pub(crate) unsafe fn setup() -> Option<Setup> {
61-
// Creates a new job object for us to use and then adds ourselves to it.
62-
// Note that all errors are basically ignored in this function,
63-
// intentionally. Job objects are "relatively new" in Windows,
64-
// particularly the ability to support nested job objects. Older
65-
// Windows installs don't support this ability. We probably don't want
66-
// to force Cargo to abort in this situation or force others to *not*
67-
// use job objects, so we instead just ignore errors and assume that
68-
// we're otherwise part of someone else's job object in this case.
69-
70-
let job = CreateJobObjectW(ptr::null_mut(), ptr::null());
71-
if job.is_null() {
72-
return None;
73-
}
74-
let job = Handle { inner: job };
75-
76-
// Indicate that when all handles to the job object are gone that all
77-
// process in the object should be killed. Note that this includes our
78-
// entire process tree by default because we've added ourselves and
79-
// our children will reside in the job once we spawn a process.
80-
let mut info: JOBOBJECT_EXTENDED_LIMIT_INFORMATION;
81-
info = mem::zeroed();
82-
info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
83-
let r = SetInformationJobObject(
84-
job.inner,
85-
JobObjectExtendedLimitInformation,
86-
&mut info as *mut _ as *const std::ffi::c_void,
87-
mem::size_of_val(&info) as u32,
88-
);
89-
if r == 0 {
90-
return None;
91-
}
61+
unsafe {
62+
// Creates a new job object for us to use and then adds ourselves to it.
63+
// Note that all errors are basically ignored in this function,
64+
// intentionally. Job objects are "relatively new" in Windows,
65+
// particularly the ability to support nested job objects. Older
66+
// Windows installs don't support this ability. We probably don't want
67+
// to force Cargo to abort in this situation or force others to *not*
68+
// use job objects, so we instead just ignore errors and assume that
69+
// we're otherwise part of someone else's job object in this case.
70+
71+
let job = CreateJobObjectW(ptr::null_mut(), ptr::null());
72+
if job.is_null() {
73+
return None;
74+
}
75+
let job = Handle { inner: job };
76+
77+
// Indicate that when all handles to the job object are gone that all
78+
// process in the object should be killed. Note that this includes our
79+
// entire process tree by default because we've added ourselves and
80+
// our children will reside in the job once we spawn a process.
81+
let mut info: JOBOBJECT_EXTENDED_LIMIT_INFORMATION;
82+
info = mem::zeroed();
83+
info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
84+
let r = SetInformationJobObject(
85+
job.inner,
86+
JobObjectExtendedLimitInformation,
87+
&mut info as *mut _ as *const std::ffi::c_void,
88+
mem::size_of_val(&info) as u32,
89+
);
90+
if r == 0 {
91+
return None;
92+
}
9293

93-
// Assign our process to this job object, meaning that our children will
94-
// now live or die based on our existence.
95-
let me = GetCurrentProcess();
96-
let r = AssignProcessToJobObject(job.inner, me);
97-
if r == 0 {
98-
return None;
99-
}
94+
// Assign our process to this job object, meaning that our children will
95+
// now live or die based on our existence.
96+
let me = GetCurrentProcess();
97+
let r = AssignProcessToJobObject(job.inner, me);
98+
if r == 0 {
99+
return None;
100+
}
100101

101-
Some(Setup { job })
102+
Some(Setup { job })
103+
}
102104
}
103105

104106
impl Drop for Setup {

0 commit comments

Comments
 (0)