CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Flock and windows

 



yim11
Novice

Jun 7, 2001, 7:00 PM

Post #1 of 3 (313 views)
Flock and windows Can't Post

Hello,
I have a script I need to use that utilizes the flock funtion. I understand that the activestate perl install on windows does not use the flock command, my question is does anyone know a way to get around this or to allow the use of flock on a windows machine? The section of code that uses flock is posted below.

TIA for all help!

--------begin code section--------
sub read_pwd_file
{
if($pwdfile eq ""){
&send_error("503"); #failed to locate the password file
exit;
}
#open password file
unless(open(PWD,$pwdfile)){
&send_error("504"); #failed to open the password file
exit;
}
flock(PWD,$LOCK_EX);
seek(PWD,0,0);
while(<PWD>){
if (index($_,":") >= 0){
($cuser,$cpwd) = split(':',$_);
chop($cpwd);
if($users{$cuser} ne ""){
&send_error("Duplicate user '" . $cuser . "' found\n");
exit;
}
$users{$cuser}=$cpwd;
}
}
flock(CFG,$LOCK_UN);
close(CFG);

return %users;
}

<--snip-->
sub write_pwd_file
{
if($pwdfile eq ""){
&send_error("503"); #failed to locate the password file
exit;
}
#open password file
unless(open(PWD,">" . $pwdfile)){
&send_error("504"); #failed to open the password file
exit;
}
flock(PWD,$LOCK_EX);
seek(PWD,0,0);
foreach $user (keys %users){
$temp = $temp . $user . " :: " . $users{$user} . "\n";
print PWD $user . ":" . $users{$user} . "\n";
}
flock(PWD,$LOCK_UN);
close(PWD);
}
-------end code section----------



Pro_4
User

Jun 7, 2001, 7:22 PM

Post #2 of 3 (312 views)
Re: Flock and windows [In reply to] Can't Post

Well the way i understand it (read from a book somewhere) you dont need to use flock or anything of that nature on a windows machine because windows does it normally or something like that.

Maybe someone else can better explain what is happening but basically you dont need to worry about it on windows.

:)

Yes i am a palm tree. What are you plantist or something!?


Mortimer
journeyman

Jun 8, 2001, 9:28 PM

Post #3 of 3 (300 views)
Re: Flock and windows [In reply to] Can't Post

There's a script I wrote to do what you ask here...

http://www.dmscripts.com/quickhacks/no_flock_lock.html

All you have to do is set $flock_on as required. If the system supports Perl's flock(), then use it because it's the best choice. If not, then this script will take care of your file locking as long as your system supports Perl's sysopen(). Windows supports sysopen(). The reason I wrote this script is so I can reassure my NT clients on file locking. Another is so I don't have to go ploughing through my scripts before uploading to uncomment all the flock() calls!

Windows does not support flock(), nor does it have it's own file locking mechanism. That's probably because windows wasn't originally intended for networks, well not busy ones. Basically, the more processes wanting to access your files in a given period of time, the more you need file locking.

Cheers,
Dave.
www.dmscripts.com
davemortimer@bigpond.com



 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives