Automatic Activation, Hotplug and UDEV, Configuration
Post Reply
lux
Posts: 3
Joined: 09 Dec 2007, 09:43

usb_modeswitch on centos 5 and red hat enterprise linux 5

Post by lux » 09 Dec 2007, 11:05

Hi all

I'm setting up usb_modeswitch for a Onda MH600HS (ZTE 620 rebranded) on CentOS 5 (RHEL5 recompiled with no hat logos).
I had a problem with udev, and I'd like to contribute the solution.
The problem: if I connect the modem and then run usb_modeswitch from the shell, everything works good and after a few seconds I have the modem device working. If I run usb_modeswitch from udev, it doesn't work.
I found that on these systems, which have udev version 095, usb_modeswitch run from udev never finds the DefaultVendor/DefaultProduct device and exits complainig about it.
I used udev in debug mode, and found that it waits for the spawned program (usb_modeswitch or a shell script launching it) to finish before completing the device activation. No matter if I use a script that sleeps an arbitrary amount of time before launching usb_modeswitch, because udev simply waits for the script to finish before creating the device. Even lanchin usb_modeswitch (or a script) in the background is enough because udev, before executing the script, opens two pipes on file descriptors 5 and 7 on the child process (which then does a dup2() to use these fds as stdout and stderr) and then repetedly uses select() to wait for them to close.
At the end, I had to use the following script to be able to use usb_modeswitch from udev:

Code: Select all

#!/bin/sh
# close these FDs to detach from udev
exec 1<&- 2<&- 5<&- 7<&-
sh -c "sleep 4; /usr/bin/usb_modeswitch" &
exit 0
One obvious consequence of doing so is that udev can not collect the script's stdout/err and write it in the log in debug mode, but I did not find whis so imoprtant. You can always redirect it.
Hope this can be useful to others too.

Luigi

Josh
Site Admin
Posts: 6570
Joined: 03 Nov 2007, 00:30

Re: usb_modeswitch on centos 5 and rhel 5

Post by Josh » 10 Dec 2007, 22:05

lux wrote:I found that on these systems, which have udev version 095, usb_modeswitch run from udev never finds the DefaultVendor/DefaultProduct device and exits complainig about it.
Interesting. This is the first report of such problems.

I suppose you did try everything concerning the order of rules. No change if the rule running usb_modeswitch was put on the very end of the chain? Like in a file "ze_last.rules"? :)

lux
Posts: 3
Joined: 09 Dec 2007, 09:43

Post by lux » 11 Dec 2007, 11:27

Prior to analyzing the way udev was so carefully assuring that my script was finished before creating the usb device in /sys, I tried putting my rules very early (10-something.rules) and very late (zz-something.rules) but nothing changed :(

Post Reply