hardened_std: eliminate thread::sleep from production code#102
Merged
zvonkok merged 4 commits intoNVIDIA:mainfrom Jan 12, 2026
Merged
hardened_std: eliminate thread::sleep from production code#102zvonkok merged 4 commits intoNVIDIA:mainfrom
zvonkok merged 4 commits intoNVIDIA:mainfrom
Conversation
- Add poll_timeout() to syslog.rs using blocking poll with timeout - Update kata_agent.rs syslog_loop to use poll_timeout instead of sleep+poll - Add process::exit() to hardened_std (thin wrapper around libc::_exit) - Fix doctest in fs.rs (mark as ignore for private function) - Remove unused import in kmsg.rs This eliminates std::thread::sleep and std::time::Duration from production code, moving closer to no_std compatibility. Test code still uses std. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
NVRC is PID 1 (init) with no threads - no thread::sleep, mutexes, or thread-safe synchronization needed in production code. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes thread::sleep from production code to support no_std compatibility for NVRC's single-threaded init process. The core change replaces the sleep+poll pattern with a blocking poll syscall that has a timeout.
Changes:
- Introduces
poll_timeout()function in syslog.rs that uses blocking poll with timeout instead of sleep+poll pattern - Removes
std::thread::sleepandstd::time::Durationimports from kata_agent.rs - Adds
hardened_std::process::exit()wrapper for no_std compatibility (preparatory work)
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/syslog.rs | Adds poll_timeout() functions that use blocking poll syscall with timeout to replace sleep+poll pattern |
| src/kata_agent.rs | Removes thread::sleep usage, switches syslog_loop to use poll_timeout(500ms) instead |
| src/kmsg.rs | Removes unused AsRawFd import |
| hardened_std/src/process.rs | Adds exit() wrapper around libc::_exit() for no_std compatibility |
| hardened_std/src/fs.rs | Changes doc example to ```ignore to prevent doctest execution |
| CLAUDE.md | Documents single-threaded design principle |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Document timeout clamping in poll_timeout() docstring: values are clamped to 65535ms (~65s), negative blocks indefinitely - Add poll_socket_timeout tests verifying Ok(false) on timeout and Ok(true) when data arrives before timeout - Expand test_syslog_loop_timeout comment explaining why no minimum time assertion: /dev/log may not exist in test environments Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- test_poll_socket_timeout_negative_zero_timeout: zero timeout returns immediately - test_poll_timeout_at_custom_path: exercise poll_once_timeout via custom path - test_poll_timeout_public_api: exercise public poll_timeout() function Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
Eliminate thread::sleep from production code