changed $fd setting .. our does not work like expected.. test
authorpesch
Tue, 21 Jun 2016 15:53:01 +0200
branchtest
changeset 30 38ba582383f2
parent 29 958202a7101b
child 31 750b25c76ab0
changed $fd setting .. our does not work like expected..
lib/Nagios/Check/DNS/check_tlsa_record.pm
--- a/lib/Nagios/Check/DNS/check_tlsa_record.pm	Tue Jun 21 14:10:20 2016 +0200
+++ b/lib/Nagios/Check/DNS/check_tlsa_record.pm	Tue Jun 21 15:53:01 2016 +0200
@@ -20,6 +20,7 @@
 my $dane_pattern = '^(?<record>(?<tlsa_usage>\d+)\s+(?<tlsa_selector>\d+)\s+(?<tlsa_match_type>\d+)\s+(?<tlsa_hash>[0-9a-f ]+))$';
 my $with_cname   = '^(?<cname>[_a-z]+.*\n).*';
 
+#our ($handle, $tempfile) = tempfile( # didn't work like expected
 my ($handle, $tempfile) = tempfile(
     TEMPLATE => 'XXXXXXXXXXXXXXXX',
     DIR      => '/tmp/',
@@ -27,8 +28,10 @@
 );
 
 
-my $fd = "/dev/fd/" . fileno $handle;
+my $fd; 
 my $flags = fcntl($handle, F_GETFD, 0);
+$flags &= ~FD_CLOEXEC;
+fcntl $handle, F_SETFD, $flags;
 
 sub main {
     my $domain   = shift;
@@ -78,10 +81,7 @@
     my $cmd;
     my $cert;
 
-    #neede here because global doesn't work like expected
-    #but if set here filediscriptor is open for writing
-    $flags &= ~FD_CLOEXEC;
-    fcntl $handle, F_SETFD, $flags;
+    $fd = "/dev/fd/" . fileno $handle;
 
     if ($port == 25) {
         $cmd = "openssl s_client -starttls smtp -connect $domain:$port";