From: Marius Gavrilescu Date: Mon, 2 Dec 2013 14:38:27 +0000 (+0200) Subject: Use flock in ::Base instead of O_EXCL X-Git-Tag: 5999.000_001~41 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=1fc8d0246c090476d30bfde6085c092fb607f7ae;p=gruntmaster-daemon.git Use flock in ::Base instead of O_EXCL --- diff --git a/lib/Gruntmaster/Daemon.pm b/lib/Gruntmaster/Daemon.pm index ebab95c..ccf9e4e 100644 --- a/lib/Gruntmaster/Daemon.pm +++ b/lib/Gruntmaster/Daemon.pm @@ -55,7 +55,7 @@ sub process{ chdir $dir; mkdir "in"; for (<*>) { - cp $_, "in" unless $_ eq 'in' || $_ eq 'pidfile'; + cp $_, "in" unless $_ eq 'in'; } my @results; diff --git a/lib/Gruntmaster/Daemon/Base.pm b/lib/Gruntmaster/Daemon/Base.pm index b7db789..d63ddee 100644 --- a/lib/Gruntmaster/Daemon/Base.pm +++ b/lib/Gruntmaster/Daemon/Base.pm @@ -7,7 +7,7 @@ use parent qw/Exporter/; our @EXPORT_OK = qw/watch/; our $VERSION = '0.001'; -use Fcntl qw/O_WRONLY O_EXCL O_CREAT/; +use Fcntl qw/:flock/; use Linux::Inotify2; use Log::Log4perl qw/get_logger/; @@ -17,12 +17,14 @@ sub process{ my ($name, $dir, $cb) = @_; my $logger = get_logger; $logger->debug("Taking job $name..."); - if (sysopen my $file, "$dir/$name/pidfile", O_WRONLY | O_EXCL | O_CREAT){ + open my $file, ">>$dir/$name/meta.yml"; + if (flock my $file, LOCK_EX|LOCK_NB){ $logger->debug("Successfully taken job $name, executing callback"); $cb->("$dir/$name"); } else { $logger->debug("Job $name already taken"); } + close $file; } sub watch{