From b5c447a3551bd280226d3b33e354bc41f68bf1ef Mon Sep 17 00:00:00 2001 From: espie Date: Fri, 2 Dec 2011 22:32:07 +0000 Subject: [PATCH] don't buffer printing to locks, to be able to get dependencies early gather needed=* lines from locks (may want to cache that info later, but I don't think it has any actual performance impact) --- infrastructure/lib/DPB/Locks.pm | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/infrastructure/lib/DPB/Locks.pm b/infrastructure/lib/DPB/Locks.pm index b8eba3d1956..21933792814 100644 --- a/infrastructure/lib/DPB/Locks.pm +++ b/infrastructure/lib/DPB/Locks.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Locks.pm,v 1.9 2011/11/13 22:18:04 espie Exp $ +# $OpenBSD: Locks.pm,v 1.10 2011/12/02 22:32:07 espie Exp $ # # Copyright (c) 2010 Marc Espie # @@ -48,6 +48,7 @@ sub dolock { my ($self, $name, $v) = @_; if (sysopen my $fh, $name, O_CREAT|O_EXCL|O_WRONLY, 0666) { + DPB::Util->make_hot($fh); print $fh "locked=", $v->logname, "\n"; $v->print_parent($fh); return $fh; @@ -103,5 +104,32 @@ sub recheck_errors } } +sub find_dependencies +{ + my ($self, $hostname) = @_; + opendir(my $dir, $self->{lockdir}); + my $h = {}; + while (my $name = readdir($dir)) { + my $fullname = $self->{lockdir}."/".$name; + next if -d $fullname; + next if $name =~ m/^host:/; + open(my $f, '<', $fullname); + my $host; + my @d; + while (<$f>) { + if (m/^host=(.*)/) { + $host = $1; + } elsif (m/^needed=(.*)/) { + @d = split(/\s/, $1); + } + } + if (defined $host && $host eq $hostname) { + for my $k (@d) { + $h->{$k} = 1; + } + } + } + return sort keys %$h; +} 1;