How to use udev in strict confinement


#1

Hi There,
I have a C program which uses libudev to detect attached USB printers. The program works fine with devmode confinement. When I switch to strict confinement, the app breaks. Apparently, the program is not able to initialize the udev monitor. I suspect I am not including sufficient plugs.
All the plugs in snapcraft.yaml are connected.

Any help would be greatly appreciated.

This is my snapcraft.yaml file:

name: hplip-printer-applications # you probably want to 'snapcraft register <name>'
base: core18 # the base snap is the execution environment for this snap
version: '0.0.2' # just for humans, typically '1.2+git' or '1.3.2'
summary: Snap for HPLIP Printer driver packages. # 79 char long summary
description: |
  This snap aims to provide modular snaps for HPLIP printer driver package.

grade: devel # must be 'stable' to release into candidate/stable channels
confinement: strict # use 'strict' once you have the right plugs and slots

apps:
  run-server:
    command: bin/server
    # daemon: simple
    plugs: [network, network-bind, avahi-control, raw-usb, home,hardware-observe]
parts:
  ippsample:
    plugin: autotools
    source: https://github.com/dheeraj135/ippsample.git
    # organize:
    #   lib/libcups.a: lib/ippsample/libcups.a
    configflags:
      - --datarootdir=/usr/share/
    build-packages:
    - libcups2-dev
    - zlib1g
    - liblzma5  
    organize: 
      lib/libcups.a : lib/cups/

  server:
    # See 'snapcraft plugins'
    plugin: autotools
    source: ./Printer-Applications-Framework
    source-type: git
    build-packages:
      - libcups2
      - libcups2-dev
      - perl
      - automake
      - autoconf
      - m4
      - libudev-dev
      - libpthread-stubs0-dev
      - libavahi-client-dev
      - libavahi-common-dev
      - libavahi-common3
      - libavahi-client3
      - zlib1g-dev
      - libgnutls28-dev
      - libgss3
      - libgss-dev
      - zlib1g
      - liblzma5
      - libusb-1.0-0-dev

    stage-packages:
      - libcups2
      - libavahi-common3
      - libavahi-client3
      - libgss3
      - libusb-1.0-0
      - libudev1

    override-build: |
      autoreconf
      snapcraftctl build

    after: [ippsample]
  
  cups-filters:
    plugin: dump
    source: ./temp
    stage-packages:
    - cups-filters
    - cups
    prime:
    - usr/lib/cups/filter/
    - usr/share/cups/mime/
    stage:
    - usr/lib/cups/filter/
    - usr/share/cups/mime/
    organize:
     /usr/lib/cups/filter/* : usr/lib/cups/filter/
     /usr/share/cups/mime/* : usr/share/cups/mime/

  libraries:
    plugin: dump
    source: ./temp
    prime:
    - .
    stage:
    - .
    stage-packages:
    - libqpdf21
    - libcupsfilters1
    - ghostscript

    
  hplip:
    plugin: autotools
    source: ./hplip-3.19.6.tar.gz
    after: [server]
    configflags:
    - --disable-scan-build
    - --prefix=/
    - --enable-new-hpcups
    - --datadir=/usr/share/
    build-packages:
    - libcups2-dev
    - libcups2
    - python-dev
    - perl
    - automake
    - autoconf
    - m4
    - libusb-1.0-0-dev
    - libsnmp-dev
    build-environment:
    - "CUPS_DATADIR" : "/root/parts/ippsample/install/share/cups/"
    stage-packages:
      - python-dev
      - libcups2-dev
      - libsnmp30
      - libusb-1.0-0
    override-build: |
      snapcraftctl build
      cp /lib/libImageProcessor* $SNAPCRAFT_PART_INSTALL/lib/
      rm $SNAPCRAFT_PART_INSTALL/lib/libImageProcessor.so
      cd $SNAPCRAFT_PART_INSTALL/lib/ && ln -s libImageProcessor*.so libImageProcessor.so

#2

one option to try might be to ship the udevadm binary inside your snap … that would override the attempt to use the one from the host.


#3

Thanks @ogra. This seems to work.