Skip to contentSkip to conversation

Yet another patch

PATCH Gioele Barabucci 2 participants 2 messages Feb 26, 2001 – Feb 27, 2001

lore
Share & tools
lore
#0 lore raw

This patch is like to previous one but adds the ability to use comments in *map files, but this this time the lines just have to start with "#" followed by any string (in the past patch "##" were not recognized as comment)

the patch is done against CVS at 22:20

Index: etc/hotplug/hotplug.functions
===================================================================
RCS file: /cvsroot/linux-hotplug/admin/etc/hotplug/hotplug.functions,v retrieving revision 1.2

hotplug/hotplug.functions +18 -13
diff -u -3 -p -r1.2 hotplug.functions
@@ -58,8 +58,13 @@ MODPROBE="/sbin/modprobe"
 #
 load_drivers ()
 {
-    DRIVERS=
+    DRIVERS=""
 
+    # make this routine more readable
+    TYPE=$1
+    FILENAME=$2
+    DESCRIPTION=$3
+
     # NOTE:  usbmodules isn't currently in the trusted path; also,
     # something later than "usbutils-0.7" is needed ("--mapfile"
     # and modutils 2.4.2 support are both needed ... patch avail
@@ -69,16 +74,16 @@ load_drivers ()
 # choose which way they use to generate module listings.
 
     # can we use usbmodules, pcimodules?
-    LISTER=`type -p $1modules`
-    if [ x$LISTER != x ]; then
-	case $1 in
+    LISTER=`type -p ${TYPE}modules`
+    if [ "$LISTER" != "" ]; then
+	case $TYPE in
 	usb)
 	    # only works if we have usbdevfs
 	    # ... reads more descriptors than are passed in env
-	    if [ x$DEVICE = x ]; then
+	    if [ "$DEVICE" = "" ]; then
 		LISTER=
 	    else
-		DRIVERS=`$LISTER --mapfile $2 --device $DEVICE`
+		DRIVERS=`$LISTER --mapfile $FILENAME --device $DEVICE`
 	    fi ;;
 
 	pci)
@@ -88,14 +93,14 @@ load_drivers ()
 	    DRIVERS=`$LISTER`
 	    ;;
 	
-	*)	mesg "how to invoke $1modules ??"
+	*)	mesg "how to invoke ${TYPE}modules ??"
 	    LISTER=
 	esac
     fi
 
     # do it with just shell scripts
-    if [ x$LISTER = x ]; then
-	$1_map_modules < $2
+    if [ "$LISTER" = "" ]; then
+	${TYPE}_map_modules < $FILENAME
     fi
 
     if [ "$DRIVERS" = "" ]; then
@@ -103,7 +108,7 @@ load_drivers ()
     fi
 
     if [ "$DEBUG" != "" ]; then
-	mesg Modprobe and setup $DRIVERS for $3
+	mesg Modprobe and setup $DRIVERS for $DESCRIPTION
     fi
 
     # maybe driver modules need loading and configuring
@@ -114,11 +119,11 @@ load_drivers ()
 	    if ! $MODPROBE $MODULE >/dev/null 2>&1
 	    then
 		mesg "... can't load module $MODULE"
-	    elif [ -x /etc/hotplug/$1/$MODULE ]; then
+	    elif [ -x /etc/hotplug/$TYPE/$MODULE ]; then
 		if [ "$DEBUG" != "" ]; then
-		    mesg Module setup $MODULE for $3
+		    mesg Module setup $MODULE for $DESCRIPTION
 		fi
-		/etc/hotplug/$1/$MODULE
+		/etc/hotplug/$TYPE/$MODULE
 	    fi
 	fi
     done

Index: etc/hotplug/pci.agent
===================================================================
RCS file: /cvsroot/linux-hotplug/admin/etc/hotplug/pci.agent,v retrieving revision 1.7

hotplug/pci.agent +6 -1
diff -u -3 -p -r1.7 pci.agent
@@ -38,7 +38,7 @@ MAP_CURRENT=$MODULE_DIR/modules.pcimap
 # accumulates list of modules we may care about
 DRIVERS=
 
-if [ x$PCI_CLASS = x  -o x$PCI_CLASS = x ]; then
+if [ "$PCI_CLASS" = ""  -o "$PCI_CLASS" = "" ]; then
     mesg Bad PCI agent invocation
     exit 1
 fi
@@ -102,6 +102,11 @@ pci_map_modules ()
     while read module vendor device subvendor subdevice class class_mask ignored
     do
 	: checkmatch $module
+	case $module in
+	    \#*)
+		#this line is a comment
+		continue ;;
+	esac
 
 	: vendor $vendor $pci_id_vendor
 	if [ $vendor -ne $PCI_ANY -a $vendor -ne $pci_id_vendor ]; then

Index: etc/hotplug/usb.agent
===================================================================
RCS file: /cvsroot/linux-hotplug/admin/etc/hotplug/usb.agent,v retrieving revision 1.7

hotplug/usb.agent +13 -5
diff -u -3 -p -r1.7 usb.agent
@@ -44,7 +44,7 @@
 
 if [ -f /etc/sysconfig/usb ]; then
     . /etc/sysconfig/usb
-    if [ x$USBD_ENABLE = xfalse ]; then
+    if [ "$USBD_ENABLE" = "false" ]; then
 	exit 0
     fi
 fi
@@ -80,7 +80,7 @@ MAP_USERMAP=$HOTPLUG_DIR/usb.usermap
 # accumulates list of modules we may care about
 DRIVERS=
 
-if [ x$PRODUCT = x  -o x$ACTION = x ]; then
+if [ "$PRODUCT" = "" -o "$ACTION" = "" ]; then
     mesg Bad USB agent invocation
     exit 1
 fi
@@ -111,7 +111,7 @@ usb_convert_vars ()
     usb_idProduct=$2
     usb_idDevice=$3
 
-    if [ x$TYPE != x ]; then
+    if [ "$TYPE" != "" ]; then
     	IFS=/
     	set $TYPE ''
 	usb_bDeviceClass=$1
@@ -125,7 +125,7 @@ usb_convert_vars ()
 	usb_bDeviceProtocol=1000
     fi
 
-    if [ x$INTERFACE != x ]; then
+    if [ "$INTERFACE" != "" ]; then
 	IFS=/
 	set $INTERFACE ''
 	usb_bInterfaceClass=$1
@@ -160,6 +160,7 @@ usb_map_modules ()
     # expected to work on any line!
 
     # comment line lists (current) usb_device_id field names
+    # is this still needed?
     read ignored
 
     # look at each usb_device_id entry
@@ -169,6 +170,13 @@ usb_map_modules ()
     do
 	: checkmatch $module
 
+	#this is a better way to handle comments
+	case $module in
+	    \#*)
+		#this line is comment
+		continue ;;
+	esac
+
 # FIXME:  tests against USB_ANY should be replaced
 # by tests against bits in match_flags
 # ... if it's there, and nonzero
@@ -273,7 +281,7 @@ add)
 	fi
     fi
 
-    if [ $FOUND = false ]; then
+    if [ "$FOUND" = "false" ]; then
 	mesg "... no drivers for $LABEL"
 	exit 2
     fi

Index: etc/hotplug/usb.rc
===================================================================
RCS file: /cvsroot/linux-hotplug/admin/etc/hotplug/usb.rc,v retrieving revision 1.5

hotplug/usb.rc +2 -1
diff -u -3 -p -r1.5 usb.rc
@@ -53,7 +53,7 @@ usb_boot_events ()
 	# synthesize hotplug events if we can 
 	# we need (non-bash) programs to parse descriptors.
 	LISTER=`type -p usbmodules`
-	if [ x$LISTER = x -o ! -f /proc/bus/usb/devices ]; then
+	if [ "$LISTER" = "" -o ! -f /proc/bus/usb/devices ]; then
 		echo $"** can't synthesize root hub events"
 		return
 	fi
@@ -98,6 +98,7 @@ maybe_start_usb ()
 	    then
 		mount /proc/bus/usb
 	    else
+                # why do not use usbdevfs instead of none?
 		mount -t usbdevfs none /proc/bus/usb
 	    fi
 	fi
#1 lore raw

Thanks, I think I'll be checking this stuff in soon. I tested it with bash1 and bash2; found a bug from somewhere for bash1 systems, "unset IFS" was failing.

Comments should be good in "usb.handmap" (which will likely collect lots of HID devices like joysticks and mice) and other places that users edit by hand.

One thing to watch out for is that this way of handling comment lines expects BASH to be able to parse the comments, so this "comment"

# Don't use punctuation.

would cause at least two errors (unterminated string literal and strange number format).

But it's still better than no comments at all!

- Dave

----- Original Message -----
From: "Gioele Barabucci" <[email protected]>
To: <[email protected]>
Sent: Monday, February 26, 2001 1:58 PM
Subject: Yet another patch

Quoted 7 lines

This patch is like to previous one but adds the ability to use comments in *map files, but this this time the lines just have to start with "#" followed by any string (in the past patch "##" were not recognized as comment)

the patch is done against CVS at 22:20

_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
http://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel