App-plockf

 view release on metacpan or  search on metacpan

bin/plockf  view on Meta::CPAN

	sleep 1;
    }
}

sub handle_error ($) {
    my $exit = shift;
    unless ($silent) {
	if ($exit == EX_UNAVAILABLE) {
	    warn progname . ": cannot open $lock_file: $!\n";
	} else {
	    warn progname . ": $lock_file: already locked\n";
	}
    }
    exit $exit;
}

sub progname () {
    require File::Basename;
    File::Basename::basename($0);
}

bin/plockf  view on Meta::CPAN

=head1 EXIT STATUS

If B<plockf> successfully acquires the lock, it returns the exit status
produced by I<command>. Otherwise, it returns one of the exit
codes defined in L<sysexits(3)>, as follows:

=over

=item C<EX_TEMPFAIL> (75)

The specified lock I<file> was already locked by another process.

=item C<EX_CANTCREAT> (73)

The B<plockf> utility was unable to create the lock I<file>, e.g.,
because of insufficient access privileges.

=item C<EX_UNAVAILABLE> (69)

The C<-n> option is specified and the specified lock I<file> does not
exist.

t/plockf.t  view on Meta::CPAN

    ok !-f $lock_file, 'cleanup of lock file works';
}

{
    my $t0 = time;
    my $pid = run_blocking_process(3);
    my @cmd = (@full_script, '-t', 0, $lock_file, $^X, '-e1');
    my($ret, undef, $stderr) = run(\@cmd);
    is $ret, 75, 'lock error on -t 0'
	or diag "Time since run_blocking_process: " . (time-$t0);
    defined $stderr and like $stderr, qr{^plockf: .*plockf.lck: already locked$};
    if ($^O ne 'MSWin32') { # SIGTERM is problematic on Windows: http://stackoverflow.com/a/33216565/2332415
	kill TERM => $pid;
    }
    waitpid $pid, 0;
    ok !-f $lock_file, 'cleanup of lock file works';
}

{
    my $t0 = time;
    my $pid = run_blocking_process(3);

t/plockf.t  view on Meta::CPAN

    ok !-f $lock_file, 'cleanup of lock file works';
}

{
    my $t0 = time;
    my $pid = run_blocking_process(4);
    my @cmd = (@full_script, '-t', 0.2, $lock_file, $^X, '-e1');
    my($ret, undef, $stderr) = run(\@cmd);
    is $ret, 75, 'lock error on -t > 0s'
	or diag "Time since run_blocking_process: " . (time-$t0);
    defined $stderr and like $stderr, qr{^plockf: .*plockf.lck: already locked$};
    if ($^O ne 'MSWin32') {
	kill TERM => $pid;
    }
    waitpid $pid, 0;
    ok !-f $lock_file, 'cleanup of lock file works';
}

{
    my $t0 = time;
    my $pid = run_blocking_process(1);



( run in 0.501 second using v1.01-cache-2.11-cpan-49f99fa48dc )