I'm trying to create a snap for a one-file program in C. It links to GLESv2 and glfw. I have successfully produced the snap, but I failed to make it run. It doesn't even run straight from commandline, like this:
stopwatch
It omits this error:
bash: /usr/local/bin/stopwatch: No such file or directory
Turns out this was because I have previously installed stopwatch to /usr/local/bin and bash has cached the location. This is no longer the case and both stopwatch and snap run stopwatch fail the same way.
When I try to run it with this command:
snap run stopwatch
It does start, however, the program fails because it doesn't have access to video drivers, or so I understood from this and that. I tried to fix it by requiring xserver-xorg-video-all with no avail. Precisely, the errors are:
libGL error: unable to load driver: i965_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: i965
libGL error: unable to load driver: i965_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: i965
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
stopwatch: /build/glfw3-KYdbSD/glfw3-3.2.1/src/input.c:493: glfwSetMouseButtonCallback: Assertion `window != NULL' failed
.
Here's the snap:
name: stopwatch
version: 0.1
summary: stopwatch
description: stopwatch
type: app
confinement: devmode
icon: stopwatch.png
grade: devel
apps:
stopwatch:
command: stopwatch
plugs: [opengl, x11]
parts:
stopwatch:
plugin: make
source: .
build-packages: [libglfw3-dev, libgles2-mesa-dev, xserver-xorg-video-all]
stage-packages: [libglfw3, libgles2-mesa, xserver-xorg-video-all]
And the Github repository. Really, I don't know what to do next. I tried flatpak, but with it I can't even make it to produce a flatpak.
Snapcraft forum discussion is going on here.
We found out that
- The snap lacks
gcc(which I think I fixed by requiringbuild-essentialbuild package). - The snap doesn't build on clean Ubuntu 16.04 environment (probably because the program requires GLFW >= 3.2, which is only available on 17.04). This was probably fixed by changing the program's source to use
glfwWaitEventsinstead of the new functionglfwWaitEventsTimeout.
I ran sudo snappy-debug.security scanlog alongside my program. Here's the output.
kernel.printk_ratelimit = 0
= AppArmor =
Time: Oct 17 21:06:11
Log: apparmor="ALLOWED" operation="open" profile="snap.stopwatch.stopwatch" name="/sys/devices/pci0000:00/0000:00:02.0/revision" pid=11255 comm="stopwatch" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
File: /sys/devices/pci0000:00/0000:00:02.0/revision (read)
Suggestion:
* adjust program to not access '/sys/devices/pci0000:00/0000:00:02.0/revision'
= AppArmor =
Time: Oct 17 21:06:11
Log: apparmor="ALLOWED" operation="open" profile="snap.stopwatch.stopwatch" name="/sys/devices/pci0000:00/0000:00:02.0/revision" pid=11255 comm="stopwatch" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
File: /sys/devices/pci0000:00/0000:00:02.0/revision (read)
Suggestion:
* adjust program to not access '/sys/devices/pci0000:00/0000:00:02.0/revision'
= AppArmor =
Time: Oct 17 21:06:11
Log: apparmor="ALLOWED" operation="open" profile="snap.stopwatch.stopwatch" name="/sys/devices/pci0000:00/0000:00:02.0/revision" pid=11255 comm="stopwatch" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
File: /sys/devices/pci0000:00/0000:00:02.0/revision (read)
Suggestion:
* adjust program to not access '/sys/devices/pci0000:00/0000:00:02.0/revision'
= AppArmor =
Time: Oct 17 21:06:11
Log: apparmor="ALLOWED" operation="open" profile="snap.stopwatch.stopwatch" name="/sys/devices/pci0000:00/0000:00:02.0/revision" pid=11255 comm="stopwatch" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
File: /sys/devices/pci0000:00/0000:00:02.0/revision (read)
Suggestion:
* adjust program to not access '/sys/devices/pci0000:00/0000:00:02.0/revision'
= AppArmor =
Time: Oct 17 21:06:11
Log: apparmor="ALLOWED" operation="open" profile="snap.stopwatch.stopwatch" name="/sys/devices/pci0000:00/0000:00:02.0/revision" pid=11255 comm="stopwatch" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
File: /sys/devices/pci0000:00/0000:00:02.0/revision (read)
Suggestion:
* adjust program to not access '/sys/devices/pci0000:00/0000:00:02.0/revision'
= AppArmor =
Time: Oct 17 21:06:11
Log: apparmor="ALLOWED" operation="open" profile="snap.stopwatch.stopwatch" name="/sys/devices/pci0000:00/0000:00:02.0/revision" pid=11255 comm="stopwatch" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
File: /sys/devices/pci0000:00/0000:00:02.0/revision (read)
Suggestion:
* adjust program to not access '/sys/devices/pci0000:00/0000:00:02.0/revision'
= AppArmor =
Time: Oct 17 21:06:11
Log: apparmor="ALLOWED" operation="open" profile="snap.stopwatch.stopwatch" name="/sys/devices/pci0000:00/0000:00:02.0/revision" pid=11255 comm="stopwatch" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
File: /sys/devices/pci0000:00/0000:00:02.0/revision (read)
Suggestion:
* adjust program to not access '/sys/devices/pci0000:00/0000:00:02.0/revision'
= AppArmor =
Time: Oct 17 21:06:11
Log: apparmor="ALLOWED" operation="open" profile="snap.stopwatch.stopwatch" name="/sys/devices/pci0000:00/0000:00:02.0/revision" pid=11255 comm="stopwatch" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
File: /sys/devices/pci0000:00/0000:00:02.0/revision (read)
Suggestion:
* adjust program to not access '/sys/devices/pci0000:00/0000:00:02.0/revision'
= AppArmor =
Time: Oct 17 21:14:23
Log: apparmor="DENIED" operation="file_inherit" namespace="root//lxd-snapcraft-surely-fresh-corgi_<var-lib-lxd>" profile="/sbin/dhclient" name="/run/systemd/journal/stdout" pid=11932 comm="dhclient" requested_mask="wr" denied_mask="wr" fsuid=165536 ouid=165536
File: /run/systemd/journal/stdout (write)
Suggestions:
* adjust program to use $SNAP_DATA
* adjust program to use /run/shm/snap.$SNAP_NAME.*
= AppArmor =
Time: Oct 17 21:14:23
Log: apparmor="DENIED" operation="file_inherit" namespace="root//lxd-snapcraft-surely-fresh-corgi_<var-lib-lxd>" profile="/sbin/dhclient" name="/run/systemd/journal/stdout" pid=11932 comm="dhclient" requested_mask="wr" denied_mask="wr" fsuid=165536 ouid=165536
File: /run/systemd/journal/stdout (write)
Suggestions:
* adjust program to use $SNAP_DATA
* adjust program to use /run/shm/snap.$SNAP_NAME.*
I tried making a snap with all plugs printed by snap interfaces. That is, I made this:
apps:
stopwatch:
command: stopwatch
plugs: [account-control, alsa, autopilot-introspection, avahi-control, avahi-observe, bluetooth-control, bluez, broadcom-asic-control, browser-support, camera, classic-support, core-support, cups-control, dcdbas-control, desktop, desktop-legacy, docker-support, firewall-control, framebuffer, fuse-support, greengrass-support, gsettings, hardware-observe, hardware-random-control, hardware-random-observe, home, io-ports-control, joystick, kernel-module-control, kubernetes-support, kvm, libvirt, locale-control, log-observe, lxd-support, modem-manager, mount-observe, netlink-audit, netlink-connector, network, network-bind, network-control, network-manager, network-observe, network-setup-control, network-setup-observe, ofono, opengl, openvswitch, openvswitch-support, optical-drive, password-manager-service, physical-memory-control, physical-memory-observe, ppp, process-control, pulseaudio, raw-usb, removable-media, screen-inhibit-control, shutdown, snapd-control, system-observe, system-trace, time-control, timeserver-control, timezone-control, tpm, uhid, unity7, upower-observe, wayland, x11]
It still crashed the same way.
Successfully made a working flatpak. Maybe it will serve as a reference. Flatpak directory structure:
.
├── export
├── files
│ ├── bin
│ │ └── stopwatch
│ └── lib
│ ├── libglapi.so -> libglapi.so.0.0.0
│ ├── libglapi.so.0 -> libglapi.so.0.0.0
│ ├── libglapi.so.0.0.0
│ ├── libGLESv2.so -> libGLESv2.so.2.0.0
│ ├── libGLESv2.so.2 -> libGLESv2.so.2.0.0
│ ├── libGLESv2.so.2.0.0
│ ├── libglfw.so -> libglfw.so.3
│ ├── libglfw.so.3 -> libglfw.so.3.2
│ └── libglfw.so.3.2
├── metadata
└── var
├── run -> /run
└── tmp
Flatpak metadata:
[Application]
name=org.test.stopwatch
runtime=org.freedesktop.Platform/x86_64/1.6
sdk=org.freedesktop.Sdk/x86_64/1.6
command=stopwatch
[Context]
sockets=x11;
devices=dri;