Return-Path: Delivered-To: apmail-apr-dev-archive@www.apache.org Received: (qmail 90128 invoked from network); 30 Oct 2009 09:27:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 30 Oct 2009 09:27:21 -0000 Received: (qmail 90843 invoked by uid 500); 30 Oct 2009 09:27:20 -0000 Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 90747 invoked by uid 500); 30 Oct 2009 09:27:20 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Id: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 90739 invoked by uid 99); 30 Oct 2009 09:27:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Oct 2009 09:27:20 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [194.25.134.82] (HELO mailout05.t-online.de) (194.25.134.82) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Oct 2009 09:27:10 +0000 Received: from fwd10.aul.t-online.de by mailout05.t-online.de with smtp id 1N3nku-0003uA-01; Fri, 30 Oct 2009 10:26:48 +0100 Received: from [192.168.0.1] (bHdYrrZB8tZo7o3-ildlxVO3A+IeY0dwrxpxS2JxBV6axFA2bSXfu-1cL1JHuV3TCPeYfZhdSc@[87.139.49.240]) by fwd10.webpage.t-com.de with esmtp id 1N3nke-0BIecC0; Fri, 30 Oct 2009 10:26:32 +0100 Message-ID: <4AEAB13F.3000804@ruppert-it.de> Date: Fri, 30 Oct 2009 10:26:23 +0100 From: Stefan Ruppert User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090707) MIME-Version: 1.0 To: APR Development List Subject: Re: apr_file_close()/apr_socket_close() References: <1256883239.2488.54.camel@shrek.rexursive.com> In-Reply-To: <1256883239.2488.54.camel@shrek.rexursive.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-ID: bHdYrrZB8tZo7o3-ildlxVO3A+IeY0dwrxpxS2JxBV6axFA2bSXfu-1cL1JHuV3TCPeYfZhdSc X-TOI-MSGID: a7881c7e-6aa8-4bfb-b86f-4dedcec13aa7 X-Virus-Checked: Checked by ClamAV on apache.org Hi Bojan, first of all the question is if the apr_file_t handle can be safely used from different threads? e.g. is APR file wrapper thread safe? And I don't think so! Or am I wrong? If it isn't thread safe the caller is responsible for locking the involved operations in different threads! If APR file wrappers should be thread safe, it has to use a mutex to protect its state changes... Regards, Stefan Bojan Smojver wrote: > We have effectively this code closing the file in apr_file_close(): > --------------- > static apr_status_t file_cleanup(apr_file_t *file, int is_child) > { > apr_status_t rv = APR_SUCCESS; > > if (close(file->filedes) == 0) { > file->filedes = -1; > --------------- > > If someone calls apr_file_os_get() from another thread (whether they set > APR_FOPEN_XTHREAD or not), then may get a file->filedes which is an FD > of an already closed file. It gets worse - they may get an FD which was > reused by yet another thread. Quite dangerous. > > I think it would be safer if we did this: > --------------- > static apr_status_t file_cleanup(apr_file_t *file, int is_child) > { > apr_status_t rv = APR_SUCCESS; > int fd = file->filedes; > > file->filedes = -1; > > if (close(fd) == 0) { > [ ... ] > } > else { > [ ... ] > file->filedes = fd; /* restore, close() was not successful */ > } > --------------- > > apr_socket_close() is similar. > > Opinions? >