From owner-freebsd-security Wed Feb 3 13:32:16 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id NAA26534 for freebsd-security-outgoing; Wed, 3 Feb 1999 13:32:16 -0800 (PST) (envelope-from owner-freebsd-security@FreeBSD.ORG) Received: from axl.noc.iafrica.com (axl.noc.iafrica.com [196.31.1.175]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id NAA26518 for ; Wed, 3 Feb 1999 13:32:08 -0800 (PST) (envelope-from sheldonh@axl.noc.iafrica.com) Received: from sheldonh (helo=axl.noc.iafrica.com) by axl.noc.iafrica.com with local-esmtp (Exim 2.11 #1) id 1089tX-000DUE-00; Wed, 3 Feb 1999 23:31:35 +0200 From: Sheldon Hearn To: Robert Wall cc: security@FreeBSD.ORG Subject: Re: Perl and file locking In-reply-to: Your message of "Wed, 03 Feb 1999 12:29:07 CST." Date: Wed, 03 Feb 1999 23:31:34 +0200 Message-ID: <51845.918077494@axl.noc.iafrica.com> Sender: owner-freebsd-security@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org On Wed, 03 Feb 1999 12:29:07 CST, Robert Wall wrote: > I noticed something interesting the other day - I'm writing a perl script > to add users to my master.passwd file, and I'm attempting to use exclusive > locks (flock filename, 2). During my test run of the script, another > program was accessing the file. My program paused and stuck until it > could get the exclusive lock for the file (~20 seconds), then finished > executing normally. Is this a bug, a feature, or just general weirdness? You need your lock attempt to be non-blocking: use Fcntl ':flock'; flock(HANDLE, LOCK_EX | LOCK_NB) or warn("Can't lock right now, will try again soon\n"); See flock(2) and perlfunc(1). Ciao, Sheldon. PS: Your question should really have gone to a perl-specific list, rather than a freebsd-specific list. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-security" in the body of the message