8 my $lockbase = shift; # suggested: $GL_REPO_BASE/$GL_REPO.git/.gl-mirror-push-lock.$SLAVE_NAME
9 my @cmd_plus_args = @ARGV; # the actual 'gitolite mirror ...' command
12 # ----------------------------------------------------------------------
14 open( my $fhrun, ">", "$lockbase.run" ) or die "open '$lockbase.run' failed: $!";
15 if ( flock( $fhrun, LOCK_EX
| LOCK_NB
) ) {
16 # got run lock; you're good to go
18 system(@cmd_plus_args);
20 flock( $fhrun, LOCK_UN
);
24 # "run" lock failed; someone is already running the command
26 open( my $fhqueue, ">", "$lockbase.queue" ) or die "open '$lockbase.queue' failed: $!";
27 if ( flock( $fhqueue, LOCK_EX
| LOCK_NB
) ) {
28 # got queue lock, now block waiting for "run" lock
29 flock( $fhrun, LOCK_EX
);
30 # got run lock, so take yourself out of "queue" state, then run
31 flock( $fhqueue, LOCK_UN
);
33 system(@cmd_plus_args);
35 flock( $fhrun, LOCK_UN
);
39 # "queue" lock also failed; someone is running AND someone is queued; we can go home
40 say STDERR
"INFO: nothing to do/queue; '$lockbase' already running and 1 in queue";