[uClibc]fdopen on unix socket, then closing fd

Doornekamp, Ico (Contractor) ico.doornekamp at intersil.com
Thu Jan 31 12:42:01 UTC 2002


Hi,

I'm trying to find out how to avoid the following problem : There's two
applications, 
communicating through a AF_UNIX socket.

- Server creates the socket, and does a listen()
- Client does a connect() to the socket
- Server accept()'s and does a fdopen on the newly acquired file
descriptor
- Client does some write()-ing to the socket file descriptor and closes
directly after
- Server does fget() on the FILE *, and fgets() causes a segmentation
fault

The segfault seems to happen due to a stack overflow somewhere in
fseek(). 

I can understand something goes wrong here, since the client closes the
socket, 
leaving the server with an unconnected endpoint. The socket file
descriptor is no longer
valid, so the correspinding FILE * will be invalid too. But how can I
tell ?

The problem is that I would like  to know, before doing the fgets(), if
the other side 
might have closed it's socket. I hoped fgets() would just return NULL in
this case so this 
could be handled nice and quiet, but instead somewhere inside uClibc
fseek() gets confused 
and messes up.

Is there any way of telling the socket is no longer valid by looking at
the FILE * ?
I guess using read() and write() on the file descriptor instead of
fgets() and fprintf() on
the FILE * would solve this problem too, but I hope there's a solution
where I can still
use these functions....

Regards,

Ico Doornekamp




More information about the uClibc mailing list