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 Subject: fcntl (locking) bug? Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Message-ID: <1MDETl-1TyrI00@fwd05.t-online.de> 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 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 #include #include #include #include #include #include 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/