# HG changeset patch # User Heiko Schlittermann # Date 1466596156 -7200 # Node ID 20874d23e7edfa68eefd7a1ab782ea16467eb22d # Parent 05ef007278eb75f2e467a98ab17904ecc1214eea use open() for TMPFILE generation diff -r 05ef007278eb -r 20874d23e7ed lib/Nagios/Check/DNS/check_tlsa_record.pm --- a/lib/Nagios/Check/DNS/check_tlsa_record.pm Tue Jun 21 16:34:49 2016 +0200 +++ b/lib/Nagios/Check/DNS/check_tlsa_record.pm Wed Jun 22 13:49:16 2016 +0200 @@ -2,26 +2,31 @@ use strict; use warnings; -use feature qw(say switch); +use feature qw(say switch state); use Carp; use Data::Dumper; use if $ENV{DEBUG} => 'Smart::Comments'; #use if $^V >= v5.0.20 => (experimental => gw(smartmatch)); use experimental qw(smartmatch); -use File::Temp; use Fcntl qw(F_GETFD F_SETFD FD_CLOEXEC); our $VERSION = '0.1'; my $dane_pattern = qr'(?i)^(?(?\d+)\s+(?\d+)\s+(?\d+)\s+(?[0-9a-f ]+))$'; -# keep in in 'our' to avoid garbage collection and destruction -# of the File::Temp object -our $tmpfile = File::Temp->new(); +# Alternativly my $tmpfile = File::Temp->new(); +# unlink($tmpfile); +# if we need more # control over the directory, the name, and such. +# The sub _tmpfile_ has the sole purpose to use the $tmpfile in a +# *global* context. This prevents our garbage collector from closing the +# file! +open(my $tmpfile, '+>', undef) + or die "Can't open anonymous file: $!\n"; +fcntl($tmpfile, F_SETFD, fcntl($tmpfile, F_GETFD, 0) & ~FD_CLOEXEC) or die "clear FD_CLOEXEC on $tmpfile: $!\n"; +sub __tmpfile { $tmpfile } my $fdname = '/dev/fd/' . fileno $tmpfile; -fcntl($tmpfile, F_SETFD, fcntl($tmpfile, F_GETFD, 0) & ~FD_CLOEXEC) - or die "clear FD_CLOEXEC on $tmpfile: $!\n"; + sub main { my $domain = shift;