Freeshow can't make MIDI connections and crashes when trying

Hey everyone!

One of the snaps I maintain, Freeshow, crashes when a user attempts to access anything MIDI related. This is probably because it’s an electron app, and snapd is assuming electron apps don’t need direct access to ALSA (MIDI control being part of ALSA) and is sandboxing that.

Checking the allowed connections, I found there is no way to connect to ALSA. There’s pulseaudio, but that wouldn’t do it because MIDI isn’t a pulseaudio function and requires a bridge.

$ sudo snap connections freeshow
Interface               Plug                      Slot                            Notes
audio-playback          freeshow:audio-playback   :audio-playback                 -
browser-support         freeshow:browser-support  :browser-support                -
content[gnome-42-2204]  freeshow:gnome-42-2204    gnome-42-2204:gnome-42-2204     -
content[gtk-3-themes]   freeshow:gtk-3-themes     gtk-common-themes:gtk-3-themes  -
content[gtk-3-themes]   freeshow:gtk-3-themes     gtk-theme-orchis:gtk-3-themes   -
content[icon-themes]    freeshow:icon-themes      gtk-common-themes:icon-themes   -
content[sound-themes]   freeshow:sound-themes     gtk-common-themes:sound-themes  -
desktop                 freeshow:desktop          :desktop                        -
desktop-legacy          freeshow:desktop-legacy   :desktop-legacy                 -
gsettings               freeshow:gsettings        :gsettings                      -
home                    freeshow:home             :home                           -
network                 freeshow:network          :network                        -
opengl                  freeshow:opengl           :opengl                         -
pulseaudio              freeshow:pulseaudio       -                               -
unity7                  freeshow:unity7           :unity7                         -
wayland                 freeshow:wayland          :wayland                        -
x11                     freeshow:x11              :x11                            -

Therefore, the only thing I can think is that snapd needs some way to access ALSA directly and that some sort of support needs to be allowed for an application such as this to be able to do so. That, or maybe there’s a different way.

Any ideas?

You mean like ?

Ha! Yes, however, as you can see, there’s no such connection in this case, meaning I’ll have to patch the snapcraft.yaml file and get back to you on this. Electron apps are finicky since the snap is created by electron-build and not by your regular means. Quite frustrating, really.

Well, it’s a little more complicated then that it turns out as the application is attempting to access the absolute path of /usr/share/alsa/alsa.conf as opposed to using system APIs that may be exposed. This, in turn, is causing a segfault in the snap when it attempts to access that file and cannot, even if that file is staged.

As I stated in the issue, even when I got the alsa interface exposed to the application, it still didn’t work because it’s attempting to access that absolute path file as a strictly confined application, so it’s clearly a bug in the app.

Yeah, just staging it will not be sufficient, you will need a layout to re-map it to the correct path…

Alternatively you might be able to use the system-files interface to access the file from the host…

In general I’d consider switching away from electron-build, this is fine for simple snaps that work without any adjustments, but as you mentioned it becomes a pain as soon as you need to adjust things

Repackaging it was a success, but adding the system-files interface was not. Here’s the snapcraft.yaml:

base: core22
grade: stable
confinement: strict
plugs:
  usr-share-alsa:
    interface: system-files
    read:
      - /usr/share/alsa/alsa.conf
  gnome-42-2204:
    interface: content
    target: $SNAP/gnome-platform
    default-provider: gnome-42-2204
  gtk-3-themes:
    interface: content
    target: $SNAP/data-dir/themes
    default-provider: gtk-common-themes
  icon-themes:
    interface: content
    target: $SNAP/data-dir/icons
    default-provider: gtk-common-themes
  sound-themes:
    interface: content
    target: $SNAP/data-dir/sounds
    default-provider: gtk-common-themes
name: freeshow
version: 1.3.0
title: FreeShow
summary: FreeShow
description: Show song lyrics and more for free!
architectures:
  - amd64
apps:
  freeshow:
    command: command.sh
    plugs:
      - alsa
      - usr-share-alsa
      - desktop
      - desktop-legacy
      - home
      - x11
      - wayland
      - unity7
      - browser-support
      - network
      - gsettings
      - audio-playback
      - pulseaudio
      - opengl
    environment:
      DISABLE_WAYLAND: '1'
      PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
      SNAP_DESKTOP_RUNTIME: $SNAP/gnome-platform
      LD_LIBRARY_PATH: $SNAP_LIBRARY_PATH:$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/x86_64-linux-gnu:$SNAP/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH:$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/x86_64-linux-gnu:$SNAP/usr/lib/x86_64-linux-gnu
parts:
  freeshow:
    source: ./dist/linux-unpacked/
    plugin: dump
    stage-packages:
      - libasound2

Messy, but it works, aside from the unfortunate same error occurring.