Perl Check - Need Help
Jerry Benton
jerry.benton at mailborder.com
Sat Apr 8 16:06:42 UTC 2017
Yes. I updated the code already and tested it. This will be the final. Thanks for taking a look.
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_dir = $queue;
$pf_dir =~ s/[^\/]+$/public/;
$pf_dir = "$pf_dir/qmgr";
if(-S $pf_dir){
# UNIX
my $fh = IO::Socket::UNIX->new(
Type => SOCK_STREAM,
Peer => $pf_dir,
) or
MailScanner::Log::WarnLog("KickMessage coould not write to UNIX > $pf_dir");
print $fh "I";
close $fh;
}elsif(-p $pf_dir){
# FIFO
open(my $fh, '>', $pf_dir) or
MailScanner::Log::WarnLog("KickMessage coould not write to FIFO > $pf_dir");
print $fh "I";
close $fh;
}else{
MailScanner::Log::WarnLog("Unable to determine socket type (FIFO/UNIX) > $pf_dir");
}
}
return 0;
}
-
Jerry Benton
www.mailborder.com
+1 - 844-436-6245
> On Apr 8, 2017, at 7:10 AM, Shawn Iverson <iversons at rushville.k12.in.us> wrote:
>
> Hi Jerry,
>
> Just looked over your code. It looks straightforward and complete to me.
>
> My only question I may have is "/var/spool/postfix/public/qmgr" being hard coded. Is it possible for this path to vary depending on the postfix configuration on other systems?
>
> On Sat, Apr 8, 2017 at 1:52 AM, Jerry Benton <jerry.benton at mailborder.com <mailto:jerry.benton at mailborder.com>> wrote:
> 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 <http://www.mailborder.com/>
> +1 - 844-436-6245 <tel:(844)%20436-6245>
>
>
>
>> On Apr 8, 2017, at 1:46 AM, Jerry Benton <jerry.benton at mailborder.com <mailto: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 <tel:(844)%20436-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 <tel:(844)%20436-6245>
>>>
>>>
>>>
>>
>
>
>
>
> --
> MailScanner mailing list
> mailscanner at lists.mailscanner.info <mailto:mailscanner at lists.mailscanner.info>
> http://lists.mailscanner.info/mailman/listinfo/mailscanner <http://lists.mailscanner.info/mailman/listinfo/mailscanner>
>
>
>
>
>
> --
> Shawn Iverson
> Director of Technology
> Rush County Schools
> 765-932-3901 x271
> iversons at rushville.k12.in.us <mailto:iversons at rushville.k12.in.us>
>
>
>
>
> --
> MailScanner mailing list
> mailscanner at lists.mailscanner.info
> http://lists.mailscanner.info/mailman/listinfo/mailscanner
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mailscanner.info/pipermail/mailscanner/attachments/20170408/ccc64638/attachment.html>
More information about the MailScanner
mailing list