Mail Archives: cygwin/2009/11/18/11:10:15
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 <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#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
- Raw text -