linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* remove bashisms from hotplug
@ 2003-11-25 13:45 Marco d'Itri
  2003-11-25 17:34 ` Chris Larson
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Marco d'Itri @ 2003-11-25 13:45 UTC (permalink / raw)
  To: linux-hotplug

[-- Attachment #1: Type: text/plain, Size: 158 bytes --]

These patches remove bashisms from hotplug (tested with the debian dash
shell) and add (partial) support for sysfs.

-- 
ciao, |
Marco | [3276 svFzLScsoTJLw]

[-- Attachment #2: posix-shell1.diff --]
[-- Type: text/plain, Size: 7445 bytes --]

diff -urN hotplug.orig/hotplug.functions hotplug/hotplug.functions
--- hotplug.orig/hotplug.functions	2003-10-07 23:15:38.000000000 +0200
+++ hotplug/hotplug.functions	2003-10-28 21:55:50.000000000 +0100
@@ -47,17 +47,6 @@
     mesg "$@"
 }
 
-#
-# The modules.*map parsing uses BASH ("declare -i") and some version
-# of AWK, typically /bin/gawk.  Most GNU/Linux distros have these,
-# but some specialized ones (floppy based, etc) may not.  ("type -p"
-# is also a bash-ism, more robust than "which".)
-#
-AWK=`type -p gawk`
-if [ "$AWK" = "" ]; then
-    AWK=`type -p awk`
-fi
-
 
 #
 # Not "modprobe --autoclean" ... one driver module can handle many
diff -urN hotplug.orig/ieee1394.agent hotplug/ieee1394.agent
--- hotplug.orig/ieee1394.agent	2003-09-16 21:42:17.000000000 +0200
+++ hotplug/ieee1394.agent	2003-10-28 21:49:52.000000000 +0100
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # IEEE1394-specific hotplug policy agent.
 #
@@ -24,7 +24,7 @@
 #
 
 cd /etc/hotplug
-. hotplug.functions
+. ./hotplug.functions
 # DEBUG=yes export DEBUG
 
 # generated by modutils 2.4.9 or later, for 2.4.10 and later kernels
@@ -39,12 +39,10 @@
 fi
 
 
-declare -i device_vendor_id device_specifier_id device_version
-device_vendor_id="0x$VENDOR_ID"
-device_specifier_id="0x$SPECIFIER_ID"
-device_version="0x$VERSION"
+device_vendor_id=$((0x$VENDOR_ID))
+device_specifier_id=$((0x$SPECIFIER_ID))
+device_version=$((0x$VERSION))
 
-declare -i MATCH_VENDOR_ID MATCH_SPECIFIER_ID MATCH_VERSION
 MATCH_VENDOR_ID=0x0001
 MATCH_SPECIFIER_ID=0x0004
 MATCH_VERSION=0x0008
@@ -56,8 +54,11 @@
 ieee1394_map_modules ()
 {
     local module ignored
-    declare -i match_flags vendor_id model_id
-    declare -i specifier_id version
+
+    # convert from hex to dec
+    match_flags=$(($match_flags))
+    vendor_id=$(($vendor_id)); model_id=$(($model_id))
+    specifier_id=$(($specifier_id)); version=$(($version))
 
     # comment line lists (current) pci_device_id field names
     read ignored
@@ -98,7 +99,7 @@
     	load_drivers ieee1394 $MAP_CURRENT "$LABEL"
     fi
 
-    if [ "$DRIVERS" == "" ]; then
+    if [ "$DRIVERS" = "" ]; then
 	mesg "... no drivers for $LABEL"
 	exit 2
     fi
diff -urN hotplug.orig/pci.agent hotplug/pci.agent
--- hotplug.orig/pci.agent	2003-09-16 21:42:17.000000000 +0200
+++ hotplug/pci.agent	2003-10-28 21:49:56.000000000 +0100
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # PCI-specific hotplug policy agent.
 #
@@ -33,7 +33,7 @@
 #
 
 cd /etc/hotplug
-. hotplug.functions
+. ./hotplug.functions
 
 # generated by modutils, for current 2.4.x kernels
 MAP_CURRENT=$MODULE_DIR/modules.pcimap
@@ -57,31 +57,22 @@
 # extra filtering.
 #
 
-# inputs to the match algorithm, from kernel by way of /sbin/hotplug
-declare -i pci_class
-declare -i pci_id_vendor pci_id_device
-declare -i pci_subid_vendor pci_subid_device
-
+# convert from hex to dec the input values passed by the kernel to
+# /sbin/hotplug
 pci_convert_vars ()
 {
-    if [ "$AWK" = "" ]; then
-	mesg "can't find awk!"
-	exit 1
-    fi
+    pci_class=$((0x$PCI_CLASS))
 
-    pci_class=0x$PCI_CLASS
-
-    set `echo $PCI_ID | $AWK -F: '{print "0x" $1, "0x" $2 }'` ''
-    pci_id_vendor=$1
-    pci_id_device=$2
-
-    set `echo $PCI_SUBSYS_ID | $AWK -F: '{print "0x" $1, "0x" $2 }'` ''
-    pci_subid_vendor=$1
-    pci_subid_device=$2
+    set $(echo $PCI_ID | sed -e 's/\([^:]*\):\(.*\)/\1 \2/')
+    pci_id_vendor=$((0x$1))
+    pci_id_device=$((0x$2))
+
+    set $(echo $PCI_SUBSYS_ID | sed -e 's/\([^:]*\):\(.*\)/\1 \2/')
+    pci_subid_vendor=$((0x$1))
+    pci_subid_device=$((0x$2))
 }
 
-declare -i PCI_ANY
-PCI_ANY=0xffffffff
+PCI_ANY=$((0xffffffff))
 
 
 #
@@ -90,12 +81,7 @@
 #
 pci_map_modules ()
 {
-    # convert the usb_device_id fields to integers as we read them 
     local module ignored
-    declare -i vendor device
-    declare -i subvendor subdevice
-    declare -i class class_mask
-    declare -i class_temp
 
     # comment line lists (current) pci_device_id field names
     read ignored
@@ -110,6 +96,11 @@
 	\#*) continue ;;
 	esac
 
+	# convert the fields from hex to dec
+	vendor=$(($vendor)); device=$(($device))
+	subvendor=$(($subvendor)); subdevice=$(($subdevice))
+	class=$(($class)); class_mask=$(($class_mask))
+
 	: checkmatch $module
 
 	: vendor $vendor $pci_id_vendor
@@ -129,7 +120,7 @@
 	    continue
 	fi
 
-	class_temp="$pci_class & $class_mask"
+	class_temp=$(($pci_class & $class_mask))
 	if [ $class_temp -eq $class ]; then
 	    DRIVERS="$module $DRIVERS"
 	    : drivers $DRIVERS
@@ -154,7 +145,7 @@
     	load_drivers pci $MAP_CURRENT "$LABEL"
     fi
 
-    if [ "$DRIVERS" == "" ]; then
+    if [ "$DRIVERS" = "" ]; then
 	mesg "... no modules for $LABEL"
 	exit 2
     fi
diff -urN hotplug.orig/pci.rc hotplug/pci.rc
--- hotplug.orig/pci.rc	2003-06-06 20:27:23.000000000 +0200
+++ hotplug/pci.rc	2003-10-28 21:57:33.000000000 +0100
@@ -9,51 +9,58 @@
 PATH=/sbin:/bin:/usr/sbin:/usr/bin
 
 cd /etc/hotplug
-
-# source function library
-if [ -f /etc/init.d/functions ]; then
-	. /etc/init.d/functions
-elif [ -f /etc/rc.d/init.d/functions ]; then
-	. /etc/rc.d/init.d/functions
-fi
-
-. hotplug.functions
-
-
-# # override any of the defaults?
-# if [ -f /etc/sysconfig/pci ]; then
-#     . /etc/sysconfig/pci
-# fi
+. ./hotplug.functions
 
 pci_boot_events ()
 {
-    #
-    # FIXME on 2.5, /sys/bus/pci/devices gives some of this
-    # information, and more can be gotten with 'lspci'.
-    # don't expect pcimodules to exist!!
-    #
-    LISTER=`type -p pcimodules`
-    if [ "$LISTER" = "" -o ! -f /proc/bus/pci/devices -o ! -x pci.agent ]; then
-	    echo $"** can't synthesize pci hotplug events"
-	    return
-    fi
-
     # make sure the pci agent will run
     ACTION=add
     PCI_CLASS=0
     PCI_ID=0:0
-    PCI_SLOT=0:0.0
     PCI_SUBSYS_ID=0:0
-    export ACTION PCI_CLASS PCI_ID PCI_SLOT PCI_SUBSYS_ID
+    PCI_SLOT_NAME=0:0.0
+    export ACTION PCI_CLASS PCI_ID PCI_SLOT_NAME PCI_SUBSYS_ID
+
+    if [ -d /sys/bus/pci/devices/ ]; then
+	# 2.6 kernels
+
+	cd /sys/bus/pci/devices/
+	for PCI_DEVICE in *; do
+	    set `echo $PCI_DEVICE \
+		| sed -e 's/\([^:]*\):\(.*\):\(.*\)\.\(.*\)/\1 \2 \3 \4/'`
+	    PCI_SLOT_NAME=$2:$3.$4
+	    PCI_CLASS="`cat $PCI_DEVICE/class`"
+	    PCI_CLASS=${PCI_CLASS#0x}
+	    vendor_id=`cat $PCI_DEVICE/vendor`
+	    device_id=`cat $PCI_DEVICE/device`
+	    PCI_ID="${vendor_id#0x}:${device_id#0x}"
+	    sub_vendor_id=`cat $PCI_DEVICE/subsystem_vendor`
+	    sub_device_id=`cat $PCI_DEVICE/subsystem_device`
+	    PCI_SUBSYS_ID="${sub_vendor_id#0x}:${sub_device_id#0x}"
 
-    # these notifications will be handled by pcimodules
-    for BUS in `cd /proc/bus/pci;find * -type d -print`; do
-	for SLOT_FUNC in `cd /proc/bus/pci/$BUS; echo *`; do
-	    PCI_SLOT=$BUS:$SLOT_FUNC
-	    : hotplug pci for $PCI_SLOT
+	    debug_mesg "Detected $PCI_DEVICE $PCI_ID ($PCI_SUBSYS_ID, $PCI_CLASS)"
 	    /sbin/hotplug pci
 	done
-    done
+
+    else
+
+	LISTER=`type -p pcimodules`
+	if [ "$LISTER" = "" -o ! -f /proc/bus/pci/devices -o ! -x pci.agent ]; then
+	    echo $"** can't synthesize pci hotplug events"
+	    return
+	fi
+
+	# these notifications will be handled by pcimodules
+	for BUS in `cd /proc/bus/pci;find * -type d -print`; do
+	    for SLOT_FUNC in `cd /proc/bus/pci/$BUS; echo *`; do
+		PCI_SLOT_NAME=$BUS:$SLOT_FUNC
+		: hotplug pci for $PCI_SLOT_NAME
+		/sbin/hotplug pci
+	    done
+	done
+
+    fi
+    return 0
 }
 
 # See how we were called.

[-- Attachment #3: posix-shell2.diff --]
[-- Type: text/plain, Size: 14214 bytes --]

diff -urN hotplug.orig1/firmware.agent hotplug/firmware.agent
--- hotplug.orig1/firmware.agent	2003-10-07 21:34:19.000000000 +0200
+++ hotplug/firmware.agent	2003-10-29 02:24:31.000000000 +0100
@@ -16,7 +16,7 @@
 #
 
 cd /etc/hotplug
-. hotplug.functions
+. ./hotplug.functions
 # DEBUG=yes export DEBUG
 
 # directory of the firmware files
diff -urN hotplug.orig1/input.agent hotplug/input.agent
--- hotplug.orig1/input.agent	2003-10-14 01:52:54.000000000 +0200
+++ hotplug/input.agent	2003-10-29 22:23:16.000000000 +0100
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # input-specific hotplug policy agent.
 #
@@ -30,7 +30,7 @@
 #
 
 cd /etc/hotplug
-. hotplug.functions
+. ./hotplug.functions
 # DEBUG=yes export DEBUG
 
 # generated by module-init-tools
@@ -51,14 +51,16 @@
 # Each modules.inputmap format line corresponds to one entry in a
 # MODULE_DEVICE_TABLE(input,...) declaration in a kernel file.
 #
-declare -i matchBits=0
-declare -i i_bustype=0 i_vendor=0 i_product=0 i_version=0
-declare -i i_evBits=0
-declare i_keyBits i_relBits i_absBits i_mscBits i_ledBits i_sndBits i_ffBits
+matchBits=0
+i_bustype=0
+i_vendor=0
+i_product=0
+i_version=0
+i_evBits=0
 
 input_join_words ()
 {
-    declare name=$1 array=$2 tmp
+    local name="$1" array="$2" tmp
     if [ "$array" = '' ]; then
 	return
     fi
@@ -81,14 +83,14 @@
 	IFS=/
 	set $PRODUCT ''
 	IFS="$DEFAULT_IFS"
-	i_bustype=0x$1
-	i_vendor=0x$2
-	i_product=0x$3
-	i_version=0x$4
+	i_bustype=$((0x$1))
+	i_vendor=$((0x$2))
+	i_product=$((0x$3))
+	i_version=$((0x$4))
     fi
 
     if [ "$EV" != "" ]; then
-	i_evBits=0x$EV
+	i_evBits=$((0x$EV))
     fi
 
     input_join_words i_keyBits "$KEY"
@@ -100,27 +102,26 @@
     input_join_words i_ffBits  "$FF"
 }
 
-declare -i INPUT_DEVICE_ID_MATCH_BUS=1
-declare -i INPUT_DEVICE_ID_MATCH_VENDOR=2
-declare -i INPUT_DEVICE_ID_MATCH_PRODUCT=4
-declare -i INPUT_DEVICE_ID_MATCH_VERSION=8
-declare -i INPUT_DEVICE_ID_MATCH_EVBIT=0x010
-declare -i INPUT_DEVICE_ID_MATCH_KEYBIT=0x020
-declare -i INPUT_DEVICE_ID_MATCH_RELBIT=0x040
-declare -i INPUT_DEVICE_ID_MATCH_ABSBIT=0x080
-declare -i INPUT_DEVICE_ID_MATCH_MSCBIT=0x100
-declare -i INPUT_DEVICE_ID_MATCH_LEDBIT=0x200
-declare -i INPUT_DEVICE_ID_MATCH_SNDBIT=0x400
-declare -i INPUT_DEVICE_ID_MATCH_FFBIT=0x800
+INPUT_DEVICE_ID_MATCH_BUS=1
+INPUT_DEVICE_ID_MATCH_VENDOR=2
+INPUT_DEVICE_ID_MATCH_PRODUCT=4
+INPUT_DEVICE_ID_MATCH_VERSION=8
+INPUT_DEVICE_ID_MATCH_EVBIT=$((0x010))
+INPUT_DEVICE_ID_MATCH_KEYBIT=$((0x020))
+INPUT_DEVICE_ID_MATCH_RELBIT=$((0x040))
+INPUT_DEVICE_ID_MATCH_ABSBIT=$((0x080))
+INPUT_DEVICE_ID_MATCH_MSCBIT=$((0x100))
+INPUT_DEVICE_ID_MATCH_LEDBIT=$((0x200))
+INPUT_DEVICE_ID_MATCH_SNDBIT=$((0x400))
+INPUT_DEVICE_ID_MATCH_FFBIT=$((0x800))
 
 
 input_match_bits ()
 {
-    declare mod_bits=$1 dev_bits=$2
-    declare -i mword dword
+    local mod_bits=$1 dev_bits=$2
 
-    mword=0x${mod_bits##*:}
-    dword=0x${dev_bits##*:}
+    mword=$((0x${mod_bits##*:}))
+    dword=$((0x${dev_bits##*:}))
 
     while true; do
 	if [ $(( $mword & $dword != $mword )) -eq 1 ]; then
@@ -151,10 +152,7 @@
 input_map_modules ()
 {
     local line module
-    declare -i matchBits
-    declare -i bustype vendor product version
-    declare -i evBits driverInfo 
-    declare relBits mscBits ledBits sndBitskeyBits absBits ffBits
+    local relBits mscBits ledBits sndBitskeyBits absBits ffBits
 
     while read line
     do
@@ -166,25 +164,26 @@
 
 	set $line
 
-	module="$1"
-	matchBits="$2"
+	module=$(($1))
+	matchBits=$(($2))
 
-	bustype="$3"
-	vendor="$4"
-	product="$5"
-	product="$6"
-
-	evBits="$7"
-	keyBits="$8"
-	relBits="$9"
+	bustype=$(($3))
+	vendor=$(($4))
+	product=$(($5))
+	product=$(($6))
+
+	evBits=$(($7))
+echo "|||$8|||"
+	keyBits=$(($8))
+	relBits=$(($9))
 
 	shift 9
-	absBits="$1"
-	cbsBits="$2"
-	ledBits="$3"
-	sndBits="$4"
-	ffBits="$5"
-	driverInfo="$6"
+	absBits=$(($1))
+	cbsBits=$(($2))
+	ledBits=$(($3))
+	sndBits=$(($4))
+	ffBits=$(($5))
+	driverInfo=$(($6))
 
 	: checkmatch $module
 
diff -urN hotplug.orig1/input.rc hotplug/input.rc
--- hotplug.orig1/input.rc	2003-10-14 01:52:54.000000000 +0200
+++ hotplug/input.rc	2003-10-29 22:19:12.000000000 +0100
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # input.rc	This loads handlers for those input devices
 #		that have drivers compiled in kernel
@@ -61,7 +61,7 @@
     export PRODUCT NAME PHYS EV KEY REL ABS MSC LED SND FF
     input_reset_state
 
-    declare line
+    local line
 
     #
     # the following reads from /proc/bus/input/devices. It is inherently
diff -urN hotplug.orig1/net.agent hotplug/net.agent
--- hotplug.orig1/net.agent	2003-10-07 21:56:24.000000000 +0200
+++ hotplug/net.agent	2003-10-29 19:16:49.000000000 +0100
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # Network hotplug policy agent for Linux 2.4 kernels
 #
@@ -17,7 +17,7 @@
 #
 
 cd /etc/hotplug
-. hotplug.functions
+. ./hotplug.functions
 # DEBUG=yes export DEBUG
 
 if [ "$INTERFACE" = "" ]; then
diff -urN hotplug.orig1/NOTES hotplug/NOTES
--- hotplug.orig1/NOTES	1970-01-01 01:00:00.000000000 +0100
+++ hotplug/NOTES	2003-10-29 02:22:51.000000000 +0100
@@ -0,0 +1,9 @@
+usb.rc:
+- PCI hotplugging is supported when sysfs is present, the HC code should
+  be removed or made conditional to 2.4 kernels
+- rmmod will always fail with some 2.6 kernel configurations, so it cannot
+  be used to check if everything has been loaded
+- could maybe_stop_usb() be improved now?
+
+firmware.agent:
+- /usr/lib/hotplug/firmware should become /usr/share/hotplug/firmware.
diff -urN hotplug.orig1/scsi.agent hotplug/scsi.agent
--- hotplug.orig1/scsi.agent	2002-12-11 23:05:06.000000000 +0100
+++ hotplug/scsi.agent	2003-10-29 19:17:07.000000000 +0100
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # SCSI hotplug agent for 2.5 kernels 
 #
@@ -7,7 +7,7 @@
 #
 
 cd /etc/hotplug
-. hotplug.functions
+. ./hotplug.functions
 
 case $ACTION in
 
diff -urN hotplug.orig1/usb.agent hotplug/usb.agent
--- hotplug.orig1/usb.agent	2003-10-14 01:52:54.000000000 +0200
+++ hotplug/usb.agent	2003-10-29 19:08:54.000000000 +0100
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # USB-specific hotplug policy agent.
 #
@@ -79,7 +79,7 @@
 fi
 
 cd /etc/hotplug
-. hotplug.functions
+. ./hotplug.functions
 # DEBUG=yes export DEBUG
 
 # generated by modutils, for current 2.4.x (and later) kernels
@@ -165,39 +165,31 @@
 # mechanism, but some driver probe() routines need to provide
 # extra filtering.
 #
-declare -i usb_idVendor usb_idProduct usb_bcdDevice
-declare -i usb_bDeviceClass usb_bDeviceSubClass usb_bDeviceProtocol
-declare -i usb_bInterfaceClass usb_bInterfaceSubClass usb_bInterfaceProtocol
 
 usb_convert_vars ()
 {
-    if [ "$AWK" = "" ]; then
-	mesg "can't find awk!"
-	exit 1
-    fi
-
     # work around 2.2.early brokenness
     # munges the usb_bcdDevice such that it is a integer rather
     # than a float: e.g. 1.0 become 0100
     PRODUCT=`echo $PRODUCT | sed -e "s+\.\([0-9]\)$+.\10+" -e "s/\.$/00/" \
                                   -e "s+/\([0-9]\)\.\([0-9][0-9]\)+/0\1\2+" \
 			  -e "s+/\([0-9][0-9]\)\.\([0-9][0-9]\)+/\1\2+"`
-    set `echo $PRODUCT | $AWK -F/ '{print "0x" $1, "0x" $2, "0x" $3 }'` ''
-    usb_idVendor=$1
-    usb_idProduct=$2
-    usb_bcdDevice=$3
+    set $(echo $PRODUCT | sed -e 's+\([^/]*\)/\([^/]*\)/\(.*\)+\1 \2 \3+')
+    usb_idVendor=$((0x$1))
+    usb_idProduct=$((0x$2))
+    usb_bcdDevice=$((0x$3))
 
     if [ "$TYPE" != "" ]; then
     	IFS=/
     	set $TYPE ''
-	usb_bDeviceClass=$1
-        usb_bDeviceSubClass=$2
-        usb_bDeviceProtocol=$3
+	usb_bDeviceClass=$((0x$1))
+        usb_bDeviceSubClass=$((0x$2))
+        usb_bDeviceProtocol=$((0x$3))
 	IFS="$DEFAULT_IFS"
     elif [ -r $SYSFS/$DEVPATH/bDeviceClass ]; then
-	usb_bDeviceClass=0x$(cat $SYSFS/$DEVPATH/bDeviceClass)
-	usb_bDeviceSubClass=0x$(cat $SYSFS/$DEVPATH/bDeviceSubClass)
-	usb_bDeviceProtocol=0x$(cat $SYSFS/$DEVPATH/bDeviceProtocol)
+	usb_bDeviceClass=$((0x$(cat $SYSFS/$DEVPATH/bDeviceClass)))
+	usb_bDeviceSubClass=$((0x$(cat $SYSFS/$DEVPATH/bDeviceSubClass)))
+	usb_bDeviceProtocol=$((0x$(cat $SYSFS/$DEVPATH/bDeviceProtocol)))
     else
 	# out-of-range values
 	usb_bDeviceClass=1000
@@ -208,14 +200,14 @@
     if [ "$INTERFACE" != "" ]; then
 	IFS=/
 	set $INTERFACE ''
-	usb_bInterfaceClass=$1
-	usb_bInterfaceSubClass=$2
-    	usb_bInterfaceProtocol=$3
+	usb_bInterfaceClass=$((0x$1))
+	usb_bInterfaceSubClass=$((0x$2))
+    	usb_bInterfaceProtocol=$((0x$3))
 	IFS="$DEFAULT_IFS"
     elif [ -r $SYSFS/$DEVPATH/bInterfaceClass ]; then
-	usb_bInterfaceClass=0x$(cat $SYSFS/$DEVPATH/bInterfaceClass)
-	usb_bInterfaceSubClass=0x$(cat $SYSFS/$DEVPATH/bInterfaceSubClass)
-	usb_bInterfaceProtocol=0x$(cat $SYSFS/$DEVPATH/bInterfaceProtocol)
+	usb_bInterfaceClass=$((0x$(cat $SYSFS/$DEVPATH/bInterfaceClass)))
+	usb_bInterfaceSubClass=$((0x$(cat $SYSFS/$DEVPATH/bInterfaceSubClass)))
+	usb_bInterfaceProtocol=$((0x$(cat $SYSFS/$DEVPATH/bInterfaceProtocol)))
     else
 	# out-of-range values
 	usb_bInterfaceClass=1000
@@ -224,16 +216,16 @@
     fi
 }
 
-declare -i USB_MATCH_VENDOR=0x0001
-declare -i USB_MATCH_PRODUCT=0x0002
-declare -i USB_MATCH_DEV_LO=0x0004
-declare -i USB_MATCH_DEV_HI=0x0008
-declare -i USB_MATCH_DEV_CLASS=0x0010
-declare -i USB_MATCH_DEV_SUBCLASS=0x0020
-declare -i USB_MATCH_DEV_PROTOCOL=0x0040
-declare -i USB_MATCH_INT_CLASS=0x0080
-declare -i USB_MATCH_INT_SUBCLASS=0x0100
-declare -i USB_MATCH_INT_PROTOCOL=0x0200
+USB_MATCH_VENDOR=$((0x0001))
+USB_MATCH_PRODUCT=$((0x0002))
+USB_MATCH_DEV_LO=$((0x0004))
+USB_MATCH_DEV_HI=$((0x0008))
+USB_MATCH_DEV_CLASS=$((0x0010))
+USB_MATCH_DEV_SUBCLASS=$((0x0020))
+USB_MATCH_DEV_PROTOCOL=$((0x0040))
+USB_MATCH_INT_CLASS=$((0x0080))
+USB_MATCH_INT_SUBCLASS=$((0x0100))
+USB_MATCH_INT_PROTOCOL=$((0x0200))
 
 #
 # stdin is "modules.usbmap" syntax
@@ -243,10 +235,6 @@
 {
     # convert the usb_device_id fields to integers as we read them 
     local line module
-    declare -i match_flags
-    declare -i idVendor idProduct bcdDevice_lo bcdDevice_hi
-    declare -i bDeviceClass bDeviceSubClass bDeviceProtocol
-    declare -i bInterfaceClass bInterfaceSubClass bInterfaceProtocol
 
     # look at each usb_device_id entry
     # collect all matches in $DRIVERS
@@ -262,21 +250,21 @@
 	set $line
 
 	module=$1
-	match_flags=$2
+	match_flags=$(($2))
 
-	idVendor=$3
-	idProduct=$4
-	bcdDevice_lo=$5
-	bcdDevice_hi=$6
-
-	bDeviceClass=$7
-	bDeviceSubClass=$8
-	bDeviceProtocol=$9
+	idVendor=$(($3))
+	idProduct=$(($4))
+	bcdDevice_lo=$(($5))
+	bcdDevice_hi=$(($6))
+
+	bDeviceClass=$(($7))
+	bDeviceSubClass=$(($8))
+	bDeviceProtocol=$(($9))
 
 	shift 9
-	bInterfaceClass=$1
-	bInterfaceSubClass=$2
-	bInterfaceProtocol=$3
+	bInterfaceClass=$(($1))
+	bInterfaceSubClass=$(($2))
+	bInterfaceProtocol=$(($3))
 
 	: checkmatch $module
 
@@ -350,10 +338,11 @@
 # remover, or that the remove action can use to execute a remover.
 #
 if [ "$DEVICE" = "" ]; then
-  declare -rx REMOVER=/var/run/usb/`echo "$INTERFACE/$PRODUCT/$TYPE" | sed -e 's;/;%;g'`
+  REMOVER=/var/run/usb/`echo "$INTERFACE/$PRODUCT/$TYPE" | sed -e 's;/;%;g'`
 else
-  declare -rx REMOVER=/var/run/usb/`echo $DEVICE | sed -e 's;/;%;g'`
+  REMOVER=/var/run/usb/`echo $DEVICE | sed -e 's;/;%;g'`
 fi
+export REMOVER
 
 #
 # What to do with this USB hotplug event?
@@ -373,7 +362,11 @@
     usb_convert_vars
 
     FOUND=false
-    LABEL="USB product $PRODUCT"
+    if [ -f $SYSFS/$DEVPATH/manufacturer ]; then
+	LABEL="USB `cat $SYSFS/$DEVPATH/manufacturer` `cat $SYSFS/$DEVPATH/product`"
+    else
+	LABEL="USB product $PRODUCT"
+    fi
 
     if [ -e "$REMOVER" ]; then
 	rm -f "$REMOVER"
diff -urN hotplug.orig1/usb.rc hotplug/usb.rc
--- hotplug.orig1/usb.rc	2003-09-25 02:09:08.000000000 +0200
+++ hotplug/usb.rc	2003-10-29 22:27:18.000000000 +0100
@@ -21,6 +21,9 @@
 
 PATH=/sbin:/bin:/usr/sbin:/usr/bin
 
+unset I_WANT_A_BROKEN_PS
+PS_PERSONALITY=linux
+
 STATIC_MODULE_LIST=
 X11_USBMICE_HACK=false
 
@@ -76,7 +79,7 @@
 
 	# synthesize hotplug events if we can 
 	# we need (non-bash) programs to parse descriptors.
-	LISTER=`type -p usbmodules`
+	LISTER=`which usbmodules`
 	if [ "$LISTER" = "" -o ! -f /proc/bus/usb/devices ]; then
 		echo $"** can't synthesize root hub events"
 		return
@@ -85,11 +88,12 @@
 	# make sure the usb agent will run
 	ACTION=add
 	PRODUCT=0/0/0
-	export ACTION PRODUCT
-
+	TYPE=
+	INTERFACE=
+	DEVPATH=
 	DEVFS=/proc/bus/usb
 	DEVICE=
-	export DEVFS DEVICE
+	export ACTION PRODUCT TYPE INTERFACE DEVPATH DEVFS DEVICE
 
 	# these notifications will be handled by usbmodules
 	# NOTE: we're not providing a full set of hotplug
@@ -100,10 +104,27 @@
 	# FIXME usbmodules, or something, should set real
 	# PRODUCT and DEVICE strings so /etc/hotplug/usb/*
 	# scripts can rely on them ...
-	for DEVICE in /proc/bus/usb/*/*
-	do
+	if [ -d /sys/bus/usb/devices ]; then
+	    cd /sys/bus/usb/devices
+	    # XXX FIXME this is not the right way...
+	    for device in /sys/bus/usb/devices/[0-9]*; do
+		DEVPATH=${device#/sys/}
+		# XXX is this correct?
+#		class=0
+		if [ -f $device/idVendor ]; then
+		    PRODUCT="`cat $device/idVendor`/`cat $device/idProduct`/`cat $device/bcdDevice`"
+#		    class=`cat $device/bDeviceClass`
+#		    TYPE="$class/`cat $device/bDeviceSubClass`/`cat $device/bDeviceProtocol`"
+                fi
+#		if [ "$class" -eq 0 -a -f $device/bInterfaceClass ]; then
+#		    INTERFACE="`cat $device/bInterfaceClass`/`cat $device/bInterfaceSubClass`/`cat $device/bInterfaceProtocol`"
+#		fi
+	    done
+	else
+	    for DEVICE in /proc/bus/usb/*/*; do
 		/etc/hotplug/usb.agent
-	done
+	    done
+	fi
 }
 
 
@@ -135,12 +156,16 @@
     if [ -d /proc/bus/usb ]; then
 	# if it's not mounted, try to mount it
 	if [ ! -f /proc/bus/usb/devices ]; then
-	    if grep -q "[	 ]/proc/bus/usb[	 ]" /etc/fstab ; then
+	    if grep -q -E "^[^#][^[:space:]]+[[:space:]]+/proc/bus/usb/?[[:space:]]" /etc/fstab; then
 		mount /proc/bus/usb
 	    else
 		# NOTE: name is changing to "usbfs" from "usbdevfs"
 		# NOTE: some versions don't create empty 'devices' files
-		mount -t usbdevfs usbdevfs /proc/bus/usb
+		if grep -q usbfs /proc/filesystems; then
+		    mount -t usbfs usbfs /proc/bus/usb
+		else
+		    mount -t usbdevfs usbdevfs /proc/bus/usb
+		fi
 	    fi
 	fi
     fi

[-- Attachment #4: posix-shell3.diff --]
[-- Type: text/plain, Size: 922 bytes --]

diff -urN hotplug.orig2/hotplug.functions hotplug/hotplug.functions
--- hotplug.orig2/hotplug.functions	2003-10-28 21:55:50.000000000 +0100
+++ hotplug/hotplug.functions	2003-10-30 02:05:59.000000000 +0100
@@ -81,7 +81,7 @@
     # ought to expose the data we need to find all candidate drivers.
     # (on 2.5.48 it does for usb; but maybe not yet for pci.)
     case "$KERNEL" in
-    2.2*|2.3*|2.4*)	LISTER=`type -p ${TYPE}modules` ;;
+    2.2*|2.3*|2.4*)	LISTER=`which ${TYPE}modules` ;;
     *)			LISTER="" ;;
     esac
 
diff -urN hotplug.orig2/pci.rc hotplug/pci.rc
--- hotplug.orig2/pci.rc	2003-10-28 21:57:33.000000000 +0100
+++ hotplug/pci.rc	2003-10-30 02:07:00.000000000 +0100
@@ -44,7 +44,7 @@
 
     else
 
-	LISTER=`type -p pcimodules`
+	LISTER=`which pcimodules`
 	if [ "$LISTER" = "" -o ! -f /proc/bus/pci/devices -o ! -x pci.agent ]; then
 	    echo $"** can't synthesize pci hotplug events"
 	    return

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: remove bashisms from hotplug
  2003-11-25 13:45 remove bashisms from hotplug Marco d'Itri
@ 2003-11-25 17:34 ` Chris Larson
  2003-11-26 21:12 ` Joerg Sommer
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Chris Larson @ 2003-11-25 17:34 UTC (permalink / raw)
  To: linux-hotplug

* Marco d'Itri (md@Linux.IT) wrote:
> These patches remove bashisms from hotplug (tested with the debian dash
> shell) and add (partial) support for sysfs.
[snip patch]

I'd just like to say that I'd love to see the bashisms removed
upstream.  I've been using a similar patch to remove the
bashisms for my embedded distributions locally for some time now.
--
Chris Larson - kergoth at handhelds dot org
Embedded Linux Developer - clarson at ti dot com
OpenZaurus Project Maintainer - http://openzaurus.org/


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: remove bashisms from hotplug
  2003-11-25 13:45 remove bashisms from hotplug Marco d'Itri
  2003-11-25 17:34 ` Chris Larson
@ 2003-11-26 21:12 ` Joerg Sommer
  2003-12-09  9:03 ` Marco d'Itri
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Joerg Sommer @ 2003-11-26 21:12 UTC (permalink / raw)
  To: linux-hotplug

begin  Chris Larson <kergoth@handhelds.org> wrote:
> * Marco d'Itri (md@Linux.IT) wrote:
>> These patches remove bashisms from hotplug (tested with the debian dash
>> shell) and add (partial) support for sysfs.
> [snip patch]
>
> I'd just like to say that I'd love to see the bashisms removed
> upstream.  I've been using a similar patch to remove the
> bashisms for my embedded distributions locally for some time now.

But why upstream want to remove bashism? I did subited an offert some
time ago, but I don't get any reaction.

Jörg.
end.
-- 
Damit das Mögliche entsteht, muß immer wieder das Unmögliche versucht
werden.                                       (Hermann Hesse)


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: remove bashisms from hotplug
  2003-11-25 13:45 remove bashisms from hotplug Marco d'Itri
  2003-11-25 17:34 ` Chris Larson
  2003-11-26 21:12 ` Joerg Sommer
@ 2003-12-09  9:03 ` Marco d'Itri
  2003-12-10  1:15 ` Greg KH
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Marco d'Itri @ 2003-12-09  9:03 UTC (permalink / raw)
  To: linux-hotplug

On Nov 25, Marco d'Itri <md@Linux.IT> wrote:

 >These patches remove bashisms from hotplug (tested with the debian dash
 >shell) and add (partial) support for sysfs.
I have sent these patches multiple times to multiple people and then to
the mailing list. Does anybody feel responsible for hotplug nowadays?

-- 
ciao, |
Marco | [3535 asesN5f7W3Xng]


-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id\x1278&alloc_id371&op=click
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: remove bashisms from hotplug
  2003-11-25 13:45 remove bashisms from hotplug Marco d'Itri
                   ` (2 preceding siblings ...)
  2003-12-09  9:03 ` Marco d'Itri
@ 2003-12-10  1:15 ` Greg KH
  2003-12-17 19:20 ` David Brownell
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2003-12-10  1:15 UTC (permalink / raw)
  To: linux-hotplug

On Tue, Dec 09, 2003 at 10:03:07AM +0100, Marco d'Itri wrote:
> On Nov 25, Marco d'Itri <md@Linux.IT> wrote:
> 
>  >These patches remove bashisms from hotplug (tested with the debian dash
>  >shell) and add (partial) support for sysfs.
> I have sent these patches multiple times to multiple people and then to
> the mailing list. Does anybody feel responsible for hotplug nowadays?

I'd bug David Brownell, as he's the primary author/maintainer of the
bash scripts.

