Perl Check - Need Help

Jerry Benton jerry.benton at mailborder.com
Sat Apr 8 05:52:09 UTC 2017


One last update to remove useless line.


  use IO::Socket::UNIX;

  sub KickMessage {
    my($queue2ids, $sendmail2) = @_;
    my($queue);

    # Do a kick for every queue that contains some message ids
    foreach $queue (keys %$queue2ids) {
      next unless $queue2ids->{$queue};

      my $pf_connection = '/var/spool/postfix/public/qmgr';
      
      if(-S $pf_connection){
      	# UNIX
	  	my $fh = IO::Socket::UNIX->new(
				 Type => SOCK_STREAM,
				 Peer => $pf_connection,
				 ) or
		MailScanner::Log::WarnLog("KickMessage coould not write to UNIX > $pf_connection");
		print $fh "I";
		close $fh;	
	  }elsif(-p $pf_connection){
	  	# FIFO
		open(my $fh, '>', $pf_connection) or
		MailScanner::Log::WarnLog("KickMessage coould not write to FIFO > $pf_connection");
		print $fh "I";
		close $fh;
	  }else{
	  	MailScanner::Log::WarnLog("Unable to determine socket type (FIFO/UNIX) > $pf_connection");
	  }
    }
    return 0;
  }


-
Jerry Benton
www.mailborder.com
+1 - 844-436-6245



> On Apr 8, 2017, at 1:46 AM, Jerry Benton <jerry.benton at mailborder.com> wrote:
> 
> I have it working under both FIFO and UNIX, so I guess I did it right. Final code for record keeper’s sake:
> 
> 
>   use IO::Socket::UNIX;
> 
>   sub KickMessage {
>     my($queue2ids, $sendmail2) = @_;
>     my($queue);
> 
>     # Do a kick for every queue that contains some message ids
>     foreach $queue (keys %$queue2ids) {
>       next unless $queue2ids->{$queue};
> 
>       my $pf_connection = '/var/spool/postfix/public/qmgr';
>       
>       if(-S $pf_connection){
>       	# UNIX
> 	  	my $fh = IO::Socket::UNIX->new(
> 				 Type => SOCK_STREAM,
> 				 Peer => $pf_connection,
> 				 ) or
> 		MailScanner::Log::WarnLog("KickMessage coould not write to UNIX > $pf_connection");
> 		print $fh "I";
> 		close $fh;	
> 	  }elsif(-p $pf_connection){
> 	  	# FIFO
> 		my $fh = new FileHandle;
> 		open(my $fh, '>', $pf_connection) or
> 		MailScanner::Log::WarnLog("KickMessage coould not write to FIFO > $pf_connection");
> 		print $fh "I";
> 		close $fh;
> 	  }else{
> 	  	MailScanner::Log::WarnLog("Unable to determine socket type (FIFO/UNIX) > $pf_connection");
> 	  }
>     }
>     return 0;
>   }
> 
> 
> -
> Jerry Benton
> www.mailborder.com <http://www.mailborder.com/>
> +1 - 844-436-6245
> 
> 
> 
>> On Apr 7, 2017, at 6:58 PM, Jerry Benton <jerry.benton at mailborder.com <mailto:jerry.benton at mailborder.com>> wrote:
>> 
>> I am trying to update some Perl code that checks if a socket is FIFO or UNIX and then executes appropriately. I am not entirely sure about the UNIX socket I am creating here. Can any Perl gurus chime in? 
>> 
>> use IO::Socket::UNIX;
>> 
>> 
>>      my $pf_connection = '/var/spool/postfix/public/qmgr';
>>      if(-p $pf_connection){
>> 		# FIFO
>> 		my $fh = new FileHandle;
>> 		$fh->open($pf_connection) or
>> 		MailScanner::Log::WarnLog("KickMessage coould not write to FIFO " .
>> 								  "%s, %s", "$public/qmgr", $!);
>> 		print $fh "I";
>> 		$fh->close;
>> 	  }elsif(-S $pf_connection){
>> 	  	# UNIX
>> 	  	my $fh = IO::Socket::UNIX->new(
>> 				 Type => SOCK_STREAM,
>> 				 Peer => $pf_connection,
>> 				 ) or
>> 		MailScanner::Log::WarnLog("KickMessage coould not write to UNIX " .
>> 								  "%s, %s", "$public/qmgr", $!);
>> 		print $fh "I";
>> 		$fh->close; 	
>> 	  }else{
>> 	  	MailScanner::Log::WarnLog("Unable to determine socket type (FIFO/UNIX) " .
>> 								  "%s, %s", "$public/qmgr", $!);
>> 	  }
>> 
>> 
>> 
>> -
>> Jerry Benton
>> www.mailborder.com <http://www.mailborder.com/>
>> +1 - 844-436-6245
>> 
>> 
>> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mailscanner.info/pipermail/mailscanner/attachments/20170408/8e08310e/attachment.html>


More information about the MailScanner mailing list