Skip to content

Commit 6ddf9a0

Browse files
committed
Reduce size of unsafe blocks to the required minimum
1 parent fa9e597 commit 6ddf9a0

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
lines changed

crates/container/src/lib.rs

+21-27
Original file line numberDiff line numberDiff line change
@@ -124,33 +124,27 @@ impl Container {
124124
}
125125

126126
let sync_raw = (sync_r.as_raw_fd(), sync_w.as_raw_fd());
127-
let pid = unsafe {
128-
clone(
129-
Box::new(|| match enter(&self, sync_raw, &mut f) {
130-
Ok(_) => 0,
131-
// Write error back to parent process
132-
Err(error) => {
133-
let error = format_error(error);
134-
let mut pos = 0;
135-
136-
while pos < error.len() {
137-
let Ok(len) = write(&sync_w, &error.as_bytes()[pos..]) else {
138-
break;
139-
};
140-
141-
pos += len;
142-
}
143-
144-
_ = close(sync_w.as_raw_fd());
145-
146-
1
147-
}
148-
}),
149-
&mut *addr_of_mut!(STACK),
150-
flags,
151-
Some(SIGCHLD),
152-
)?
153-
};
127+
let clone_cb = Box::new(|| match enter(&self, sync_raw, &mut f) {
128+
Ok(_) => 0,
129+
// Write error back to parent process
130+
Err(error) => {
131+
let error = format_error(error);
132+
let mut pos = 0;
133+
134+
while pos < error.len() {
135+
let Ok(len) = write(&sync_w, &error.as_bytes()[pos..]) else {
136+
break;
137+
};
138+
139+
pos += len;
140+
}
141+
142+
_ = close(sync_w.as_raw_fd());
143+
144+
1
145+
}
146+
});
147+
let pid = unsafe { clone(clone_cb, &mut *addr_of_mut!(STACK), flags, Some(SIGCHLD))? };
154148

155149
// Update uid / gid map to map current user to root in container
156150
if rootless {

moss/src/signal.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ pub fn ignore(signals: impl IntoIterator<Item = Signal>) -> Result<Guard, Error>
1515
Ok(Guard(
1616
signals
1717
.into_iter()
18-
.map(|signal| unsafe {
19-
let action = sigaction(
20-
signal,
21-
&SigAction::new(SigHandler::SigIgn, SaFlags::empty(), SigSet::empty()),
22-
)
18+
.map(|signal| {
19+
let action = unsafe {
20+
sigaction(
21+
signal,
22+
&SigAction::new(SigHandler::SigIgn, SaFlags::empty(), SigSet::empty()),
23+
)
24+
}
2325
.map_err(Error::Ignore)?;
2426

2527
Ok(PrevHandler { signal, action })

0 commit comments

Comments
 (0)