delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT com |
DomainKey-Signature: | a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id |
:list-unsubscribe:list-subscribe:list-archive:list-post | |
:list-help:sender:date:from:to:subject:message-id:reply-to | |
:references:mime-version:content-type:in-reply-to; q=dns; s= | |
default; b=N7c2z1FyXJpL6lCc6B3y0lN1gkUMTxdNrrTPz2KvfR5aRirhzwBPb | |
SKnN4LFKjFJe2Gjs3e+ieBmw7HHBv2q8zUkXmSmS/oTfOMLIPkn7ASZNhFEn+rPJ | |
SEEEd1KKGVCnyvCL99wKZO+oMr2bykFcrhJ414VvpemwSi/cpuBHFs= | |
DKIM-Signature: | v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id |
:list-unsubscribe:list-subscribe:list-archive:list-post | |
:list-help:sender:date:from:to:subject:message-id:reply-to | |
:references:mime-version:content-type:in-reply-to; s=default; | |
bh=fxG5WiMuJ+p4iNefgLFexYUEAuY=; b=ehTDFdd8njmMjsJwXsm/Qh4pYKBQ | |
vl77swwiBrAh7X8Kee8U8Dj7vpaUPa9w07L+/RiHrScIAmFBNkL+gtxQEOZooj5K | |
cE5bfGaPf98Xak9dS5hvwKhOnfc/21tNmpXZVhjIZWoHHaLhmtlGxsoF9HyrkojU | |
aARTvsDs68Rk+Fw= | |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
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 |
Authentication-Results: | sourceware.org; auth=none |
X-Virus-Found: | No |
X-Spam-SWARE-Status: | No, score=-96.3 required=5.0 tests=AWL,BAYES_00,GOOD_FROM_CORINNA_CYGWIN,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_PBL,RCVD_IN_SORBS_DUL,RDNS_DYNAMIC autolearn=ham version=3.3.2 spammy=suddenly, shake, Hx-languages-length:1867, H*i:CAMpcqEHb |
X-HELO: | calimero.vinschen.de |
Date: | Tue, 21 Jun 2016 14:23:14 +0200 |
From: | Corinna Vinschen <corinna-cygwin AT cygwin DOT com> |
To: | cygwin AT cygwin DOT com |
Subject: | Re: 2.5.1: flock blocks when it shouldn't (NT-10.0, x86_64) |
Message-ID: | <20160621122314.GA12441@calimero.vinschen.de> |
Reply-To: | cygwin AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
References: | <CAMpcqEHb+UarN8WhMdONDOW3iJa5Zi+c49_RnYq8zXHNYWCvKQ AT mail DOT gmail DOT com> |
MIME-Version: | 1.0 |
In-Reply-To: | <CAMpcqEHb+UarN8WhMdONDOW3iJa5Zi+c49_RnYq8zXHNYWCvKQ@mail.gmail.com> |
User-Agent: | Mutt/1.6.1 (2016-04-27) |
--vtzGhvizbBRQ85DL Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Jun 21 06:04, RG wrote: > Hello, >=20 > I have encountered unexpected behavior when using flock. > It will block forever, but to my understanding it should not. > I've attached a simple program that would trigger the behavior. >=20 > Regards, > Alex > #include <stdio.h> > #include <unistd.h> > #include <sys/file.h> >=20 > FILE *fp; >=20 > void main() { > unlink("a"); unlink("b"); >=20 > fp =3D fopen("a", "wb"); // file a >=20 > printf("lock a\n"); > flock(fileno(fp), LOCK_EX); >=20 > fwrite("TEST", sizeof(char), 4, fp); >=20 > printf("unlock a\n"); > flock(fileno(fp), LOCK_UN); > fclose(fp); >=20 > fp =3D fopen("b", "wb"); // file b >=20 > printf("lock b\n"); > flock(fileno(fp), LOCK_EX); // hang >=20 > fwrite("TEST", sizeof(char), 4, fp); >=20 > printf("unlock b\n"); > flock(fileno(fp), LOCK_UN); > fclose(fp); > } Thank you for the report and especially the testcase! This is one of those long-standing problems where you shake your head violently and wonder why nobody noticed this earlier. The problem only occurs for newly created files, and only if they get created in the same parent dir. What happoens is that the inode number for the files (which is crucial for flock) is yet incorrectly the inode number of the parent directory after fopen. However, due to the way fwrite works, its call results in fetching the correct inode number of the file. The subsequent flock fails to unlock because searching the file by inode number suddenly fails. I uploaded new developer snapshots on https://cygwin.com/snapshots/, I also created and just announced a new test release 2.5.2-0.2 which contains a fix for this problem and can be easily installed via setup. Please give any of them a try ASAP. Thanks, Corinna --=20 Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat --vtzGhvizbBRQ85DL Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJXaTGyAAoJEPU2Bp2uRE+g53gQAIcYSDU+zAr06zAg3+pjMnri 5SzZYfWs8ec2a8r30UQMtIPXIcE6LHD4m11LSkmAEtK5AV+X21xKaDu00qBcJ6J3 BqJDS4lVhffrZpedWy0QN+YZ/B26DIcuNbTJVmBh9kDPqyeV+SVWb3f230g5fQGy fQOB/+Jqu0xcfoiuQb+gL2PQi3LuHOFJtD4erAby6OicBG7xCO1L5JbnIDjn1wnZ fZPAFC55RxNxKswH2FcdWHviH2mSJ61ME4n6fjJeTkhIm2tr1Numjyiy+g9wva0B nh4b5eDN9gPAQMHDhL992paQFKBBfPykBYSsyhtAXZRiKxmY0Pu7n5nExvJD0WM9 I5yo5H8qfmuib77ZcD4YRRdud/fvqmFbvguXy4KptceL4dXkldnNRdaAa+JcCiO9 CtwZZ023Nznq/wfPBsZ1OWFBFbirWG0n/jL++pwgx7gJpjZHeboL22oEwAQFsN+u 9o57cURpK7JLDxZC21YHbmKp0/AUVCMQVzLdO4Rq3gTELJpSNWRNxapk7kWOHy+B UpRp22IMOq/ETl3/j/GwL4YQO0hEyMML7qhfOy86eVQWqcOKoo040JYubpM18gCy F1NqXRpYa34pjoDiK18SzmwDGaMEMXTE1R0RjXQFWUhmomK3MSWXWtEy0n451sqN kfMuyR1hnXSSTSUCw6pa =/5QC -----END PGP SIGNATURE----- --vtzGhvizbBRQ85DL--
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |