Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: file lock error

by wind (Priest)
on Apr 06, 2011 at 19:50 UTC ( #897869=note: print w/replies, xml ) Need Help??


in reply to file lock error

The Fcntl constants for flock can be found by browsing the source at cpan Fcntl.pm

use Fcntl qw(:flock);

They are:

'flock' => [qw(LOCK_SH LOCK_EX LOCK_NB LOCK_UN)],

Replies are listed 'Best First'.
Re^2: file lock error
by dbs (Sexton) on Apr 06, 2011 at 20:06 UTC
    ok thank you but I am still getting the same error.

    new code

    use strict; use warnings; use MIME::Lite; use FileHandle; use File::Copy; use Logfile::Rotate; use Fcntl qw(:flock); flock($RLOG, LOCK_SH|LOCK_NB) || warn "no NB lock $!"; flock($MLOG, LOCK_SH|LOCK_NB) || warn "no NB lock $!";

    well similar error NOW: error: can not open: (1)

    before :error: can not lock open: (1)"
      As you should. You're locking the file for reading, which prevents Logfile::Rotate from getting an exclusive lock on the file. Why are you locking the file?
        I did not intentionally lock the file. Rather I only add the 'flock' calls after I got this error after adding add'l code to my logfile rotate sub.

        I also told logfile rotate Flock => no, but that does not rid of my error.

        Here is my logfile rotate code:
        sub _logroll($;$) { my $gzip; eval qq(use Compress::Zlib); if ($@) { $gzip = q(/usr/bin/gzip); } else { $gzip = q(lib); } if ( scalar @_ == 1 ) { my $roll1 = @_; my $rollog1 = new Logfile::Rotate( File => $roll1, Count => 15, Dir => $dir, Gzip => $gzip, Flock => 'no', Persist => 'yes' ); $rollog1->rotate(); } elsif ( scalar @_ == 2 ) { my ($roll1, $roll2) = @_; my $rollog2 = new Logfile::Rotate( File => $roll1, Count => 15, Dir => $dir, Gzip => $gzip, Flock => 'no', Persist => 'yes' ); my $rollog2a = new Logfile::Rotate( File => $roll2, Count => 15, Dir => $dir, Gzip => $gzip, Flock => 'no', Persist => 'yes' ); $_->rotate() for ($rollog2, $rollog2a); } }
        later in my code I am '>>' to this same file from a system command called mksysb, so that looks like:

         system ("mksysb /dev/$rmt -A -e -m -p -X >> $mksysblog 2>&1");

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://897869]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2021-06-22 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (100 votes). Check out past polls.

    Notices?