delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/07/21/19:26:46

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS
X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Eric Blake <ebb9 AT byu DOT net>
Subject: flock still buggy
Date: Tue, 21 Jul 2009 23:26:16 +0000 (UTC)
Lines: 33
Message-ID: <loom.20090721T231647-613@post.gmane.org>
Mime-Version: 1.0
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes
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

I finally figured out why autoconf is still failing its flock-related tests, 
and why perl was reliably failing even though my simple attempts in C were 
always passing.  It turns out that if you do:

open
flock(LOCK_EX)
if (!fork)
  execlp("sleep","sleep","10",NULL);
sleep(10);

then ProcessExplorer shows that the Event in the global namespace of flock-dev-
ino\20-2-* exists in both parent and child, and with a notification level of 
false, blocking any outside influence until both the parent and forkee exit.  
But if you do:

open
fcntl (fd, F_SETFD, FD_CLOEXEC | fcntl (fd, F_GETFD))
flock(LOCK_EX)
if (!fork)
  execlp("sleep","sleep","10",NULL);
sleep(10);

then only the parent holds a handle to the Event, but with a notification level 
of true, allowing any outside party to do whatever they want.

I'm still trying to figure out why the close-on-exec cleanup appears to be 
spuriously triggering the flock Event to unlock.  But my understanding is that 
F_FLOCK locks should survive over exec, so the close-on-exec cleanup should 
only trigger lock release on F_POSIX locks.

-- 
Eric Blake



--
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 -


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