Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^4: file lock error

by dbs (Sexton)
on Apr 06, 2011 at 20:24 UTC ( #897881=note: print w/replies, xml ) Need Help??


in reply to Re^3: file lock error
in thread file lock error

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");

Replies are listed 'Best First'.
Re^5: file lock error
by ikegami (Pope) on Apr 06, 2011 at 20:30 UTC

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

    That can't be. That error is only given when Flock is 'yes' or not specified.

    if( $self->{'Flock'} eq 'yes'){ $self->{'Fh'} = new IO::File "$self->{'File'}", O_WRONLY|O_EXC +L; croak "error: can not lock open: ($self->{'File'})" unless defined($self->{'Fh'}); flock($self->{'Fh'},LOCK_EX); }

    But that doesn't matter. First, don't tell it not to lock.

    Second, it's telling you it's having problem locking file "1". Is your log file really named 1? That's the file name you gave to it. One error is using

    my $roll1 = @_;

    when you mean to use

    my ($roll1) = @_;

    An array in scalar context returns the number of elements in the array.

    Fix:

    sub _logroll { eval 'use Compress::Zlib'; my $gzip = $@ ? '/usr/bin/gzip' : 'lib'; for my $log_file ( @_ ) { my $rotator = Logfile::Rotate->new( File => $log_file, Count => 15, Dir => $dir, Gzip => $gzip, Flock => 'yes', Persist => 'yes' ); $rotator->rotate(); } }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2021-04-23 16:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?