1

I'm trying to create a dbus service using sdbus (sd-bus?), that will respond with an fd representing a socket.

My client is able to receive strings and ints, so I have the basics covered. What I am looking for is how to package the fd as an "h" type in the response message.

3
  • You are aware file-descriptors are local to the process which created them, are you?? Commented Nov 29, 2016 at 15:11
  • @Olaf Yup, thanks. I've been promised some magic marshalling between processes that dbus is supposed to provide. Trying to find out how to invoke the magic. Commented Nov 29, 2016 at 15:17
  • 2
    You can find a discussion of the raw mechanisms needed to transfer file descriptors between processes in Sending file descriptor by Linux socket. I'm not sure how that ties in with sdbus, though. Commented Nov 29, 2016 at 15:21

1 Answer 1

2

It seems that there is no magic required.

The server creates the socket and replies to the client in the most apparent way (pseudo code):

fd = socket(AF_UNIX, SOCK_STREAM, 0); sd_bus_reply_method_return(message, "h", fd); 

The client just had to dup() the incoming fd and is then able to access it:

int fd; int dup_fd; sd_bus_message_read(message, "h", &fd); dup_fd = dup(fd); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.