Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing file descriptor from one program to another on the same host using UNIX sockets

Tags:

c

linux

I have two prgrams lets say prog1 and prog2. I am opening a file with prog1 and doing some operations on it. Now without closing the file in prog1 i am sending its file descriptor to prog2 using unix sockets which then does some operations in it.

Though i get the same descriptor i passed in prog1 but doing a fstat() on the fd recieved in prog2 throws an error saying Bad file descriptor. I have opened the file in prog1 with corerct permissions that is read and write for all, still i get an error.

Why is it happening so. If my way of passing a file descriptor is wrong then please suggest a correct one.

like image 487
tnx123456 Avatar asked Dec 12 '22 03:12

tnx123456


1 Answers

I believe this site has what you're looking for:

http://www.lst.de/~okir/blackhats/node121.html

There's also information in Linux's man 7 unix on using SCM_RIGHTS and other features of Unix sockets.

Fix for broken link: http://web.archive.org/web/20131016032959/http://www.lst.de/~okir/blackhats/node121.html

like image 92
R.. GitHub STOP HELPING ICE Avatar answered Dec 31 '22 01:12

R.. GitHub STOP HELPING ICE