NetBSD Problem Report #46713

From  Tue Jul 17 14:48:30 2012
Return-Path: <>
Received: from ( [])
	by (Postfix) with ESMTP id 9A23E63B882
	for <>; Tue, 17 Jul 2012 14:48:29 +0000 (UTC)
Message-Id: <>
Date: Tue, 17 Jul 2012 14:48:28 +0000 (UTC)
Subject: comm/p5-Device-SerialPort has 'status()' unnecessarily disabled
X-Send-Pr-Version: www-1.0

>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
>Last-Modified:  Mon Jul 23 18:30:08 +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.

From: Bernd Ernesti <>
Subject: Re: pkg/46713
Date: Mon, 23 Jul 2012 20:21:43 +0200

 ----- Forwarded message from Michai Ramakers <> -----

 Date: Mon, 23 Jul 2012 13:07:32 +0200
 From: Michai Ramakers <>
 Subject: suggest small change to pkg/46713

 in section 'Fix': '#ifndef' should be '#ifdef', sorry.

 (If I can change this myself, please let me know how.)


 ----- End forwarded message -----

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD:,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.