Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fcntl instead of flock

Status
Not open for further replies.

rotis23

Programmer
Aug 29, 2002
121
GB
Hi All,

I've got a problem with a script running on a Linux 2.4 kernel where 'flock' is apparently broken. Therefore I'm thinking of using the 'fcntl' wrapper.

Here's the existing flock call:

Code:
$retval = flock(QF, $LOCK_EX|$LOCK_NB)

So, I need to create an exclusive lock on an entire file (like flock does) and make it non-blocking. Can I do this with fcntl like this?
Code:
my $lock = struct_flock(F_WRLCK,SEEK_SET,0,0,0);
...
fcntl(QF, F_SETLK, $lock) or die "F_GETLK $$ @_: $!";
...

Are there any other modules/mthods I can use?

Thanks for any help on this.

rotis23
 
Have you tested "flock"?
"fcntl" is the only other obvious way I can see that you could do this.


Trojan.
 
Thanks for your response Trojan. From the sendmail release notes for v8.13:

"The Linux kernel version 2.4 series has a broken flock() so change to using fcntl() locking until they can fix it. Be sure to update other sendmail related programs to match locking techniques"

This script scans large sendmail queues and move mails -we've seen problems.

Is my example of fcntl OK? Does anyone else use it for file locking (over flock)?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top