| 1 |
#!/usr/bin/perl |
|---|
| 2 |
# Copyright (c) 2006, 2007 Software Freedom Law Center, Inc. |
|---|
| 3 |
# |
|---|
| 4 |
# This software gives you freedom; it is licensed to you under version 3 |
|---|
| 5 |
# of the GNU General Public License. |
|---|
| 6 |
# |
|---|
| 7 |
# This software is distributed WITHOUT ANY WARRANTY, without even the |
|---|
| 8 |
# implied warranties of MERCHANTABILITY and FITNESS FOR A PARTICULAR |
|---|
| 9 |
# PURPOSE. See the GNU General Public License for further details. |
|---|
| 10 |
# |
|---|
| 11 |
# You should have received a copy of the GNU General Public License, |
|---|
| 12 |
# version 3. If not, see <http://www.gnu.org/licenses/> |
|---|
| 13 |
# |
|---|
| 14 |
# License: GPLv3-only |
|---|
| 15 |
|
|---|
| 16 |
# update-loblaw-test.plx, when it did its work right from the post-commit |
|---|
| 17 |
# hook, ran too long. Plus, there were probably race conditions that I |
|---|
| 18 |
# hadn't realized were there, too. Under this way of doing things, I |
|---|
| 19 |
# pass the commit immediately without error, and update-loblaw-test.plx |
|---|
| 20 |
# picks up the data as it comes. |
|---|
| 21 |
|
|---|
| 22 |
use strict; |
|---|
| 23 |
use warnings; |
|---|
| 24 |
|
|---|
| 25 |
use Fcntl; |
|---|
| 26 |
|
|---|
| 27 |
my $PIPE_FILE = "/home/svn/pipes/loblaw-update"; |
|---|
| 28 |
|
|---|
| 29 |
############################################################################### |
|---|
| 30 |
use Unix::Syslog qw(:subs); |
|---|
| 31 |
use Unix::Syslog qw(:macros); |
|---|
| 32 |
use Carp; |
|---|
| 33 |
{ |
|---|
| 34 |
my $PAGE_EMAIL = 'root@softwarefreedom.org'; |
|---|
| 35 |
my %messageHistory; |
|---|
| 36 |
|
|---|
| 37 |
sub WarnLog ($) { |
|---|
| 38 |
my($message) = @_; |
|---|
| 39 |
|
|---|
| 40 |
use Date::Manip; |
|---|
| 41 |
my $NOW = ParseDate("now"); |
|---|
| 42 |
syslog LOG_INFO, $message; |
|---|
| 43 |
|
|---|
| 44 |
my $lastTime = $messageHistory{$message}; |
|---|
| 45 |
|
|---|
| 46 |
my $sendIt = 0; |
|---|
| 47 |
if (not defined $lastTime) { |
|---|
| 48 |
$sendIt = 1; |
|---|
| 49 |
} else { |
|---|
| 50 |
my $err; |
|---|
| 51 |
my $sinceLast = DateCalc($lastTime,"+ 10 minutes",\$err); |
|---|
| 52 |
$sendIt = 1 if ($NOW gt $sinceLast); |
|---|
| 53 |
} |
|---|
| 54 |
if ($sendIt) { |
|---|
| 55 |
open(SENDMAIL, "|/usr/sbin/sendmail -f root\@softwarefreedom.org -t"); |
|---|
| 56 |
print SENDMAIL "To: $PAGE_EMAIL\nFrom: root\@softwarefreedom.org\n", |
|---|
| 57 |
close(SENDMAIL); |
|---|
| 58 |
if ($? != 0) { |
|---|
| 59 |
syslog LOG_INFO, "Unable to perform sendmail: $!"; |
|---|
| 60 |
} else { |
|---|
| 61 |
$messageHistory{$message} = $NOW; |
|---|
| 62 |
} |
|---|
| 63 |
} |
|---|
| 64 |
die "$message"; |
|---|
| 65 |
} |
|---|
| 66 |
} |
|---|
| 67 |
############################################################################### |
|---|
| 68 |
|
|---|
| 69 |
my($repository, $revision) = @ARGV; |
|---|
| 70 |
|
|---|
| 71 |
WarnLog("\"$0 @ARGV\" called with bad repository and/or revision") |
|---|
| 72 |
unless defined $repository and |
|---|
| 73 |
defined $revision and $revision =~ /^\s*\d+\s*/; |
|---|
| 74 |
|
|---|
| 75 |
# Only operate if it is in our repository |
|---|
| 76 |
|
|---|
| 77 |
exit 0 unless $repository =~ m|Repository/loblaw\s*$|; |
|---|
| 78 |
|
|---|
| 79 |
sysopen(FIFO, $PIPE_FILE, O_WRONLY) |
|---|
| 80 |
or WarnLog("cannot open $PIPE_FILE for writing: $!"); |
|---|
| 81 |
|
|---|
| 82 |
print FIFO "REPOSITORY: \"$repository\" REVISION: $revision\n"; |
|---|
| 83 |
close FIFO; |
|---|
| 84 |
my $val = $?; |
|---|
| 85 |
WarnLog("Got $val exit code while trying to pass data to $PIPE_FILE: $!") |
|---|
| 86 |
unless ($val == 0); |
|---|
| 87 |
|
|---|
| 88 |
exit $val; |
|---|
| 89 |
__END__ |
|---|
| 90 |
############################################################################### |
|---|
| 91 |
# |
|---|
| 92 |
# Local variables: |
|---|
| 93 |
# compile-command: "perl -c post-hook-loblaw-test-feed.plx" |
|---|
| 94 |
# End: |
|---|
| 95 |
# |
|---|