UC20 - prepare-device hook cannot access files under /sys/devices/

The hook of prepare-device cannot access the files under /sys/devices/. I used the same configuration in gadget file for core18 and it worked as below:

      - hardware-observe

The logs show “Permission Denied” when prepare-device script accesses the file. Will “connections” work for this case? For example:

  - plug: GADGET_SNAP_ID:hardware-observe


the prepare-device hook should run after seeding is done (which is when the connections: statements are applied), so it should work …

Thanks @ogra, will try them together later :slight_smile:

Just tried with both settings but still getting DENIED messages, when the prepare-device tried to access a file under /sys/devices/. I may put the above setting in a wrong place.


What is the slot for this plug? Is it core/core18/core20?

Found the below from https://snapcraft.io/docs/gadget-snap:

# Interface connection instructions for plugs and slots of seeded
# snaps to connect at first boot. snap IDs can be the "system"
# nick as well. Omitting "slot" in an instruction is allowed
# and equivalent then to: slot: system:<plug>
# (since 2.34) (optional)
   -  plug: <plug snap id>:<plug>
      slot: <slot snap id>:<slot>

by default, the slot will be system:hardware-observe.

Then it seems the connections setting should be working:

root@ubuntu:/home/test# snap connections gadget
Interface         Plug                                       Slot  Notes
hardware-observe  gadget:hardware-observe  -     -

After connecting the slug manually snap connect gadget:hardware-observe, the outputs are different:

root@ubuntu:/home/test# snap connections gadget
Interface         Plug                                       Slot               Notes
hardware-observe  gadget:hardware-observe  :hardware-observe  manual

I’ll give it a try with:

  - plug: GADGET_SNAP_ID:hardware-observe
     slot: system:hardware-observe

A quick update, adding slot as above doesn’t work.

Try leaving the slot out completely…

I used this setting as well but no luck :slight_smile:

The interface command doesn’t show the system slot but the connections command shows if I run snap connect GADGET_NAME:hardware-observe manually:

interface command:

root@ubuntu:/home/test# snap interface hardware-observe
name:    hardware-observe
summary: allows reading information about system hardware
  - snapd

connections command:

root@ubuntu:/home/test# snap connections GADGET_NAME
Interface         Plug                                       Slot               Notes
hardware-observe  GADGET_NAME:hardware-observe  :hardware-observe  manual

I think I may know the cause. The gadget file is an extra one while building the image, which is the reason I cannot see the gadget details from snap known snap-declarations. After the image is built from store, I don’t see the error message now. Will test more and see if there is any other issue. Thanks. :slight_smile:

1 Like