From nobody@FreeBSD.org  Tue Apr 23 07:21:55 2002
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 88FA637B417
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 23 Apr 2002 07:21:55 -0700 (PDT)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.6/8.11.6) id g3NELtI81692;
	Tue, 23 Apr 2002 07:21:55 -0700 (PDT)
	(envelope-from nobody)
Message-Id: <200204231421.g3NELtI81692@freefall.freebsd.org>
Date: Tue, 23 Apr 2002 07:21:55 -0700 (PDT)
From: Tom Limoncelli <tal@lumeta.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: /dev/MAKEDEV entry for RocketPort is broken
X-Send-Pr-Version: www-1.0

>Number:         37379
>Category:       i386
>Synopsis:       /dev/MAKEDEV entry for RocketPort is broken
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Apr 23 07:30:01 PDT 2002
>Closed-Date:    Wed Jun 01 03:02:41 GMT 2005
>Last-Modified:  Wed Jun 01 03:02:41 GMT 2005
>Originator:     Tom Limoncelli
>Release:        4.5-RELEASE
>Organization:
Lumeta Corp
>Environment:
FreeBSD scan2.prod.lumeta.com 4.5-RELEASE FreeBSD 4.5-RELEASE #0: Mon Feb 25 14:05:51 EST 2002     anon@devscan2:/usr/src/sys/compile/INT  i386
>Description:
The code in /dev/MAKEDEV to create the cuaR* and ttyR* devices is 
broken.

There are 2 bugs:

1) MAKEDEV assumes that only one "RocketPort = 32" will appear in the output of dmesg.  Not true if you have multiple cards or have rebooted many times.
As a result, $ndevices="32\n32\n32\n32\n" instead of "32", similar problem with $controllers.  The output looks like:

Creating 32
32
32
32
32 devices for RocketPort0: [: 32: unexpected operator

2)  The code relies on "dmesg" to find out what controllers exist.  I consider this to be a problem, albiet minor.  If the machine hasn't been rebooted in long enough that dmesg no longer mentions "RocketPort0 = 32" (or whatever) then the script fails.  (Hey, it actually happened to me.  We have very long uptimes.)  I don't see any other use of "dmesg" in MAKEDEV, so maybe this practice isn't encouraged.


>How-To-Repeat:
cd /dev
sh MAKEDEV cuaR31

Note: if you don't have a rocketport installed you might not get any output.  Change the dmesg command to "cat foo" where "foo" is a file that contains:

RocketPort = 32
RocketPort = 32
RocketPort = 32
RocketPort = 32

>Fix:
I fixed part 1 by passing the output of dmesg through "sort -u", but there has got to be a better way.  Maybe the script shouldn't try to be so smart and just create the entries.

Below is an ugly patch, but it works as long as you have rebooted recently.  Not usually a problem since MAKEDEV is usually run as part of initial setup of a machine.

# diff MAKEDEV.old MAKEDEV
1407c1407
<               dmesg | while read first rest; do
---
>               dmesg | /usr/bin/sort -u | while read first rest; do
1418c1418
<               dmesg | while read first bar ports rest; do
---
>               dmesg | /usr/bin/sort -u | while read first bar ports rest; do
1447c1447
<               dmesg | while read first rest; do
---
>               dmesg | /usr/bin/sort -u | while read first rest; do
1458c1458
<               dmesg | while read first bar ports rest; do
---
>               dmesg | /usr/bin/sort -u | while read first bar ports rest; do



>Release-Note:
>Audit-Trail:

From: Makoto Matsushita <matusita@jp.FreeBSD.org>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: i386/37379: /dev/MAKEDEV entry for RocketPort is broken
Date: Wed, 24 Apr 2002 19:33:23 +0900

 tal> I fixed part 1 by passing the output of dmesg through "sort -u",
 tal> but there has got to be a better way.  Maybe the script shouldn't
 tal> try to be so smart and just create the entries.
 
 What's happen if you insert "tail -1" instead of "sort -u"?  I don't
 have any RocketPort (I can't test your patch), but it seems that this
 code wants only the *last* entry.
 
 -- -
 Makoto `MAR' Matsushita

From: Tom Limoncelli <tal@lumeta.com>
To: freebsd-gnats-submit@FreeBSD.org, tal@lumeta.com
Cc:  
Subject: Re: i386/37379: /dev/MAKEDEV entry for RocketPort is broken
Date: Wed, 24 Apr 2002 07:43:40 -0400

 "tail -1" won't work because you might have multiple rocketports (in 
 which case "sort -u" would output
 "RocketPort0 = 32\nRocketPort1 = 32\n".
 

From: Tom Limoncelli <tal@lumeta.com>
To: freebsd-gnats-submit@FreeBSD.org, tal@lumeta.com
Cc:  
Subject: Re: i386/37379: /dev/MAKEDEV entry for RocketPort is broken
Date: Wed, 24 Apr 2002 07:45:26 -0400

 Note: the "0" was left out in the original submission.  Here's an 
 example that is cut-and-pasted to avoid typos:
 
 # dmesg|egrep Rock
 RocketPort0 = 32 ports
 RocketPort0 = 32 ports
 RocketPort0 = 32 ports
 RocketPort0 = 32 ports
 
 (this machine has been rebooted 4 times since dmesg was cleared)
 
State-Changed-From-To: open->closed 
State-Changed-By: rodrigc 
State-Changed-When: Wed Jun 1 03:02:00 GMT 2005 
State-Changed-Why:  
The MAKEDEV script is obsolete, since entries in /dev 
are created dynamically using DEVFS in FreeBSD 5.x and higher. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=37379 
>Unformatted:
