-
Notifications
You must be signed in to change notification settings - Fork 683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passing multiple FD over an Unix Socket in a single Control Message doesn't work #464
Comments
Similarly, sending multiple control messages doesn't seem to work either. The following code panics at runtime on the extern crate nix;
use std::os::unix::net::UnixDatagram;
use std::os::unix::io::{RawFd, AsRawFd};
use nix::sys::socket::{CmsgSpace, ControlMessage, MsgFlags, sendmsg, recvmsg};
use nix::sys::uio::IoVec;
fn main() {
let (send, receive) = UnixDatagram::pair().unwrap();
let thread = std::thread::spawn(move || {
let mut buf = [0u8; 8];
let iovec = [IoVec::from_mut_slice(&mut buf)];
let mut space = CmsgSpace::<([RawFd; 1], CmsgSpace<[RawFd; 1]>)>::new();
let (paneid, fds) = match recvmsg(receive.as_raw_fd(), &iovec, Some(&mut space), MsgFlags::empty()) {
Ok(msg) => {
let mut iter = msg.cmsgs();
let fdone;
let fdtwo;
if let Some(ControlMessage::ScmRights(fds)) = iter.next() {
fdone = fds[0];
} else {
panic!();
}
if let Some(ControlMessage::ScmRights(fds)) = iter.next() {
fdtwo = fds[0];
} else {
panic!();
}
(iovec[0].as_slice(), [fdone, fdtwo])
},
Err(_) => {
panic!();
}
};
println!("paneid = {:?}, fds = {:?}", paneid, fds);
});
let slice = [1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u8];
let iov = [IoVec::from_slice(&slice)];
let arrone = [0];
let arrtwo = [1]; // pass stdin and stdout
let cmsg = [ControlMessage::ScmRights(&arrone), ControlMessage::ScmRights(&arrtwo)];
sendmsg(send.as_raw_fd(), &iov, &cmsg, MsgFlags::empty(), None).unwrap();
thread.join().unwrap();
} |
roblabla
added a commit
to roblabla/nix
that referenced
this issue
Sep 1, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For some reason, passing multiple FD over a Unix Domain Socket doesn't seem to work. Below is some test code that is supposed to send two fd over a Unix Socket along with 8 bytes of data. For some reason, only one FD is sent though, the other is lost in the void.
The output is
paneid = [1, 2, 3, 4, 5, 6, 7, 8], fds = [6]
The text was updated successfully, but these errors were encountered: