Automatic Activation, Hotplug and UDEV, Configuration
Post Reply
haris2887
Posts: 1
Joined: 13 Oct 2020, 14:12

UDEV rules problem with ifup

Post by haris2887 » 13 Oct 2020, 14:21

Hello all.
I currently have USB mode switch working on a very stripped down redhat Linux box.

Inside my /etc/udev/rules.d/52-e8372.rules I have

Code: Select all

ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1f01",
    RUN+="/usr/sbin/usb_modeswitch -v 12d1 -p 1f01 -J ; sleep 5s ; /usr/sbin/ifup eth0
However when I plug the USB dongle it does the mode switch properly, It even shows up as eth0 and CDC_Driver is loaded correctly as verified by DMESG.
[Thu Jan 1 18:04:54 2009] usb 2-1.2: new high-speed USB device number 5 using ehci-pci
[Thu Jan 1 18:04:54 2009] usb 2-1.2: New USB device found, idVendor=12d1, idProduct=1f01
[Thu Jan 1 18:04:54 2009] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[Thu Jan 1 18:04:54 2009] usb 2-1.2: Product: HUAWEI_MOBILE
[Thu Jan 1 18:04:54 2009] usb 2-1.2: Manufacturer: HUAWEI_MOBILE
[Thu Jan 1 18:04:54 2009] usb 2-1.2: SerialNumber: 0123456789ABCDEF
[Thu Jan 1 18:04:54 2009] usb-storage 2-1.2:1.0: USB Mass Storage device detected
[Thu Jan 1 18:04:54 2009] scsi host7: usb-storage 2-1.2:1.0
[Thu Jan 1 18:04:54 2009] usb 2-1.2: USB disconnect, device number 5
[Thu Jan 1 18:04:55 2009] usb 2-1.2: new high-speed USB device number 6 using ehci-pci
[Thu Jan 1 18:04:55 2009] usb 2-1.2: New USB device found, idVendor=12d1, idProduct=14db
[Thu Jan 1 18:04:55 2009] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[Thu Jan 1 18:04:55 2009] usb 2-1.2: Product: HUAWEI_MOBILE
[Thu Jan 1 18:04:55 2009] usb 2-1.2: Manufacturer: HUAWEI_MOBILE
[Thu Jan 1 18:04:55 2009] cdc_ether 2-1.2:1.0 eth0: register 'cdc_ether' at usb-0000:00:1d.0-1.2, CDC Ethernet Device, 0c:5b:8f:27:9a:64
[Thu Jan 1 18:04:55 2009] usb-storage 2-1.2:1.2: USB Mass Storage device detected
[Thu Jan 1 18:04:55 2009] scsi host8: usb-storage 2-1.2:1.2
[Thu Jan 1 18:04:56 2009] scsi 8:0:0:0: Direct-Access HUAWEI TF CARD Storage 2.31 PQ: 0 ANSI: 2
[Thu Jan 1 18:04:56 2009] sd 8:0:0:0: Attached scsi generic sg1 type 0
[Thu Jan 1 18:04:56 2009] sd 8:0:0:0: [sdb] Attached SCSI removable disk
my problem is that I have to manually go and do an

Code: Select all

ifup eth0
inorder to use the device.
Everytime I unplug the device i have to manually do an ifup.

i was hoping that i could just put it as part of the udev rule.
However that doe not seem to be working.

any ideal ?

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

Re: UDEV rules problem with ifup

Post by Josh » 02 Jan 2021, 13:48

Newer versions of udev will kill subprocesses started by rules if they are running 'too long'. I suspect this is happening in your case.

Standard usb_modeswitch installations are working around this by using a systemd service file. This allows the detachment of the mode-switching process from udev so that it can run as long as it needs to.

You should be able to start that directly from the udev rules file. I can't provide you with step-by-step instructions but you certainly can figure it out for yourself by unpacking the source distribution:

Look into the small shell script usb_modeswitch.sh which does basically not much else but start the service. Then look into usb_modeswitch@.service; there is plenty of information available about these systemd files.
Just one quick hint: the "@" character in the name is required to pass a parameter to the service file and therefore to usb_modeswitch.

Post Reply