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.

Mattias Backman
  • 927
  • 12
  • 25
  • You are aware file-descriptors are local to the process which created them, are you?? – too honest for this site Nov 29 '16 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. – Mattias Backman Nov 29 '16 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](http://stackoverflow.com/questions/28003921/sending-file-descriptor-by-linux-socket). I'm not sure how that ties in with sdbus, though. – Jonathan Leffler Nov 29 '16 at 15:21

1 Answers1

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);
Mattias Backman
  • 927
  • 12
  • 25