Changeset 984 for trunk

Show
Ignore:
Timestamp:
07/10/07 14:45:33 (18 months ago)
Author:
aj
Message:
  • add flexible loop to wait for device.
  • the loop must run in the background, otherwise udev will not create the device till the loop timed out.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/etc/openct_usb.in

    r961 r984  
    55test -e /var/run/openct/status || exit 0 
    66 
    7 # race condition in the kernel, $DEVICE might not exist now 
    8 sleep 0.1 
    9  
    107if [ -n "$DEVICE" ] 
    118then 
    12         # if you see two ifdhandlers for one device, then you can 
    13         # either comment out the next line here ... 
    14         SBINDIR/openct-control attach usb:$PRODUCT usb $DEVICE 
    15         exit 0 
     9        for A in `seq 10` 
     10        do 
     11                if test -e $DEVICE 
     12                then 
     13                        # if you see two ifdhandlers for one device, then you can 
     14                        # either comment out the next line here ... 
     15                        SBINDIR/openct-control attach usb:$PRODUCT usb $DEVICE 
     16                        exit 0 
     17                fi 
     18                sleep 0.1 
     19        done 
     20        echo "$0 waited for $DEVICE but it did not appear." \ 
     21                |logger -p daemon.error 
     22        exit 1 
    1623fi 
    1724 
    1825if [ -n "$DEVNAME" ] 
    1926then 
    20         V="`cat /sys/$DEVPATH/device/idVendor |sed -e "s/^0*//"`" 
    21         P="`cat /sys/$DEVPATH/device/idProduct|sed -e "s/^0*//"`" 
    22         D="`cat /sys/$DEVPATH/device/bcdDevice |sed -e "s/^0*//"`" 
    23         PRODUCT="$V/$P/$D" 
    24         # or the following line. both should disable that effect. 
    25         SBINDIR/openct-control attach usb:$PRODUCT usb $DEVNAME 
     27        for A in `seq 10` 
     28        do 
     29                if test -e $DEVNAME 
     30                then 
     31                        V="`cat /sys/$DEVPATH/device/idVendor |sed -e "s/^0*//"`" 
     32                        P="`cat /sys/$DEVPATH/device/idProduct|sed -e "s/^0*//"`" 
     33                        D="`cat /sys/$DEVPATH/device/bcdDevice |sed -e "s/^0*//"`" 
     34                        PRODUCT="$V/$P/$D" 
     35                        # or the following line. both should disable that effect. 
     36                        SBINDIR/openct-control attach usb:$PRODUCT usb $DEVNAME 
     37 
     38                        exit 0 
     39                fi 
     40                sleep 0.1 
     41        done 
     42        echo "$0 waited for $DEVNAME but it did not appear." \ 
     43                |logger -p daemon.error 
     44        exit 1 
     45fi 
     46 
     47) & 
     48disown %1 
     49 
    2650        exit 0 
    2751fi