commit: a8e55ea71ba5602d791561c105310a53566f0503
Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
AuthorDate: Wed Mar 22 16:29:34 2023 +0000
Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Wed Mar 22 16:29:34 2023 +0000
URL:
https://gitweb.gentoo.org/proj/gentoo-mirrorstats.git/commit/?id=a8e55ea7
probe-mirmon: cleanup
Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>
probe-mirmon | 35 +++++++++++++++++++++++++++--------
1 file changed, 27 insertions(+), 8 deletions(-)
diff --git a/probe-mirmon b/probe-mirmon
index a40be16..233b6a3 100755
--- a/probe-mirmon
+++ b/probe-mirmon
@@ -76,7 +76,15 @@ sub handle_wget {
my ( $timeout, $url ) = @_;
# TODO: replace this with native HTTP
# TODO: munge the output!
- exec {'/usr/bin/wget'} 'wget', qw( -q --passive-ftp -O - -T ), $timeout,
'-t', 1, $url;
+ # kill -9 wget when it gets really stuck.
+ my $tmpdir = File::Tempdir->new();
+ my $dir = $tmpdir->name;
+ my $file = $url;
+
+ $file =~ s/\W/_/g; # translate all non-letters to _
+ system {'/usr/bin/timeout'} qw(--preserve-status -s KILL -k ), ($timeout +
1), ($timeout + 0.5),
+ 'wget', qw( -q --passive-ftp -T ), $timeout, '-t', 1, '-O',
"$dir/$file", $url;
+ slurp_and_output("$dir/$file");
}
sub handle_rsync {
@@ -90,20 +98,18 @@ sub handle_rsync {
# https://stackoverflow.com/a/6331618/1583179
my ($stdout, $stderr, $ret) = capture {
- system '/usr/bin/rsync', qw( -q --no-motd --timeout ), $timeout, $url,
"$dir/$file";
+ system {'/usr/bin/rsync'} qw( -q --no-motd --timeout ), $timeout, $url,
"$dir/$file";
};
+ #print "STDOUT: $stdout\n";
+ #print "STDERR $stderr\n";
+ #print "RET: $ret\n";
if ($ret!=0) {
#warn "rsync failed, exit code $fail, $! $? $@\n";
#exit $ret;
exit 800;
}
- open my $fh, '<', "$dir/$file" or do {
- warn "Opening Downloaded timestamp Failed";
- exit 900; # rediculous exit code.
- };
-
- print munge_date(<$fh>);
+ slurp_and_output("$dir/$file");
exit 0;
}
@@ -123,3 +129,16 @@ sub munge_date {
}
return -1;
}
+
+sub slurp_and_output {
+ my $filename = shift;
+ open my $fh, '<', $filename or do {
+ warn "Opening Downloaded timestamp Failed";
+ exit 900; # rediculous exit code.
+ };
+ my $line = <$fh>;
+ #print "RAW: $line\n";
+
+ print munge_date($line), "\n";
+ exit 0;
+}