X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00 X-Spam-Check-By: sourceware.org Message-ID: <936047.37094.qm@web87013.mail.ird.yahoo.com> Date: Wed, 18 Nov 2009 08:08:59 -0800 (PST) From: jmsplat101-cygwin AT yahoo DOT co DOT uk Subject: Problem with fcnlt F_GETLK command To: cygwin AT cygwin DOT com MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Hello, I've down loaded version 1.7 onto my Windows XP laptop (uname -a reports CY= GWIN_NT-5.1 XXXXXXXXXX 1.7.0(0.217/5/3) 2009-11-10 13:03 i686 Cygwin) and I= 'm having some problems with the fcntl() function. I've written the following sample to demonstrate=A0the problem: #include #include #include #include #define LOCK_FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S= _IWOTH) int main(int argc, char* argv[]) { =A0 struct flock lock ; =A0 // Open the file =A0 int fd =3D open("lockfile", O_RDWR | O_CREAT, LOCK_FILE_MODE) ; =A0 // define the lock =A0 lock.l_type =3D F_WRLCK ; =A0 lock.l_start =3D 0 ; =A0 lock.l_whence =3D SEEK_SET ; =A0 lock.l_len =3D 1 ; =A0 lock.l_pid =3D 0 ; =A0 // Check if the lock will work =A0 if ( fcntl(fd, F_GETLK, &lock) < 0 ) =A0=A0=A0 perror("fcntl error") ; =A0=20 =A0 if ( lock.l_type =3D=3D F_UNLCK ) =A0=A0=A0 { =A0=A0=A0=A0=A0 printf("No blocking lock\n") ; =A0=A0=A0=A0=A0 lock.l_type =3D F_WRLCK ;=20 =A0=A0=A0 }=A0=20 =A0=20 =A0 printf("Trying to get lock\n") ; =A0 if ( fcntl(fd, F_SETLKW, &lock) < 0 ) =A0=A0=A0 perror("fcntl error") ; =A0 printf("Holding onto lock\n") ; =A0=A0 // Hold the lock for ever. =A0loop: =A0=A0 sleep(60) ; =A0=A0 goto loop ; =A0=A0 return 0 ; } If I run this code in the same directory in two seperate shells I'd expect = only the first=A0instance=A0to print 'No blocking lock'=A0 however=A0both d= o=A0and the=A0 second then goes on to block waiting for the actual lock (wh= ich it gets when I terminate the first instance). So the locking functional= ity works just fine; however the lock reporting does seem not to work and a= lways returns F_UNLCK. Can someone confirm if this is=A0a known limittaion of the current version,= a limitation of the underlying windows API or a bug? Jackson -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple