Skip to content

Commit d6d73d2

Browse files
senamakelmedullabot
andcommitted
refactor(linux): extract landlock restrict_self into a standalone function
Move the closure that calls `restrict_self` into a named function to improve readability and reduce nesting inside the `pre_exec` call. Auto-committed-on: dragonfly Co-authored-by: Medulla <medulla@tinyhumans.ai>
1 parent 9006c64 commit d6d73d2

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

‎crates/tinybox-jail/src/linux.rs‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,7 @@ impl JailBackend for LandlockBackend {
9191

9292
// SAFETY: the child callback only applies this prebuilt ruleset.
9393
unsafe {
94-
cmd.pre_exec(move || {
95-
apply_ruleset(ruleset.take(), |ruleset| {
96-
ruleset
97-
.restrict_self()
98-
.map(|_| ())
99-
.map_err(|_| std::io::Error::from_raw_os_error(5))
100-
})
101-
});
94+
cmd.pre_exec(move || apply_ruleset(ruleset.take(), restrict_self));
10295
}
10396

10497
cmd.spawn()
@@ -122,6 +115,14 @@ fn apply_ruleset<T>(
122115
}
123116
}
124117

118+
#[cfg(feature = "landlock")]
119+
fn restrict_self(ruleset: landlock::Ruleset) -> std::io::Result<()> {
120+
ruleset
121+
.restrict_self()
122+
.map(|_| ())
123+
.map_err(|_| std::io::Error::from_raw_os_error(5))
124+
}
125+
125126
#[cfg(test)]
126127
#[path = "linux_tests.rs"]
127128
mod tests;

0 commit comments

Comments
 (0)