thanks,

greg k-h


-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id\x1278&alloc_id371&op=click
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: remove bashisms from hotplug
  2003-11-25 13:45 remove bashisms from hotplug Marco d'Itri
                   ` (3 preceding siblings ...)
  2003-12-10  1:15 ` Greg KH
@ 2003-12-17 19:20 ` David Brownell
  2003-12-25 13:47 ` Marco d'Itri
  2004-01-09 12:58 ` Olaf Hering
  6 siblings, 0 replies; 8+ messages in thread
From: David Brownell @ 2003-12-17 19:20 UTC (permalink / raw)
  To: linux-hotplug

Greg KH wrote:
> On Tue, Dec 09, 2003 at 10:03:07AM +0100, Marco d'Itri wrote:
> 
>>On Nov 25, Marco d'Itri <md@Linux.IT> wrote:
>>
>> >These patches remove bashisms from hotplug (tested with the debian dash
>> >shell) and add (partial) support for sysfs.
>>I have sent these patches multiple times to multiple people and then to
>>the mailing list. Does anybody feel responsible for hotplug nowadays?
> 
> 
> I'd bug David Brownell, as he's the primary author/maintainer of the
> bash scripts.

... who hasn't been merging many patches or even keeping up with
the hotplug list lately, sorry.  And it didn't help that some
of Greg's email to me seems to trashed by a bad spam filter lately,
I'm not sure why ... :-(


I think it's right to get rid of bash-isms, and will see if I can
get on top of most of the script patches in the next month or so.

- Dave





-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id\x1278&alloc_id371&op=click
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: remove bashisms from hotplug
  2003-11-25 13:45 remove bashisms from hotplug Marco d'Itri
                   ` (4 preceding siblings ...)
  2003-12-17 19:20 ` David Brownell
@ 2003-12-25 13:47 ` Marco d'Itri
  2004-01-09 12:58 ` Olaf Hering
  6 siblings, 0 replies; 8+ messages in thread
From: Marco d'Itri @ 2003-12-25 13:47 UTC (permalink / raw)
  To: linux-hotplug

[-- Attachment #1: Type: text/plain, Size: 259 bytes --]

On Nov 25, Marco d'Itri <md@Linux.IT> wrote:

 >These patches remove bashisms from hotplug (tested with the debian dash
 >shell) and add (partial) support for sysfs.
Bugfix, to be applied on top of the other patches.

-- 
ciao, |
Marco | [3784 tiJkekUnVwCzw]

[-- Attachment #2: posix-shell4.diff --]
[-- Type: text/plain, Size: 750 bytes --]

diff -ur hotplug.orig3/input.agent hotplug/input.agent
--- hotplug.orig3/input.agent	2003-10-29 22:23:16.000000000 +0100
+++ hotplug/input.agent	2003-12-25 14:46:06.000000000 +0100
@@ -164,7 +164,7 @@
 
 	set $line
 
-	module=$(($1))
+	module=$1
 	matchBits=$(($2))
 
 	bustype=$(($3))
@@ -173,7 +173,6 @@
 	product=$(($6))
 
 	evBits=$(($7))
-echo "|||$8|||"
 	keyBits=$(($8))
 	relBits=$(($9))
 
diff -ur hotplug.orig3/input.rc hotplug/input.rc
--- hotplug.orig3/input.rc	2003-10-29 22:19:12.000000000 +0100
+++ hotplug/input.rc	2003-12-25 14:46:11.000000000 +0100
@@ -81,7 +81,7 @@
 	    P:* )	# Physical
 		eval "${line#P: }"
 		PHYS=$Phys
-	;;
+	    ;;
 	    B:* )	# Controls supported
 		line="${line#B: }"
 		eval "${line%%=*}=\"${line#*=}\""

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: remove bashisms from hotplug
  2003-11-25 13:45 remove bashisms from hotplug Marco d'Itri
                   ` (5 preceding siblings ...)
  2003-12-25 13:47 ` Marco d'Itri
@ 2004-01-09 12:58 ` Olaf Hering
  6 siblings, 0 replies; 8+ messages in thread
