From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 111099 invoked by alias); 21 Jun 2016 12:23:27 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 111077 invoked by uid 89); 21 Jun 2016 12:23:26 -0000 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 Received: from ipbcc0227e.dynamic.kabel-deutschland.de (HELO calimero.vinschen.de) (188.192.34.126) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 21 Jun 2016 12:23:16 +0000 Received: by calimero.vinschen.de (Postfix, from userid 500) id 8F074A803D5; Tue, 21 Jun 2016 14:23:14 +0200 (CEST) Date: Tue, 21 Jun 2016 14:03:00 -0000 From: Corinna Vinschen To: cygwin@cygwin.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@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="vtzGhvizbBRQ85DL" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.6.1 (2016-04-27) X-SW-Source: 2016-06/txt/msg00276.txt.bz2 --vtzGhvizbBRQ85DL Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 1947 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 > #include > #include >=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" Content-length: 819 -----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--