Classic package command in udev rule not working

I am using a Huawei LTE modem which requires usb_modeswitch to switch the mode of the USB in order to detect the device as a modem.(Ubuntu Core on Dragonboard410c)

In a classical ubuntu system, I would add the udev rule as the following in /etc/udev/rules.d/70-huawei-e3372.rules

ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1f01", RUN+="/usr/sbin/usb_modeswitch -v 12d1 -p 1f01 -M '55534243123456780000000000000a11062000000000000100000000000000'"

However, usb_modeswitch was installed using apt, so the package does not exist in /usr/sbin/usb_modeswitch but in /var/snap/classic/common/classic/usr/sbin/usb_modeswitch

Therefore, tried adding the rule

ACTION=="add", SUBSYSTEM=="block", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1f01", RUN+="/var/snap/classic/common/classic/usr/sbin/usb_modeswitch -v 12d1 -p 1f01 -M '55534243123456780000000000000a11062000000000000100000000000000'"
SUBSYSTEM=="block", ATTRS{idVendor}=="12d1"

However, the device is not loaded properly.

As I cannot run the application directly with

$ /var/snap/classic/common/classic/usr/sbin/usb_modeswitch
/var/snap/classic/common/classic/usr/sbin/usb_modeswitch: error while loading shared libraries: cannot open shared object file: No such file or directory

As I can see that is located in /var/snap/classic/common/classic/lib/aarch64-linux-gnu, I am suspecting when a package is installed in the classic snap, the udev cannot access the file in the classic snap.

How can I resolve this? Could anyone help in resolving this issue?

Thank you in advance,

Given the classic snap is (on purpose) solely a build environment and not something to use at runtime, you can use it to make sure your resulting snap includes as stage-packages or build-packages, but not really access its content as “system enhancements”

1 Like

@ogra Thank you for your input. I guess this is the wrong way to do it.

Is there a work around the issue?

I tried creating a snap that packages the usb_modeswitch and run it with the --devmode flag but usb_modeswitch requires a sudo command which seems to prevent the snap from running properly.

name: usbmode-switch
version: '0.1' 
summary: usb-modeswitch packaged as snap
description: |
  usb-modeSwitch is (surprise!) a mode switching tool for controlling 'multi-mode' USB devices.

grade: devel 
confinement: devmode 

    plugin: make
    plugin: make

    command: |
      sudo usb_modeswitch -v 12d1 -p 1f01 -M '55534243123456780000000000000a11062000000000000100000000000000'

In the end of the day, I just need to run the following command.

sudo usb_modeswitch -v 12d1 -p 1f01 -M '55534243123456780000000000000a11062000000000000100000000000000'

try removing the sudo from snapcraft.yaml and instead call the command with sudo when you execute it… like:

sudo conf-huaweii

if you do it like you did above you would actually have to ship sudo inside your snap, whereas if you invoke the command with sudo later as i suggested, it uses the sudo from the system …

@ogra Great! it works thank you!

One more question, does this mean that I cannot run this snap as a daemon?

My initial intention was to configure the device on boot without any commands

daemons always run as root :wink: