Bug 37379

Summary: /dev/MAKEDEV entry for RocketPort is broken
Product: Base System Reporter: Tom Limoncelli <tal>
Component: i386Assignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.5-RELEASE   
Hardware: Any   
OS: Any   

Description Tom Limoncelli 2002-04-23 15:30:01 UTC
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.

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
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
Comment 1 Makoto Matsushita 2002-04-24 11:33:23 UTC
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
Comment 2 Tom Limoncelli 2002-04-24 12:43:40 UTC
"tail -1" won't work because you might have multiple rocketports (in 
which case "sort -u" would output
"RocketPort0 = 32\nRocketPort1 = 32\n".
Comment 3 Tom Limoncelli 2002-04-24 12:45:26 UTC
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)
Comment 4 Craig Rodrigues freebsd_committer freebsd_triage 2005-06-01 04:02:00 UTC
State Changed
From-To: open->closed

The MAKEDEV script is obsolete, since entries in /dev 
are created dynamically using DEVFS in FreeBSD 5.x and higher.