Repository navigation
Use libc's exit as the sandbox's SIGTERM handler - #28
Merged
Merged
Conversation
anoek
force-pushed
the
fix-sigterm-handler
branch
from
October 31, 2026 13:31
b4cc02d to
2c7c994
Compare
The sandbox's PID 1 registered std::process::exit as its SIGTERM handler by casting it to sighandler_t, which rustc now warns about (function_casts_as_integer). Beyond the warning, std::process::exit uses the Rust calling convention while signal handlers are called with the C one; it only worked because the two agree for a single integer argument on the architectures we build for. libc::exit has the C calling convention and does the same thing here (stdout and stderr are already closed), so register it instead, through a typed function pointer. Also add a test that SIGTERM stops a sandbox, which nothing tested.
anoek
force-pushed
the
fix-sigterm-handler
branch
from
October 31, 2026 14:14
2c7c994 to
f48ceda
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #26. This doesn't depend on the rest of the stack; it's here so it can land alongside it.
Fixes this warning:
The compiler's suggested fix (
as *const () as libc::sighandler_t) would only silence it. The underlying problem is thatstd::process::exituses the Rust calling convention, while the kernel calls signal handlers with the C one. It only worked because the two agree for a single integer argument on x86_64 and aarch64.The sandbox's PID 1 now registers
libc::exitinstead, through a typed function pointer:The behavior doesn't change: SIGTERM exits PID 1 with status 15, and
exit()still runs exit handlers.std::process::exitonly adds flushing stdout, which is already closed at this point.Why not a separate handler function
A Rust
extern "C" fnhandler that callsstd::process::exitalso works, but its body would always show as uncovered. In coverage builds, PID 1 dumps its profile early in its sleep loop, and LLVM ignores any later writes.#[coverage(off)]is still unstable.Testing
tests/ai_test_sigterm.rschecks that SIGTERM stops a sandbox's PID 1 and that the sandbox starts again afterwards. No existing test sent SIGTERM.main, the fullmake testrun passes: 285 passed, 0 failed. Every changed line is covered.ai_test_sigterm,ai_test_resource_limits,test_sandbox_inceptionandtest_mount_unmount_killpass, and the build has no warnings.