delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/03/07/13:46:15

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <008801c52345$e6ce1bf0$173ca8c0@AlohaSunset.com>
From: "Mark Pizzolato" <list-cygwin AT subscriptions DOT pizzolato DOT net>
To: <cygwin AT cygwin DOT com>
Subject: Possible lack of thread safety in dup,fdopen
Date: Mon, 7 Mar 2005 10:45:55 -0800
MIME-Version: 1.0
X-OriginalArrivalTime: 07 Mar 2005 18:46:00.0554 (UTC) FILETIME=[E836ACA0:01C52345]
X-IsSubscribed: yes

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019