amd_s2idle: fix fchown called on closed file descriptor#43
Merged
Conversation
os.fchown(fd, ...) was called after the `with os.fdopen(fd, ...)` block exited, at which point fd is already closed. This caused OSError (Bad file descriptor) when SUDO_UID/SUDO_GID were set. Move the fchown call inside the with block so fd is still valid. Add test_build_template_fchown_called_while_fd_open to verify fchown is invoked with the correct uid/gid while the fd is open.
Copilot created this pull request from a session on behalf of
superm1
May 28, 2026 15:31
View session
superm1
approved these changes
May 28, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #43 +/- ##
==========================================
+ Coverage 85.19% 85.33% +0.14%
==========================================
Files 36 36
Lines 8119 8136 +17
Branches 766 767 +1
==========================================
+ Hits 6917 6943 +26
+ Misses 980 971 -9
Partials 222 222 ☔ View full report in Codecov by Sentry. |
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.
os.fchownwas called after thewith os.fdopen(fd, ...)block exited, at which pointfdis already closed — raisingOSError: [Errno 9] Bad file descriptorwheneverSUDO_UID/SUDO_GIDwere set and a report filename was provided.Changes
src/amd_debug/sleep_report.py— Movefchowncall inside thewith os.fdopen(...)block sofdremains valid:src/test_sleep_report.py— Addtest_build_template_fchown_called_while_fd_open: setsSUDO_UID/SUDO_GID, callsbuild_templatewith a real temp path, and assertsfchownis invoked with the correct uid/gid.