This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Possible lack of thread safety in dup,fdopen


I've been using clamav's clamd under cygwin and today noticed an issue.

Clamd is a multi-threaded program.

The following code sequence encountered an error today (ERROR calling fdopen on fd 11):

int i, fd;
FILE *f, *tmp;
tmp = fopen("somefile", "wb+");
if (NULL == tmp) return;
fd = fileno(tmp);
{write some stuff to fd }
lseek(fd, 0, SEEK_SET);
i = dup(fd);
if ((f - fdopen(i, "rb")) == NULL) {
    fprintf(stderr, "ERROR calling fdopen on  fd %d", i);

This is happening in one thread while other threads are merrily open and closing files and sockets.

I've got some log output suggesting that fd 11 might have also been used by another thread at "around" the same time. It would seem that this could only happen if something lost track of the bookeeping for fd's or there was a race managing that bookeeping.

I tried to look at the code for fopen(),dup(), and fdopen() myself before reporting this, but I can't find the implementations of these system calls in the source package for cygwin-1.5.13-1

Can someone point me to where I can look at the source code?

Thanks.

- Mark Pizzolato







--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]