So close!

I am so close to having my app working with Snap! But I’m really stumped. The app consists of a service that runs in the tray and a gui application that the user runs whenever they want. So, I’m trying to include both applications in the same snap. It almost works, both apps run… but it looks like the second app (vision) is running from my home directory for some reason and so it cannot find its gstreamer plugins.

They both log their working directory when they startup so I can see what the problem is. The first app (revere) logs its working directory:

/snap/revere/x1/usr/local/revere

The second app (vision) logs its working directory and its:

/home/td

And that is not right. How can I get the second app to run from the same location as the first?

Here is my snapcraft.yaml… Any help here would be greatly appreciated:

# you probably want to 'snapcraft register <name>'
name: revere
# the base snap is the execution environment for this snap
base: core22
# just for humans, typically '1.2+git' or '1.3.2'
version: '0.1'
# 79 char long summary
summary: Open source, cross platform ONVIF compatible video surveillance.
description: |
A free, open source, onvif compatible, cross platform video surveillance system designed to run 
unobtrusively on standard desktop computers.
# must be 'stable' to release into candidate/stable channels
grade: devel
# use 'strict' once you have the right plugs and slots
confinement: classic

parts:
  revere:
    plugin: cmake
    source-type: git
    source: https://github.com/dicroce/revere
    build-packages:
      - git
      - curl
      - zip
      - unzip
      - tar
      - cmake
      - pkg-config
      - nasm
      - libxinerama-dev
      - libxcursor-dev
      - xorg-dev
      - libglu1-mesa-dev
      - bison
      - python3-distutils
      - flex
      - libgtk-3-dev
      - libayatana-appindicator3-dev
      - libunwind-dev
      - build-essential
    stage-packages:
      - libcurl3-gnutls
      - lzip
      - libxinerama1
      - libxcursor1
      - libglu1-mesa
      - libayatana-appindicator3-1
      - libunwind8
      - libglx0
      - libgl1-mesa-dri
      - xserver-xorg-video-all

apps:
  revere:
    command: usr/local/revere/revere
  vision:
    command: usr/local/revere/vision

you should start with proper strict confinement, classic behaves massively different and needs a lot of experience to keep the two environments apart from each other (snaps always run on top of their base snap and should only use libs from their own environment, making sure noting leaks through from the host here is not easy), to not be blocked by the sandboxing while developing, you can use --devmode while test-installing the snap.

your app seems to be a desktop app, you should use the gnome extension for this so you get all needed fonts, themes, gstreamer libs and other desktop related parts … as well as all needed environment variables a desktop app expects. just add extensions: [gnome] to the various apps:sections.

So, the following is almost working. After much trial and error I have discovered a set of plugs that allow revere to run… but Vision still has its current working directory set to my home directory for some reason and hence cannot find its plugins.

# snap notes:
# sudo snappy-debug.security scanlog

# you probably want to 'snapcraft register <name>'
name: revere
# the base snap is the execution environment for this snap
base: core22
# just for humans, typically '1.2+git' or '1.3.2'
version: '0.1'
# 79 char long summary
summary: Open source, cross platform ONVIF compatible video surveillance.
description: |
  A free, open source, onvif compatible, cross platform video surveillance system designed to run     unobtrusively on standard desktop computers.
# must be 'stable' to release into candidate/stable channels
grade: devel
# use 'strict' once you have the right plugs and slots
confinement: strict

parts:
  revere:
    plugin: cmake
    source-type: git
    source: https://github.com/dicroce/revere
    build-packages:
      - git
      - curl
      - zip
      - unzip
      - tar
      - cmake
      - pkg-config
      - nasm
      - libxinerama-dev
      - libxcursor-dev
      - xorg-dev
      - libglu1-mesa-dev
      - bison
      - python3-distutils
      - flex
      - libgtk-3-dev
      - libayatana-appindicator3-dev
      - libunwind-dev
      - build-essential
    stage-packages:
      - libcurl3-gnutls
      - lzip
      - libxinerama1
      - libxcursor1
      - libglu1-mesa
      - libayatana-appindicator3-1
      - libunwind8
      - libglx0
      - libgl1-mesa-dri
      - xserver-xorg-video-all

apps:
  revere:
    command: usr/local/revere/revere
    plugs: [process-control, home, network, network-bind, network-control, network-manager,     network-manager-observe, network-observe, network-setup-control, network-setup-observe,     network-status, removable-media, opengl, desktop, avahi-control, avahi-observe, desktop-launch]
    extensions: [gnome]
  vision:
    command: usr/local/revere/vision
    plugs: [process-control, home, network, network-bind, network-control, network-manager,     network-manager-observe, network-observe, network-setup-control, network-setup-observe,     network-status, removable-media, opengl, desktop, avahi-control, avahi-observe, desktop-launch]
    extensions: [gnome]

Seems it has a hard coded function to read your home from /etc/passwd instead of respecting the $HOME variable … might be that you need to patch it …

That is the code where it finds the current users home directory (in Vision’s case i believe this is probably because it wants to to write its logs to $HOME/Documents/revere/revere/logs… in Revere’s case everything it writes is under that folder (video, exports, logs, config files, etc))… That isn’t the problem… the problem is that the process that is running Vision has its current working directory (as returned by getcwd() under libc) set to the users home directory… The Revere app running in this snap has its cwd set to the correct place and it is able to find its plugins… the vision binary is sitting in the same directory as Revere (its placed there by the cmake install target) but it is being run from a different place.

well, if it is just using getcwd() you can add a simply command-chain script like:

#! /bin/sh

cd $SNAP_USER_DATA
exec"$"

to make it go to the proper writable space before launching …

Is there an environment variable that has the path to the binary? I just want the binary run from the same location it is installed to (like it’s doing for the revere binary).

On this page:

If you scroll down to the “override-build” section there is a line that has a clue: “The working directory is the base build directory for the given part.”… so perhaps because vision doesn’t have a part defined for it (it is built as part of the the revere build) it didn’t get its cwd set?

that will be read-only but it sits underneath $SNAP (which translates to /snap/<snap name>/current)

It doesn’t write to its cwd directory… it writes to a folder under the users Documents folder… It just needs to be run from (have its cwd set to) the same directory the vision binary is sitting in.

So, i finally figured this out. The reason Revere was working but Vision wasn’t was that revere had some code at startup that changed the current working directory to be the same directory the executable was located in… I put similar code in Vision and all is well.

Do you have any advice for getting autostart working for revere?

1 Like

if you want to use it as a system process you just add a daemon: entry to your apps: section …

for the desktop you need to ship an autostart .desktop file and add it to your snapcraft.yaml like: