[check_postgres] [commit] Call File::Temp::cleanup() explicitly, as CLEANUP => 1 on tempdir()

Chris Butler chrisb at zedcore.com
Thu Nov 6 17:56:42 UTC 2008


On Thu, Oct 09, 2008 at 02:35:17PM -0400, check_postgres at bucardo.org wrote:
> Committed by Greg Sabino Mullane <greg at endpoint.com>
> 
> Call File::Temp::cleanup() explicitly, as CLEANUP => 1 on tempdir()
> creates an END block that is not always reached on some systems.
> Per report by sb at nnx.com.

I've just updated to the latest version on our servers, and this change
caused the checks to start failing.

It turns out that the version of File::Temp bundled with CentOS3 and CentOS4
doesn't have the 'cleanup' method.

My fix was to put 'eval' around the calls to File::Temp::cleanup(), so that
the call fails silently when File::Temp is an older version. The files still
get cleaned up with the END block on those systems, so it shouldn't leave
temp files lying around.

Index: check_postgres.pl
===================================================================
--- check_postgres.pl	(revision 32)
+++ check_postgres.pl	(revision 33)
@@ -303,7 +303,7 @@
 
 ## We don't (usually) want to die, but want a graceful Nagios-like exit instead
 sub ndie {
-	File::Temp::cleanup();
+	eval { File::Temp::cleanup(); };
 	my $msg = shift;
 	chomp $msg;
 	print "ERROR: $msg\n";
@@ -1139,7 +1139,7 @@
 	close $errfh or ndie qq{Could not close $errorfile: $!\n};
 	close $tempfh or ndie qq{Could not close $tempfile: $!\n};
 
-	File::Temp::cleanup();
+	eval { File::Temp::cleanup(); };
 
 	$info->{hosts} = keys %host;
 
-- 
Chris Butler
Zedcore Systems Ltd
UK tel: 0114 238 1828 ext 72


More information about the Check_postgres mailing list