pkgsrc-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

pkg/46713: comm/p5-Device-SerialPort has 'status()' unnecessarily disabled

>Number:         46713
>Category:       pkg
>Synopsis:       comm/p5-Device-SerialPort has 'status()' unnecessarily disabled
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jul 17 14:50:00 +0000 2012
>Originator:     Michai Ramakers
>Release:        6.0 BETA2
NetBSD dwarf 6.0_BETA2 NetBSD 6.0_BETA2 (MIC) #1: Sun Jun 24 22:05:29 CEST 2012 
 michai@dwarf:/usr/src/sys/arch/i386/compile/MIC i386
[ this is a verbatim copy of report upstream: ]


tested on NetBSD 6.0BETA2 / i386 and Device::SerialPort 1.04. I did not
test on Linux, although I think behaviour would be ok (see 'ANALYSIS':
ioctl 'TIOCINQ' is present in bits/ioctls.h on Linux systems, afaik).


'Device::SerialPort::status()' is inconveniently disabled as per
'can_status()', making it necessary to use 'Device::SerialPort::ioctl(
"TIOCOUTQ", \$num_byte )' to read the number of bytes pending write in
the output-buffer. 

If not necessary, it would IMHO be better to do this without explicit


Implementation of 'status()' (

  1870 sub status {
  1871     my $self = shift;
  1872     return if (@_);
  1873     return unless ($self->can_status);

(i.e. precondition for this function to work is 'can_status()' returning

Implementation of 'can_status()' (

   702 sub can_status {
   703     return 1 if (defined($bits->{'portable_TIOCINQ'}) &&
   704                  defined($bits->{'TIOCOUTQ'}));
   705     return 0;
   706     #return 0 unless ($incount && $outcount);
   707     #return 1;
   708 }

On NetBSD, 'TIOCOUTQ' is found at compile-time (namely, in

A pseudo-flag 'portable_TIOCINQ' is used instead of 'TIOCINQ'

    91 # Set alternate bit names
    92 $bits->{'portable_TIOCINQ'} = $bits->{'TIOCINQ'} ||

This is fine, since TIOCINQ and FIONREAD are the same, from what I

On NetBSD, TIOCINQ is not found at compile-time, but FIONREAD is
(namely, in /usr/include/sys/filio.h). 

The '$bits' hash is constructed in the build-process (SerialPort.xs):

   99 #ifdef TIOCINQ
  101 #endif
  102 #ifdef TIOCOUTQ
  104 #endif

However, a similar clause for 'FIONREAD' is not present - it seems the
fallback to 'FIONREAD' as substitute to 'TIOCINQ' was not completely


to get number of bytes in output-buffer, use
'Device::SerialPort::ioctl()' as alternative, as stated in the manual:

  my $mstat = " ";
  $my_serial_port->ioctl( 'TIOCOUTQ', \$mstat ) or die;
  my $count = unpack( 'L', $mstat );
  print "there are $count bytes pending write\n";

    1 #!/usr/pkg/bin/perl
    3 use strict;
    4 use warnings;
    5 use Device::SerialPort;
    7 my $port = Device::SerialPort->new( "/dev/ttyU0" ) or die;
    8 $port->can_status() or die;   # on NetBSD, execution fails here

(alternatively, list known ioctls using a oneliner - see suggested fix.)

add a clause for 'FIONREAD' to SerialPort.xs:

  #ifndef FIONREAD

To verify effect of fix without actually opening a port:

$ perl -MDevice::SerialPort -MData::Dumper -e 'print
Data::Dumper::Dumper Device::SerialPort::Bits::get_hash()' | grep FIONREAD

...returns nothing before, and returns 1 entry after the fix. 

I also verified the functionality of 'status()' after the fix w.r.t.
bytes in output-buffer, which worked fine.

Home | Main Index | Thread Index | Old Index