refactor(libcgroups): store DbusConnection socket as OwnedFd - #3630
Open
tkshsbcue wants to merge 3 commits into
Open
refactor(libcgroups): store DbusConnection socket as OwnedFd#3630tkshsbcue wants to merge 3 commits into
tkshsbcue wants to merge 3 commits into
Conversation
DbusConnection held its socket as a bare RawFd: connect() created the fd as a ManuallyDrop<OwnedFd> and then stored socket.as_raw_fd(). Because the OwnedFd was wrapped in ManuallyDrop and there was no Drop impl to close it, the socket fd was effectively leaked for the lifetime of the process. Store the socket as an OwnedFd instead. Ownership and lifetime are now explicit and compiler-enforced, the fd is closed automatically when the connection is dropped, and the ManuallyDrop dance in new() is gone. The nix socket calls still take a RawFd, so they now pass self.socket.as_raw_fd(); behaviour is otherwise unchanged. Closes youki-dev#3629 Signed-off-by: tkshsbcue <kumar.tanay@somaiya.edu>
Contributor
|
@tkshsbcue |
Contributor
Author
|
hey @nayuta723 just did that hope you can have a look |
Member
|
Please make sure the CI checks pass. |
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.
Description
Follow-up to the review note in #3557 (#3557 (comment)).
DbusConnectionstored its socket as a bareRawFd(socket: i32). The fd wascreated in
new()as aManuallyDrop<OwnedFd>and then only the raw fd(
socket.as_raw_fd()) was kept. Since theOwnedFdwas wrapped inManuallyDropand there is no
Dropimpl onDbusConnection, the socket fd was never closed —it leaked for the lifetime of the process.
This PR replaces the field with an owned
OwnedFd:ManuallyDropinnew()is no longer neededThe
nix::sys::socketcalls (send/recv/sendmsg/recvmsg/connect) still take aRawFd, so they now passself.socket.as_raw_fd(). There is no behavioural change tothe dbus protocol handling.
Type of Change
Testing
The existing
#[cfg(feature = "systemd")]dbus tests indbus.rs(
test_dbus_connection_auth,test_dbus_function_calls, …) exercise this pathunchanged.
cargo +nightly fmtis clean.Related Issues
Closes #3629