hotplug and test and set
Hello,
I have an Epox DG02A usb dongle for bluetooth.
$ ls usbview [...] Bus 003 Device 002: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle
I added a script to start pand into my /etc/hotplug.d/usb directory on my Debian system.
rd@topsi:~$ cat /etc/hotplug.d/usb/epox-bluetooth.hotplug
#!/bin/sh
pidfile=/var/run/pand.pid
lockfile=/var/lock/pand.lock
DAEMON=/usr/bin/pand
case `echo $PRODUCT|cut -d / -f 1-2` in
# a12/1/525 and a12/1/828 have been seen for the Epox BT DB02A
a12/1) break ;;
*) exit ;;
esac
case $TYPE in
224/1/1) break ;;
*) exit ;;
esac
case $ACTION in
add)
# poor man's locking
if [ ! -e $lockfile ]; then
touch $lockfile
echo entered locked area >> /tmp/epox.log
hcitool scan >> /tmp/epox.log
sleep 1
start-stop-daemon --start --exec $DAEMON -- --nodetach --role
PANU --search --encrypt --pidfile $pidfile
fi
;;
remove)
start-stop-daemon --stop --exec $DAEMON --pidfile $pidfile
rm $lockfile
ifdown bnep0
;;
esac
rd@topsi:~$My problem is that this script is called four times when the dongle is plugged in. I order to avoid to call pand four times, I added a poor test and set to the script to add a lock when a pand is running. Does anybody know, what I could do to get a better locking behaviour, e.g. an atomic test and set?
Many thanks,
Rainer
Signature · 15 lines
Rainer Dorsch Alzentalstr. 28 D-71083 Herrenberg 07032-919495 Icq: 32550367 ------------------------------------------------------- The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net [email protected] https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 2 lines · Rainer Dorsch
I added a script to start pand into my
/etc/hotplug.d/usbdirectory on my Debian system.
...
Quoted 2 lines
My problem is that this script is called four times when the dongle is plugged in.
What is in the DEVPATH variable of all four events? I expect you can sort out the right one.
Kay
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 4 lines · Rainer Dorsch
My problem is that this script is called four times when the dongle is plugged in. I order to avoid to call pand four times, I added a poor test and set to the script to add a lock when a pand is running. Does anybody know, what I could do to get a better locking behaviour, e.g. an atomic test and set?
From http://linux-hotplug.sourceforge.net/?selected=usb:
There are two kinds of usb hotplug event: device, and interface. Kernel 2.6 added device events, as well as reporting the complete set of interface events. You can tell which kind of event by the environment
variables: device events don't include PRODUCT, or any of the other parameters here except DEVPATH and ACTION.
So:
# ignore device events [ "$PRODUCT" ] || exit 0
Signature · 12 lines
ciao, Marco ------------------------------------------------------- The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net [email protected] https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Am Sonntag, 2. Januar 2005 02:27 schrieb Marco d'Itri:
Quoted 15 lines · Rainer Dorsch
Quoted 7 lines
My problem is that this script is called four times when the dongle is plugged in. I order to avoid to call pand four times, I added a poor test and set to the script to add a lock when a pand is running. Does anybody know, what I could do to get a better locking behaviour, e.g. an atomic test and set?
There are two kinds of usb hotplug event: device, and interface. Kernel 2.6 added device events, as well as reporting the complete set of interface events. You can tell which kind of event by the environment
variables: device events don't include PRODUCT, or any of the other parameters here except DEVPATH and ACTION.
Quoted 4 lines
So:
# ignore device events [ "$PRODUCT" ] || exit 0
Many thanks for the quick reply.
I added
(date
echo $DEVPATH
echo $PRODUCT
echo $TYPE
echo $ACTION) >> /tmp/epox.log
into the script.
The result is
Sun Jan 2 14:06:32 CET 2005
/devices/pci0000:00/0000:00:07.2/usb1/1-2
add
Sun Jan 2 14:06:32 CET 2005
/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.0
a12/1/525
224/1/1
add
entered locked area
Sun Jan 2 14:06:32 CET 2005
/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.1
a12/1/525
224/1/1
add
Sun Jan 2 14:06:32 CET 2005
/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.2
a12/1/525
224/1/1
add
That means that I should scan for a DEVPATH variable ending with 1.0 (?)
Many thanks,
Rainer
Signature · 15 lines
Rainer Dorsch Alzentalstr. 28 D-71083 Herrenberg 07032-919495 Icq: 32550367 ------------------------------------------------------- The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net [email protected] https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 23 lines · Rainer Dorsch
Am Sonntag, 2. Januar 2005 02:27 schrieb Marco d'Itri:
Quoted 15 lines · Rainer Dorsch
Quoted 7 lines
My problem is that this script is called four times when the dongle is plugged in. I order to avoid to call pand four times, I added a poor test and set to the script to add a lock when a pand is running. Does anybody know, what I could do to get a better locking behaviour, e.g. an atomic test and set?
There are two kinds of usb hotplug event: device, and interface. Kernel 2.6 added device events, as well as reporting the complete set of interface events. You can tell which kind of event by the environment
variables: device events don't include PRODUCT, or any of the other parameters here except DEVPATH and ACTION.Quoted 4 lines
So:
# ignore device events [ "$PRODUCT" ] || exit 0Many thanks for the quick reply.
Quoted 7 lines
/devices/pci0000:00/0000:00:07.2/usb1/1-2
/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.0
a12/1/525
/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.1
a12/1/525
/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.2
a12/1/525
You get one device event and three interface events for this USB device.
Quoted 1 line
That means that I should scan for a DEVPATH variable ending with 1.0 (?)
You may just just match the event for the device. Just add the exit statement Marco suggested and negate it to skip interface events instead.
Kay
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Am Sonntag, 2. Januar 2005 16:23 schrieb Kay Sievers:
Quoted 32 lines · Rainer Dorsch
Quoted 23 lines
Am Sonntag, 2. Januar 2005 02:27 schrieb Marco d'Itri:
Quoted 15 lines · Rainer Dorsch
Quoted 7 lines
My problem is that this script is called four times when the dongle is plugged in. I order to avoid to call pand four times, I added a poor test and set to the script to add a lock when a pand is running. Does anybody know, what I could do to get a better locking behaviour, e.g. an atomic test and set?
There are two kinds of usb hotplug event: device, and interface. Kernel 2.6 added device events, as well as reporting the complete set of interface events. You can tell which kind of event by the environment
variables: device events don't include PRODUCT, or any of the other parameters here except DEVPATH and ACTION.Quoted 4 lines
So:
# ignore device events [ "$PRODUCT" ] || exit 0Many thanks for the quick reply.
Quoted 7 lines
/devices/pci0000:00/0000:00:07.2/usb1/1-2
/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.0
a12/1/525
/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.1
a12/1/525
/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.2
a12/1/525
Quoted 8 lines
You get one device event and three interface events for this USB device.
Quoted 1 line
That means that I should scan for a DEVPATH variable ending with 1.0 (?)
You may just just match the event for the device. Just add the exit statement Marco suggested and negate it to skip interface events instead.
Hmm... $PRODUCT and $TYPE are empty for the interface. Wouldn't that mean that I try to start pand for every usb device?
Thanks,
Rainer
Signature · 15 lines
Rainer Dorsch Alzentalstr. 28 D-71083 Herrenberg 07032-919495 Icq: 32550367 ------------------------------------------------------- The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net [email protected] https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 37 lines · Rainer Dorsch
Am Sonntag, 2. Januar 2005 16:23 schrieb Kay Sievers:
Quoted 36 lines · Rainer Dorsch
Quoted 23 lines
Am Sonntag, 2. Januar 2005 02:27 schrieb Marco d'Itri:
Quoted 15 lines · Rainer Dorsch
Quoted 7 lines
My problem is that this script is called four times when the dongle is plugged in. I order to avoid to call pand four times, I added a poor test and set to the script to add a lock when a pand is running. Does anybody know, what I could do to get a better locking behaviour, e.g. an atomic test and set?
There are two kinds of usb hotplug event: device, and interface. Kernel 2.6 added device events, as well as reporting the complete set of interface events. You can tell which kind of event by the environment
variables: device events don't include PRODUCT, or any of the other parameters here except DEVPATH and ACTION.Quoted 4 lines
So:
# ignore device events [ "$PRODUCT" ] || exit 0Many thanks for the quick reply.
Quoted 7 lines
/devices/pci0000:00/0000:00:07.2/usb1/1-2
/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.0
a12/1/525
/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.1
a12/1/525
/devices/pci0000:00/0000:00:07.2/usb1/1-2/1-2:1.2
a12/1/525You get one device event and three interface events for this USB device.
Quoted 1 line
That means that I should scan for a DEVPATH variable ending with 1.0 (?)
Quoted 7 lines
Quoted 4 lines
You may just just match the event for the device. Just add the exit statement Marco suggested and negate it to skip interface events instead.
Hmm... $PRODUCT and $TYPE are empty for the interface. Wouldn't that mean that I try to start pand for every usb device?
You are right, sorry. I thought you were using the usermap and not the multiplexer infrastructure.
Kay
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel