Expose the launched SNAP application in environment variable

Bug #1969783 reported by Marco Trevisan (Treviño)
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
snapd
New
Undecided
Unassigned

Bug Description

Snaps may expose multiple applications, and desktop names depend on that.

To be able to figure out what would be the desktop name of a snapped application we should use the `$SNAP_NAME` variable, and that should be joined together with the application name. But there's no such information for us.

So for example running:
  snap run fooo.bar --shell

I have environment variables for fooo, but nothing for bar.

I can figure it from /proc/self/cgroup, but I think having a $SNAP_APP env variable would be useful.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Ah, `/proc/self/attr/current` that would be clearer, isn't readable either.

Revision history for this message
Alberto Mardegan (mardy) wrote :

Hi Marco, while the issue is clear (and in principle, what you are asking makes a lot of sense -- I'm actually surprised we don't have such a variable), please help me understand your use-case a bit better: who would use that variable, and why?

If you are asking this for a specific snap, one option is to define the variable yourself in your snapcraft file (https://forum.snapcraft.io/t/declaratively-defining-environment-variables/175).

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Hi Alberto,

So... Here I'm not targeting one single applications, but all the snapped applications that are using libnotify to notify the desktop. So, using per-snap variables is not an option.

In such case the apps may use desktop-id's that are not matching the actual icon ID, and in order to figure it out the only way is to use the snap app name.

The only way I've been able to figure it out has been using the cgroups, so something like this:
   https://gitlab.gnome.org/GNOME/libnotify/-/merge_requests/23/diffs?commit_id=a1dd92dc2a

But I'm wondering if there's a better way for it. Assuming that snaps can't access to their own /proc/self/attr/

Revision history for this message
Ilya Fedin (ilya-fedin) wrote :

I'm lacking such an API for constructing the value for QGuiApplication::setDesktopFileName (which is used for window association on Wayland, com.canonical.Unity counter via QGuiApplication::setBadgeNumber and whatnot via third-party Qt libraries) and for io.snapcraft.Settings.SetSub default-url-scheme-handler (marking the app as the default handler for an URL scheme). The former needs actual .desktop file name (SNAP_INSTANCE_NAME + app name) while the latter accepts just app name.

Revision history for this message
Ilya Fedin (ilya-fedin) wrote :

That's probably the same issue: https://bugs.launchpad.net/snapd/+bug/1669151

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.