Problem with fcnlt F_GETLK command

jmsplat101-cygwin@yahoo.co.uk jmsplat101-cygwin@yahoo.co.uk
Wed Nov 18 16:32:00 GMT 2009


Hello,

I've down loaded version 1.7 onto my Windows XP laptop (uname -a reports CYGWIN_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 the 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[])
{
  struct flock lock ;
  // Open the file
  int fd = open("lockfile", O_RDWR | O_CREAT, LOCK_FILE_MODE) ;
  // define the lock
  lock.l_type = F_WRLCK ;
  lock.l_start = 0 ;
  lock.l_whence = SEEK_SET ;
  lock.l_len = 1 ;
  lock.l_pid = 0 ;
  // Check if the lock will work
  if ( fcntl(fd, F_GETLK, &lock) < 0 )
    perror("fcntl error") ;
  
  if ( lock.l_type == F_UNLCK )
    {
      printf("No blocking lock\n") ;
      lock.l_type = F_WRLCK ; 
    }  
  
  printf("Trying to get lock\n") ;
  if ( fcntl(fd, F_SETLKW, &lock) < 0 )
    perror("fcntl error") ;
  printf("Holding onto lock\n") ;
   // Hold the lock for ever.
 loop:
   sleep(60) ;
   goto loop ;
   return 0 ;
}

If I run this code in the same directory in two seperate shells I'd expect only the first instance to print 'No blocking lock'  however both do and the  second then goes on to block waiting for the actual lock (which it gets when I terminate the first instance). So the locking functionality works just fine; however the lock reporting does seem not to work and always returns F_UNLCK.

Can someone confirm if this is a 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



More information about the Cygwin mailing list