From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 0560C15A7D9 for ; Wed, 22 Mar 2023 16:29:45 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 20276E07F9; Wed, 22 Mar 2023 16:29:44 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 08D9CE07F9 for ; Wed, 22 Mar 2023 16:29:44 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id ED003340834 for ; Wed, 22 Mar 2023 16:29:42 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 863D18E3 for ; Wed, 22 Mar 2023 16:29:41 +0000 (UTC) From: "Robin H. Johnson" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Robin H. Johnson" Message-ID: <1679502574.a8e55ea71ba5602d791561c105310a53566f0503.robbat2@gentoo> Subject: [gentoo-commits] proj/gentoo-mirrorstats:master commit in: / X-VCS-Repository: proj/gentoo-mirrorstats X-VCS-Files: probe-mirmon X-VCS-Directories: / X-VCS-Committer: robbat2 X-VCS-Committer-Name: Robin H. Johnson X-VCS-Revision: a8e55ea71ba5602d791561c105310a53566f0503 X-VCS-Branch: master Date: Wed, 22 Mar 2023 16:29:41 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 831f54d5-9db7-435a-a582-4b45074867ae X-Archives-Hash: 9542d9790095160b687c8a3f0e260ffa commit: a8e55ea71ba5602d791561c105310a53566f0503 Author: Robin H. Johnson gentoo org> AuthorDate: Wed Mar 22 16:29:34 2023 +0000 Commit: Robin H. Johnson gentoo 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 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; +}