Skip to content

Commit 0ec23ad

Browse files
committed
fix: do not build debug a default seccomp policy in debug binaries
Rust 1.80.0 added a debug assertion that uses fcntl(F_GETFD) to ensure the fd is still valid when it gets dropped, which broke debug builds of firecracker. This made us rethink on whether we'd want any default seccomp policy in debug builds, and we decided that in most cases we don't need them and in some cases they get in the way of prororyping and debugging. This patch changes the default seccomp policy in debug builds to empty. Signed-off-by: Riccardo Mancini <[email protected]>
1 parent a8f38cb commit 0ec23ad

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/firecracker/build.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,34 @@ const SECCOMPILER_SRC_DIR: &str = "../seccompiler/src";
1414
fn main() {
1515
// Target triple
1616
let target = std::env::var("TARGET").expect("Missing target.");
17+
let debug: bool = std::env::var("DEBUG")
18+
.expect("Missing debug.")
19+
.parse()
20+
.expect("Invalid env variable DEBUG");
1721
let out_dir = std::env::var("OUT_DIR").expect("Missing build-level OUT_DIR.");
1822
// Target arch (x86_64 / aarch64)
1923
let target_arch = std::env::var("CARGO_CFG_TARGET_ARCH").expect("Missing target arch.");
2024

2125
let seccomp_json_path = format!("{}/{}.json", JSON_DIR, target);
22-
// If the current target doesn't have a default filter, use a default, empty filter.
26+
// If the current target doesn't have a default filter, or if we're building a debug binary,
27+
// use a default, empty filter.
2328
// This is to make sure that Firecracker builds even with libc toolchains for which we don't
2429
// provide a default filter. For example, GNU libc.
25-
let seccomp_json_path = if Path::new(&seccomp_json_path).exists() {
26-
seccomp_json_path
27-
} else {
30+
let seccomp_json_path = if debug {
31+
println!(
32+
"cargo:warning=Using empty default seccomp policy for debug builds: \
33+
`resources/seccomp/unimplemented.json`."
34+
);
35+
format!("{}/unimplemented.json", JSON_DIR)
36+
} else if !Path::new(&seccomp_json_path).exists() {
2837
println!(
2938
"cargo:warning=No default seccomp policy for target: {}. Defaulting to \
3039
`resources/seccomp/unimplemented.json`.",
3140
target
3241
);
3342
format!("{}/unimplemented.json", JSON_DIR)
43+
} else {
44+
seccomp_json_path
3445
};
3546

3647
// Retrigger the build script if the JSON file has changed.

0 commit comments

Comments
 (0)