Hi
I wanted to port a script that is running perfectly fine on my own Debian GNU/Linux boxes to one of the Solaris boxes at work. Somehow though this is a no go :-(
The problem is with file locking. Google and the monastery search didn't help me, but maybe someone else can explain to me what's going on here.
This is the code that's giving me trouble:
#Lock the file and move it to the processing file
if (-f $file) {
print "Moving the file from $file to $processfile...\n" if $verbose;
open(INFILE, '<', $file) or die "Cannot open the file: $!\n";
unless (flock(INFILE, LOCK_EX | LOCK_NB)) {
if ($verbose) {
local $| = 1; #Flush buffer so the message is shown immediately
print "Waiting for a lock on $file...\n";
}
flock(INFILE, LOCK_EX) or die "Cannot lock $file: $!\n";
}
move($file, $processfile) or die "Cannot move $file: $!\n";
close INFILE;
}
else {
die "No file found at $file\n";
}
On Solaris this results in the following error message:
Waiting for a lock on /home/flr/gvtest...
Cannot lock file: Bad file number
It seems open is successful, but locking is not.
As far as I know this is normally the result of $file not being a file, but the -f test should exclude that possibility.
Can anyone tell me where to look or maybe even how to solve this?
Help would be appreciated as this is the last hurdle to take. If this is remedied I have a fully functional Antivirus Monitor that looks up local infections in our network and processes them (reporting, warnings, statistics, ticketing...)
Thanks for your time
In reply to Trouble with locking under Solaris by jadev
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |