Skip to content

Instantly share code, notes, and snippets.

@davel
Created February 10, 2012 11:22
Show Gist options
  • Save davel/1788840 to your computer and use it in GitHub Desktop.
Save davel/1788840 to your computer and use it in GitHub Desktop.
my $pid;
my $timed_out;
local $SIG{ALRM} = sub {
$timed_out = 1;
warn "all went wrong";
kill(9, $pid) if $pid;
};
alarm(30);
$pid = fork();
die "yikes: $!" unless defined $pid;
unless ($pid) {
open(my $fh, "<", $filename) or die $!;
exit 0;
}
waitpid $pid, 0;
alarm(0);
if ($timed_out or $?) {
... what we do when we've lost NFS
}
else {
... nfs good
}
@drrk
Copy link

drrk commented Feb 10, 2012

my $filename = $CONFIG->{healthcheck_base};
my $timed_out;
local $SIG{ALRM} = sub {
$timed_out = 1;if
warn "all went wrong"
};
alarm(6);

my $pid = fork();
die "yikes: $!" unless defined $pid;

unless ($pid) {
open(my $fh, "<", $filename) or die $!;
}

try {
waitpid $pid, 0;
}
catch {
warn $_;
};

alarm(0);

if ($timed_out or $?) {
$return=1;
}
else {
$return = 0;
}

ok( $return, 'NFS mount ok' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment