feat: add MethodCall::push_fd() for passing file descriptors (SCM_RIGHTS)#149
Open
lsjostro wants to merge 1 commit into
Open
feat: add MethodCall::push_fd() for passing file descriptors (SCM_RIGHTS)#149lsjostro wants to merge 1 commit into
lsjostro wants to merge 1 commit into
Conversation
…HTS) Varlink allows a method call to carry file descriptors as ancillary data (SCM_RIGHTS), referenced from the parameters by push order. The client side had no way to attach them. Add MethodCall::push_fd(fd) (unix only): it dups the fd (F_DUPFD_CLOEXEC, so the caller keeps ownership), queues it, and returns its push-order index. send() then delivers the queued fds with the request via a single sendmsg()/SCM_RIGHTS on the connection's socket (any tail past the first sendmsg is written normally). Only socket-backed connections (Connection::with_address) support this; a reader/writer-pair connection has no socket and push_fd() returns an Unsupported error. This is send-only; receiving fds is not implemented. Tested in varlink/src/test.rs: push_fd() over a socketpair, recvmsg() on the peer confirming the descriptor arrives and refers to the same underlying pipe, plus the Unsupported case for non-socket connections.
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.
Varlink lets a method call carry file descriptors as ancillary data (SCM_RIGHTS),
referenced from the parameters by push order — but this crate had no client-side
way to attach them. This adds that.
API
MethodCall::push_fd(fd) -> io::Result<usize>(unix only). Dups the fd withF_DUPFD_CLOEXEC(caller keeps ownership of the original), queues it, andreturns its push-order index.
sendmsg()+SCM_RIGHTSon the connection's socket; any bytes past the firstsendmsgare written normally through the existing writer.Connection::with_address) support this; areader/writer-pair connection has no socket for ancillary data, so
push_fdreturns
io::ErrorKind::Unsupported.Passing descriptors is part of the Varlink protocol; this lets a client talk to
services that accept them (e.g. handing over stdio fds).
Scope
Send-only. Receiving descriptors (server → client) is not implemented — it would
require recvmsg-based reading throughout the input path, and nothing needs it yet.
cfg(unix)only, matching the crate's existing platform split;libcis alreadya unix dependency.
Tests
varlink/src/test.rs:test_push_fd_passes_descriptor: push an fd over one end of a socketpair,recvmsg()the other end, and confirm the descriptor arrives and refers to thesame underlying pipe (write through the received fd, read it back).
test_push_fd_requires_socket:push_fdon a non-socket connection returnsUnsupported.cargo test -p varlinkpasses.