Electron, Classic Confinement, $UID, and systemd

Electron v2 finally moved to a more recent version of Chromium (and gtk3), but I’m having a surprisingly hard time getting our snap to run on Ubuntu 18.04 (it runs fine on 16.04).

What seems to be happening is that the current user id cannot be found, which then results in a snazzy broken syscall:

[pid  3936] write(2, "mkdir: ", 7mkdir: )      = 7
[pid  3936] write(2, "cannot create directory \342\200\230/run/"..., 52cannot create directory ‘/run/user//snap.slack/’) = 52

As a simple test, I’m now running the following on launch:

#!/bin/sh

mkdir -p “/run/user/$UID/snap.slack/” || true
exec “$@” --executed-from="$(pwd)" --pid=$$ > /dev/null 2>&1 &

Running $(id -u $USER) works, but returns always 0.

I’m having a very hard time finding the user id. I’m probably just doing something wrong, but I’d be very thankful for pointers!

This did the trick:

mkdir -p “/run/user/$(id -u $(whoami))/snap.slack/” || true

This is likely an issue with Electron, but I have a hard time figuring out why we don’t see similar issues outside our snap.

Is there any indication why it is trying to create that path? If you have code that needs to look up files relative to $XDG_RUNTIME_DIR, it should be using that environment variable directly.

Update: $XDG_RUNTIME_DIR is set, but we cannot assume that it exists.

If you’re using the desktop-launch script from snapcraft-desktop-helpers (e.g. in the form of the desktop-gtk3 cloud part), this should be taken care of for you.

If you aren’t using that script, perhaps just reuse it’s logic:

This is definitely something that we need to fix, but the above workaround should be safe even after the referenced bug is addressed.