X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org Date: Thu, 12 Mar 2009 23:17:23 +0100 From: Corinna Vinschen To: cygwin AT cygwin DOT com Subject: Re: Problem getting flock with timeout to work Message-ID: <20090312221723.GA9322@calimero.vinschen.de> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <9e3fd2c80903120740u5fa06d62t372cd67212fad1e AT mail DOT gmail DOT com> <20090312155236 DOT GX9322 AT calimero DOT vinschen DOT de> <9e3fd2c80903120944h5aebc094y7e461eee580e4eeb AT mail DOT gmail DOT com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9e3fd2c80903120944h5aebc094y7e461eee580e4eeb@mail.gmail.com> User-Agent: Mutt/1.5.19 (2009-02-20) Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: 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 On Mar 12 17:44, Robert Klemme wrote: > The second flock does not start the command as I expect it to be. > > I am referring to the man page of flock which says this about option -w: > > Fail (with an exit code of 1) if the lock cannot be acquired within > seconds seconds. Decimal fractional values are allowed. > > So, since the second flock obviously cannot obtain the lock in time, I > would have expected it to fail and not execute the command given. > This is at least a documentation issue as flock's behavior and > documentation do not match IMHO. This scenario (your first testcase) works fine with Cygwin 1.7 with my fix from a couple of hours ago. I missed the fact that BSD flock lock semantic allows to set both lock types (LOCK_SH/LOCK_EX) regardless of the read/write mode in which the file has been opened, in contrast to POSIX lock semantic. That's fixed now and other than that glitch, it worked. However... > I'll attach another script which implements the other suggested scheme > with even more disturbing output: > > 17:31:09 tmp$ ./fl-test.sh > CYGWIN_NT-5.1 padrklemme1 1.5.25(0.156/4/2) 2008-06-12 19:34 i686 Cygwin > -rw-r--r-- 1 RKlemme Domain Users 0 Mar 12 17:31 lock > timeout 10 > started 1 with PID 3160 > 1 1 Thu Mar 12 17:31:31 WEST 2009 > started 2 with PID 1848 > 2 1 Thu Mar 12 17:31:32 WEST 2009 > 1 2 Thu Mar 12 17:31:32 WEST 2009 > waiting... > 2 2 Thu Mar 12 17:31:33 WEST 2009 > 1 3 Thu Mar 12 17:31:33 WEST 2009 > 2 3 Thu Mar 12 17:31:34 WEST 2009 > 1 4 Thu Mar 12 17:31:34 WEST 2009 > 2 4 Thu Mar 12 17:31:35 WEST 2009 > 1 5 Thu Mar 12 17:31:35 WEST 2009 > 2 5 Thu Mar 12 17:31:36 WEST 2009 > done > 17:31:37 tmp$ > > Zero locking at all! Cygwin won't be able to support the scenario from your second testcase for the time being. The reason is that in this scenario ( flock -s 200 ... ) 200> lockfile the lock will end when the flock process exits. The lock can only persist as long as the process which created the lock, or any of the child applications which inherited the file descriptor, still runs. We can't maintain a global file descriptor table with lock information like the OS or what a master process could do if Cygwin would be designed so. I know that's bad news, it certainly is for me since I thought I had implemented flock with full BSD semantics, but we just can't do that for now. Corinna -- Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Project Co-Leader cygwin AT cygwin DOT com Red Hat -- 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/