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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.