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
Hope this can be useful to others too.
Luigi