Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically lookup the base snap name #262

Merged
merged 5 commits into from
Jan 10, 2024

Conversation

simondeziel
Copy link
Member

Rather than hardcode the core base name, look it up where/when needed. This was tested locally:

daemon.start:

$ sudo ls -l /var/snap/lxd/common/mntns/etc/ | grep core
lrwxrwxrwx 1 root root   37 Jan  9 12:48 alternatives -> /snap/core22/current/etc/alternatives
lrwxrwxrwx 1 root root   33 Jan  9 12:48 apparmor -> /snap/core22/current/etc/apparmor
lrwxrwxrwx 1 root root   35 Jan  9 12:48 apparmor.d -> /snap/core22/current/etc/apparmor.d

editor:

$ EDITOR=foo lxc config edit &
$ grep -a 'core[0-9]*' "/proc/$(pgrep vim.tiny)/environ"
LESSOPEN=| /usr/bin/lesspipe %s
HISTTIMEFORMAT=%F %T 
LANGUAGE=en_CA:en
LC_TIME=C.UTF-8
SNAP_COMMON=/var/snap/lxd/common
SNAP_INSTANCE_KEY=USER=sdeziel
XDG_SESSION_TYPE=x11
LXD_CONF=/home/sdeziel/snap/lxd/common/config
LD_LIBRARY_PATH=/var/lib/snapd/lib/gl:/var/lib/snapd/lib/gl32:/var/lib/snapd/void:/snap/lxd/x1/lib:/snap/lxd/x1/lib/x86_64-linux-gnu
SHLVL=0
SNAP_UID=1000
TEMPDIR=/tmp
HOME=/home/sdeziel/snap/lxd/x1
SNAP_LIBRARY_PATH=/var/lib/snapd/lib/gl:/var/lib/snapd/lib/gl32:/var/lib/snapd/void
DESKTOP_SESSION=ubuntu
SNAP_USER_DATA=/home/sdeziel/snap/lxd/x1
...
VIMINIT=source /snap/core22/current/etc/vim/vimrc
...
EDITOR=/snap/lxd/x1/bin/editor foo

kmod:

# nsenter -m -t "$(lxc info | awk '/server_pid:/ {print $2}')" sh -x /usr/sbin/lsmod | grep ^+
+ basename /usr/sbin/lsmod
+ NAME=lsmod
+ sed -n /^name:/ s/^name:\s*\(core[0-9]\{2\}\)/\1/p /meta/snap.yaml
+ SNAP_BASE=core22
+ id -u
+ [ 0 != 0 ]
+ [ lsmod = lsmod ]
+ exec /snap/core22/current/bin/kmod list

This changes `[ "name: core2X" != "name: core2Y" ]` to
`[ "core2X" != "core2Y" ]` but avoids reading the new base's
/meta/snap.yaml twice.

Signed-off-by: Simon Deziel <[email protected]>
@simondeziel simondeziel marked this pull request as ready for review January 9, 2024 18:09
@tomponline tomponline merged commit d6a902c into canonical:latest-edge Jan 10, 2024
3 checks passed
@simondeziel simondeziel deleted the lookup-base-name branch January 10, 2024 13:25
@simondeziel
Copy link
Member Author

FTR, I asked if snap could get a SNAP_BASE variable to avoid resorting to "parsing" that yaml file ourselves. https://forum.snapcraft.io/t/environment-variables/7983/36?u=sdeziel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants