Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

file lock error

by dbs (Sexton)
on Apr 06, 2011 at 19:29 UTC ( #897866=perlquestion: print w/replies, xml ) Need Help??

dbs has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I am opening a few files like this:
use FileHandle; usr Fcntl; my $RLOG = new FileHandle "+>> $runlog"; my $MLOG = new FileHandle "+>> $mksysblog"; flock($RLOG, O_NONBLOCK) || warn "no NB lock $!"; flock($MLOG, O_NONBLOCK) || warn "no NB lock $!";
But I keep getting this error:  error: can not lock open: (1) my code giving this error is:
if ( scalar @_ == 1 ) { my $roll1 = @_; my $rollog1 = new Logfile::Rotate( File => $roll1, Count => 15, Dir => $dir, Gzip => $gzip, Flock => 'yes', Persist => 'yes' ); $rollog1->rotate(); }
plz help! thx!

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

    Valid arguments for flock are

    • LOCK_SH
    • LOCK_EX
    • LOCK_UN
    • LOCK_SH|LOCK_NB
    • LOCK_EX|LOCK_NB
    • LOCK_UN|LOCK_NB

    No idea what you meant by flock O_NONBLOCK.

      tried those, but it gave me an error
      Bareword "LOCK_SH" not allowed while "strict subs" in use at dlpar_mks +ysb-run.plx line 62. Bareword "LOCK_NB" not allowed while "strict subs" in use at dlpar_mks +ysb-run.plx line 62. Bareword "LOCK_SH" not allowed while "strict subs" in use at dlpar_mks +ysb-run.plx line 63. Bareword "LOCK_NB" not allowed while "strict subs" in use at dlpar_mks +ysb-run.plx line 63. dlpar_mksysb-run.plx had compilation errors.

        From the documentation to which I linked,

        import them from the Fcntl module, either individually, or as a group using the ':flock' tag.

        Add

        use Fcntl qw( :flock );

        as in the example

        DUP
Re: file lock error
by wind (Priest) on Apr 06, 2011 at 19:50 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?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (1)
As of 2021-05-18 04:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (173 votes). Check out past polls.

    Notices?