| delorie.com/archives/browse.cgi | search |
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
| List-Archive: | <http://sources.redhat.com/ml/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/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 |
| To: | cygwin AT cygwin DOT com |
| From: | "Blair P. Houghton" <blair AT houghton DOT net> |
| Subject: | Re: unlink(2) or fopen(3) failing under cygwin |
| Date: | Wed, 24 Mar 2004 06:47:41 +0000 (UTC) |
| Lines: | 52 |
| Message-ID: | <loom.20040324T072953-83@post.gmane.org> |
| References: | <loom DOT 20040323T173940-810 AT post DOT gmane DOT org> <NGBBLLIAMFLGJEOAJCCEMEJFDJAA DOT garbage_collector AT telia DOT com> |
| Mime-Version: | 1.0 |
| X-Complaints-To: | usenet AT sea DOT gmane DOT org |
| X-Gmane-NNTP-Posting-Host: | main.gmane.org |
| User-Agent: | Loom/3.14 (http://gmane.org/) |
| X-Loom-IP: | 12.223.151.176 (Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)) |
Hannu E K Nevalainen <garbage_collector <at> telia.com> writes: > > Does anyone know of any reason an fopen on the > > just-unlinked file would fail under Cygwin? > > IIRC this has been up earlier; unlink() isn't atomic. Hence the loop. I'm sure I've even had to do this to this exact file before (but I'm putting the code onto a new machine and managed not to have the code from the old machine anywhere I could get at it...it's kind of a long story...) It turns out the real problem is that trn is doing this protocol for killfile processing: on entering newsgroup: fp1 = open killfile read fp1, apply data to newsgroup on exiting newsgroup: unlink killfile fp2 = open killfile (***) write new data to fp2 close fp2 close fp1 fp1 = open killfile Cygwin on Win XP (at least) doesn't like the (***) line. I don't like it either. It's just wrong to be able to open an unclosed file just because you unlinked it. It must work on BSD and/or SysV though, or trn would never have gone anywhere. I fixed it by changing the rewrite code to use a temp file for the output, then close the old file and rename the temp file on top of it: on exiting newsgroup: fp2 = open tempfile write new data to fp2 close fp2 close fp1 move tempfile to killfile (using rename) fp1 = open killfile It works perfectly now, and doesn't look quite so shroom-induced. It doesn't even use unlink(2) unless certain rule changes cause the killfile to end up empty on rewrite. Thanks for the pointers. --Blair "pointers. heh. get it?" -- 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/
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |