diff options
author | 2023-03-22 09:29:34 -0700 | |
---|---|---|
committer | 2023-03-22 09:29:34 -0700 | |
commit | a8e55ea71ba5602d791561c105310a53566f0503 (patch) | |
tree | 648fc6d6c56303e2d5f6f86b61bb61766f1ef3bc | |
parent | probe-mirmon: workaround: back to wget for FTP (diff) | |
download | gentoo-mirrorstats-a8e55ea71ba5602d791561c105310a53566f0503.tar.gz gentoo-mirrorstats-a8e55ea71ba5602d791561c105310a53566f0503.tar.bz2 gentoo-mirrorstats-a8e55ea71ba5602d791561c105310a53566f0503.zip |
probe-mirmon: cleanup
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
-rwxr-xr-x | probe-mirmon | 35 |
1 files 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; +} |