From: Olaf Hering @ 2004-01-09 12:58 UTC (permalink / raw)
  To: linux-hotplug

 On Tue, Nov 25, Marco d'Itri wrote:

> These patches remove bashisms from hotplug (tested with the debian dash
> shell) and add (partial) support for sysfs.

> @@ -208,14 +200,14 @@
>      if [ "$INTERFACE" != "" ]; then
>  	IFS=/
>  	set $INTERFACE ''
> -	usb_bInterfaceClass=$1
> -	usb_bInterfaceSubClass=$2
> -    	usb_bInterfaceProtocol=$3
> +	usb_bInterfaceClass=$((0x$1))
> +	usb_bInterfaceSubClass=$((0x$2))
> +    	usb_bInterfaceProtocol=$((0x$3))

This doesnt match reality.

drivers/usb/core/usb.c:                     "INTERFACE=%d/%d/%d",


-- 
USB is for mice, FireWire is for men!

sUse lINUX ag, n√úRNBERG


-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-01-09 12:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-25 13:45 remove bashisms from hotplug Marco d'Itri
2003-11-25 17:34 ` Chris Larson
2003-11-26 21:12 ` Joerg Sommer
2003-12-09  9:03 ` Marco d'Itri
2003-12-10  1:15 ` Greg KH
2003-12-17 19:20 ` David Brownell
2003-12-25 13:47 ` Marco d'Itri
2004-01-09 12:58 ` Olaf Hering

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).