views:

548

answers:

1

Hello All,

Not been able to figure out why recvmsg() blocks when i try this test app on ubuntu.

http://web.mit.edu/kolya/misc/break-chroot.c

thanks

+2  A: 

I strongly remember file descriptor passing only working over Unix Datagram sockets, not Unix stream sockets. This may also necessitate resends. Your example is too large (and I'm too lazy) to do a proper analysis, but look here for alternative example code. I've used that example myself on both FreeBSD and Linux, it works.

Michiel Buddingh'
thanks, the code you referenced also works fine in my environment.But the problem is when i set msg.msg_iovlen=0 and msg.msg_iov=NULL, it doesn't work on ubuntu ( i am not sure on the behavior of other flavors of linux/unix).recvmsg() doesn't return and gets blocked waiting for msg. The example i referred in my post, sets msg.msg_iov=NULL.
harishvk27
The example code remarks that you need to send at least one byte of 'real' data for your message to be delivered.
Michiel Buddingh'
`SOCK_STREAM` unix sockets work, too, per my own experience and, perhaps more credibly :), Stevens' *UNIX Network Programming*.
pilcrow
I stand corrected, then :) It seems your answer was right all along.
Michiel Buddingh'
But i didn't understand why did you recommend SOCK_DGRAM over SOCK_STREAM, because i am able to send fd's over SOCK_STREAM also. is there any good reason when to use SOCK_DGRAM over SOCK_STREAM ? or it's just the matter of programmers confirt level
harishvk27
I recommended SOCK_DGRAM because I was wrong :)
Michiel Buddingh'
@harishvk27, why don't you pose your question, *"[I]s there any good reason to use `SOCK_DGRAM` over `SOCK_STREAM`,"* as a new SO question?
pilcrow