From a8e55ea71ba5602d791561c105310a53566f0503 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Wed, 22 Mar 2023 09:29:34 -0700 Subject: probe-mirmon: cleanup Signed-off-by: Robin H. Johnson --- 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; +} -- cgit v1.2.3-65-gdbad