delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/06/07/05:16:15

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=0.0 required=5.0 tests=BAYES_50
X-Spam-Check-By: sourceware.org
Date: Sun, 07 Jun 2009 11:15:47 +0200
To: cygwin AT cygwin DOT com
From: Margit Schubert-While <margitsw AT t-online DOT de>
Subject: fcntl (locking) bug?
Mime-Version: 1.0
Message-ID: <1MDETl-1TyrI00@fwd05.t-online.de>
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

This is 1.5.25 but also happens on earlier versions.
It would appear that placing a shared read lock
on a file open for input/output is preventing the
the process itself from writing.
Consider -

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int
main ()
{
         int             fd;
         struct flock    lock;

         errno = 0;
         fd = open ("TESTFILE", O_CREAT | O_TRUNC | O_WRONLY, 0777);
         printf("Open for write - Errno %d\n", errno);
         if (fd >= 0) {
                 errno = 0;
                 if (write (fd, "TESTtest", 8) != 8) {
                         printf ("Write error - %d\n", errno);
                         close (fd);
                         return 1;
                 }
                 errno = 0;
                 close (fd);
                 printf("Close after write - Errno %d\n", errno);
         }
         fd = open ("TESTFILE", O_RDWR, 0);
         printf("Open for I/O - Errno %d\n", errno);
         if (fd < 0) {
                 return 1;
         }
         memset (&lock, 0, sizeof (struct flock));
         lock.l_type = F_RDLCK;
         lock.l_whence = SEEK_SET;
         lock.l_start = 0;
         lock.l_len = 0;
         errno = 0;
         if (fcntl (fd, F_SETLK, &lock) < 0) {
                 printf ("Lock error - %d\n", errno);
                 close (fd);
                 return 1;
         }
         errno = 0;
         if (write (fd, "test", 4) != 4) {
                 printf ("Write I/O error - %d\n", errno);
         }
         memset (&lock, 0, sizeof (struct flock));
         lock.l_type = F_UNLCK;
         lock.l_whence = SEEK_SET;
         lock.l_start = 0;
         lock.l_len = 0;
         errno = 0;
         if (fcntl (fd, F_SETLK, &lock) < 0) {
                 printf ("Unlock error - %d\n", errno);
                 close (fd);
                 return 1;
         }
         close (fd);
         return 0;
}

This always prodcues -
Write I/O error - 13
ie. EACCES

Margit


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019