[asterisk-users] broken pipe in perl agi

Danny Nicholas danny at debsinc.com
Fri Jun 5 08:42:36 CDT 2009


You're on the right track, Steve but that didn't do it either.  Here is the
Perl snippet:
use strict;
use warnings;
my $towatch = $ARGV[0];
my $a=0;
my $retval=undef;
# show hints will get hint information from the dialplan
while ($a<1) {
   my $cmda = '/usr/sbin/asterisk -rx "core show hints"|';
   ####  Get Trunk Information ####
   my %lines;
   my $lineseq=0;
   $SIG{'PIPE'} = 'IGNORE';
   open (my $trunk_info,$cmda) or print STDOUT "Broken pipe\n";
   if ($trunk_info) {
      while (<$trunk_info>) {
         if ($_ =~ /internal/) {
            if ($_ =~ /$towatch/) {
               $lines{$lineseq} = $_;
               $lineseq++;
               }
            }
         }
      close $trunk_info;
      }
   sleep 2;

   for (my $i=0;$i<=$lineseq;$i++) {
      if ($lines{$i}) {
         my $c = unpack("x74 a16", $lines{$i});
         $c =~ s/\s//gx;
         $retval=1;
         print STDOUT "SET VARIABLE LINESTAT \"$c\" \r\n";
         <STDIN>;
         }
      }
   $a++;
   }
# if /var/run/asterisk.ctl is not mod 777, no result so we return a dummy
Idle
if (! $retval) {
   my $c = "Idle";
   print STDOUT "SET VARIABLE LINESTAT \"$c\" \r\n";
   <STDIN>;
   }
exit;

If there is an active call on the extension, it works.  If not, the "broken
pipe" message is returned.

-----Original Message-----
From: asterisk-users-bounces at lists.digium.com
[mailto:asterisk-users-bounces at lists.digium.com] On Behalf Of Steve Edwards
Sent: Thursday, June 04, 2009 6:37 PM
To: Asterisk Users Mailing List - Non-Commercial Discussion
Subject: Re: [asterisk-users] broken pipe in perl agi

On Thu, 4 Jun 2009, Danny Nicholas wrote:

> Here's what I got from agi debug:
> agi debug
> AGI Debugging Enabled
> *CLI> AGI Tx >> agi_request: hintcheck.agi

[snip]

> AGI Rx << SET VARIABLE LINESTAT="Idle"
> AGI Tx >> 200 result=1
> [Jun  4 13:33:42] ERROR[28261]: utils.c:979 ast_carefulwrite: write()
> returned error: Broken pipe

I'm guessing you're not reading the last "200 result=1" before exiting or 
closing the pipe.

Thanks in advance,
------------------------------------------------------------------------
Steve Edwards      sedwards at sedwards.com      Voice: +1-760-468-3867 PST
Newline                                             Fax: +1-760-731-3000

_______________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users




More information about the asterisk-users mailing list