From: "Marco d'Itri" Date: Sun, 07 Mar 2004 12:43:14 +0000 Subject: hotplug patches: fixes and sysfs support 2/5 Message-Id: <20040307124314.GB4291@wonderland.linux.it> MIME-Version: 1 Content-Type: multipart/mixed; boundary="0eh6TmSyL6TZE2Uz" List-Id: References: <20040205010507.GA12825@wonderland.linux.it> In-Reply-To: <20040205010507.GA12825@wonderland.linux.it> To: linux-hotplug@vger.kernel.org --0eh6TmSyL6TZE2Uz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 001_no_bashisms: removed bashisms from all scripts. -- ciao, | Marco | [4957 raw4F0e.nH4kU] --0eh6TmSyL6TZE2Uz Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=001_no_bashisms diff -ruN hotplug-2004_01_05.orig/etc/hotplug/firmware.agent hotplug-2004_01_05/etc/hotplug/firmware.agent --- hotplug-2004_01_05.orig/etc/hotplug/firmware.agent 2003-10-07 21:34:19.000000000 +0200 +++ hotplug-2004_01_05/etc/hotplug/firmware.agent 2004-02-03 01:21:16.000000000 +0100 @@ -16,7 +16,7 @@ # cd /etc/hotplug -. hotplug.functions +. ./hotplug.functions # DEBUG=yes export DEBUG # directory of the firmware files diff -ruN hotplug-2004_01_05.orig/etc/hotplug/hotplug.functions hotplug-2004_01_05/etc/hotplug/hotplug.functions --- hotplug-2004_01_05.orig/etc/hotplug/hotplug.functions 2003-10-07 23:15:38.000000000 +0200 +++ hotplug-2004_01_05/etc/hotplug/hotplug.functions 2004-02-03 01:21:19.000000000 +0100 @@ -32,7 +32,7 @@ # # for diagnostics # -if [ -t -o -z "$LOGGER" ]; then +if [ -t 1 -o -z "$LOGGER" ]; then mesg () { echo "$@" } @@ -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 @@ -92,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 -ruN hotplug-2004_01_05.orig/etc/hotplug/ieee1394.agent hotplug-2004_01_05/etc/hotplug/ieee1394.agent --- hotplug-2004_01_05.orig/etc/hotplug/ieee1394.agent 2004-02-03 01:21:26.000000000 +0100 +++ hotplug-2004_01_05/etc/hotplug/ieee1394.agent 2004-02-03 01:21:16.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 diff -ruN hotplug-2004_01_05.orig/etc/hotplug/input.agent hotplug-2004_01_05/etc/hotplug/input.agent --- hotplug-2004_01_05.orig/etc/hotplug/input.agent 2003-10-14 01:46:58.000000000 +0200 +++ hotplug-2004_01_05/etc/hotplug/input.agent 2004-02-03 01:21:21.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,21 +51,18 @@ # 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 set $array - tmp=$1 + tmp="$1" shift while [ "$#" -gt 0 ]; do tmp="$tmp:$1" @@ -81,14 +78,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 +97,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 +147,7 @@ input_map_modules () { local line module - declare -i matchBits - declare -i bustype vendor product version - declare -i evBits driverInfo - declare relBits mscBits ledBits sndBits keyBits absBits ffBits + local relBits mscBits ledBits sndBits keyBits absBits ffBits while read line do @@ -167,24 +160,24 @@ set $line module="$1" - matchBits="$2" + matchBits=$(($2)) - bustype="$3" - vendor="$4" - product="$5" - version="$6" - - evBits="$7" - keyBits="$8" - relBits="$9" + bustype=$(($3)) + vendor=$(($4)) + product=$(($5)) + version=$(($6)) + + evBits=$(($7)) + 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 -ruN hotplug-2004_01_05.orig/etc/hotplug/input.rc hotplug-2004_01_05/etc/hotplug/input.rc --- hotplug-2004_01_05.orig/etc/hotplug/input.rc 2003-10-14 01:46:58.000000000 +0200 +++ hotplug-2004_01_05/etc/hotplug/input.rc 2004-02-03 01:21:16.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 -ruN hotplug-2004_01_05.orig/etc/hotplug/net.agent hotplug-2004_01_05/etc/hotplug/net.agent --- hotplug-2004_01_05.orig/etc/hotplug/net.agent 2003-10-07 21:56:24.000000000 +0200 +++ hotplug-2004_01_05/etc/hotplug/net.agent 2004-02-03 01:21:16.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 -ruN hotplug-2004_01_05.orig/etc/hotplug/pci.agent hotplug-2004_01_05/etc/hotplug/pci.agent --- hotplug-2004_01_05.orig/etc/hotplug/pci.agent 2004-02-03 01:21:26.000000000 +0100 +++ hotplug-2004_01_05/etc/hotplug/pci.agent 2004-02-03 01:21:16.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,20 @@ # 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 - 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 +79,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 +94,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 +118,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 diff -ruN hotplug-2004_01_05.orig/etc/hotplug/pci.rc hotplug-2004_01_05/etc/hotplug/pci.rc --- hotplug-2004_01_05.orig/etc/hotplug/pci.rc 2003-06-28 02:13:10.000000000 +0200 +++ hotplug-2004_01_05/etc/hotplug/pci.rc 2004-02-03 01:21:16.000000000 +0100 @@ -17,7 +17,7 @@ . /etc/rc.d/init.d/functions fi -. hotplug.functions +. ./hotplug.functions # # override any of the defaults? @@ -32,7 +32,7 @@ # information, and more can be gotten with 'lspci'. # don't expect pcimodules to exist!! # - 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 diff -ruN hotplug-2004_01_05.orig/etc/hotplug/scsi.agent hotplug-2004_01_05/etc/hotplug/scsi.agent --- hotplug-2004_01_05.orig/etc/hotplug/scsi.agent 2002-12-11 23:05:06.000000000 +0100 +++ hotplug-2004_01_05/etc/hotplug/scsi.agent 2004-02-03 01:21:16.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 -ruN hotplug-2004_01_05.orig/etc/hotplug/usb.agent hotplug-2004_01_05/etc/hotplug/usb.agent --- hotplug-2004_01_05.orig/etc/hotplug/usb.agent 2004-02-03 01:21:26.000000000 +0100 +++ hotplug-2004_01_05/etc/hotplug/usb.agent 2004-02-03 01:21:16.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,27 +165,19 @@ # 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=/ @@ -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 @@ -241,12 +233,7 @@ # usb_map_modules () { - # 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 +249,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 +337,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? diff -ruN hotplug-2004_01_05.orig/etc/hotplug/usb.rc hotplug-2004_01_05/etc/hotplug/usb.rc --- hotplug-2004_01_05.orig/etc/hotplug/usb.rc 2004-02-03 01:21:26.000000000 +0100 +++ hotplug-2004_01_05/etc/hotplug/usb.rc 2004-02-03 01:21:16.000000000 +0100 @@ -79,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 --0eh6TmSyL6TZE2Uz-- ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&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