X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:reply-to:message-id:to:subject :in-reply-to:references:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=oIWGfq3NCUXPVCwh FAEmxB0ei67pEkKEcQxxe5q+7QrCj21jZs+9Ih4jC8vwdWRY2GbWt1f06aVXofbA IU4hTH84fqg2NcUiYKWOyEbQ4VHO8Pt53JiDihpUzemJ5+CHrQs88hJ/a0MJZ1rM 6ZGIeiNLis+aLExePg2XhWVglJU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:reply-to:message-id:to:subject :in-reply-to:references:mime-version:content-type :content-transfer-encoding; s=default; bh=OnK+HdaMFcVPCOZCEfq6yp 6oMGs=; b=mcO0ATAhOJsVpLCU1vgTXxGd4pmlfHFFucsqTK7VohFdHclGMTO+Ut HcCIYZmZnzMXRHwzUU4KrpLzEbFnqFzyeVZi7x+B4DmkL3yKAMh9T43tFpLnkA8O oXEEy+0OL/wJAh5kBDuGP4LkUZo7uMhJ2wiogOqA4igZjTleQeRqY= 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 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=4.0 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,KAM_THEBAT,SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=H*UA:Bat!, H*x:Bat!, H*r:sk:postmas, H*r:4.80.1 X-HELO: smtp.ht-systems.ru Date: Mon, 4 Apr 2016 19:51:11 +0300 From: Andrey Repin Reply-To: cygwin AT cygwin DOT com Message-ID: <59768064.20160404195111@yandex.ru> To: Corinna Vinschen , cygwin AT cygwin DOT com Subject: Re: Unreliable flock In-Reply-To: <20160404151644.GB29337@calimero.vinschen.de> References: <175808986 DOT 20160403002257 AT yandex DOT ru> <20160404151644 DOT GB29337 AT calimero DOT vinschen DOT de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Greetings, Corinna Vinschen! >> The script (let's call it test.sh): >> >> #!/bin/dash -x >> _lock="./console-session.lock" >> { >> flock -n 9 || { >> echo "The $(cat "$_lock") command is running already." >> exit 3 >> } >&2 >> >> printf "$1" >&9 >> >> trap 'rm "$_lock";' EXIT HUP INT ABRT TERM >> >> sleep 20 >> >> } 9>> "$_lock" >> >> Very simple in essence. >> The one-liner: >> >> { flock -n 9 && sleep 10 || echo Fail;} 9>> ./console-session.lock >> >> Also extremely simple. >> >> Open two terminals. mintty or native, bash or dash, doesn't matter. >> chdir to the directory with the script. >> >> Start script in one terminal. ./test.sh >> Start oneliner in another terminal. Fail. How predictable! > I don't know what I'm doing wrong, but this WJFFM with Cygwin 2.4.1 > as well as 2.5.0. Additionally I tried to put the oneliner into a > script but it still WFM. It works for me, too. From time to time. But this work is completely unreliable. It may work five times, then fail ten times in a row. Most often it fails, if I run oneliner first. Almost 100%. > Apart from that, did you notice the flock restrictions outlined in > https://cygwin.com/cygwin-api/std-notes.html ? If you mean the part about > BSD file locks created via flock are only propagated to the direct parent > process, not to grand parents or sibling processes. The locks are only valid > in the creating process, its parent process, and subsequently started child > processes sharing the same file descriptor. then that's a showstopper. In short, it makes the function literally useless. I can work around it in a given script, but... *sad panda* Why they aren't real locks? What's use for "advisory locks"? "I think I may have a use for this file, but you are free to delete it, if you wish" ? -- With best regards, Andrey Repin Monday, April 4, 2016 19:27:11 Sorry for my terrible english... -- 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