From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Marco d'Itri" Date: Tue, 25 Nov 2003 13:45:09 +0000 Subject: remove bashisms from hotplug MIME-Version: 1 Content-Type: multipart/mixed; boundary="envbJBWh7q8WU6mo" Message-Id: List-Id: To: linux-hotplug@vger.kernel.org --envbJBWh7q8WU6mo Content-Type: text/plain; charset=us-ascii Content-Disposition: inline These patches remove bashisms from hotplug (tested with the debian dash shell) and add (partial) support for sysfs. -- ciao, | Marco | [3276 svFzLScsoTJLw] --envbJBWh7q8WU6mo Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="posix-shell1.diff" 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. --envbJBWh7q8WU6mo Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="posix-shell2.diff" 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 --envbJBWh7q8WU6mo Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="posix-shell3.diff" 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 --envbJBWh7q8WU6mo-- ------------------------------------------------------- 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