Comment 8 for bug 1791691

Revision history for this message
Scott Moser (smoser) wrote :

Summary: environment-generators inherit environment that /sbin/init
started with, but no other systemd defaults. Therefore, there is no
easy way to append to an environment variable that is not set as snapd
was hoping to do. The only solution currently is to copy the expected
"default path" into the snapd environment-generator.

Long winded comment following.

I've attached an example environment-generator above, and then with it
installed and a 'print-path.service', we can see that the proposed solution in
https://github.com/snapcore/snapd/pull/5808 does not work.

To quote xnox from https://bugs.launchpad.net/cloud-init/+bug/1771382
  "Systemd by default executes things, with execv, not execve. Hence the default environment is not available."

Here is some output collected from the 4 MODE values in a container, followed by in a kvm guest booted with an initramfs.

In both cases there are no other environment generators enabled.

The inherited PATH is as follows:
  initramfs boot: PATH=/sbin:/usr/sbin:/bin:/usr/bin:/snapd/bin
  lxd container: PATH=None # not present

----- container -----

$ lxc exec c3 -- cat /run/path-generator-test.log
current PATH=None
mode=append-ref
writing 'PATH=$PATH:/snapd/bin'
=== printing ===
found PATH=$PATH:/snapd/bin

$ lxc exec c3 -- cat /run/path-generator-test.log
current PATH=None
mode=append-full
writing 'PATH=:/snapd/bin'
=== printing ===
found PATH=:/snapd/bin

$ lxc exec c3 -- cat /run/path-generator-test.log
current PATH=None
mode=none
writing ''
=== printing ===
found PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

$ lxc exec c3 -- cat /run/path-generator-test.log
current PATH=None
mode=snapd-only
writing 'PATH=/snap/bin'
=== printing ===
found PATH=/snap/bin

------ kvm guest -----
$ cat /run/path-generator-test.log
current PATH=/sbin:/usr/sbin:/bin:/usr/bin
mode=append-ref
writing 'PATH=$PATH:/snapd/bin'
=== printing ===
found PATH=$PATH:/snapd/bin

$ cat /run/path-generator-test.log
current PATH=/sbin:/usr/sbin:/bin:/usr/bin
mode=append-full
writing 'PATH=/sbin:/usr/sbin:/bin:/usr/bin:/snapd/bin'
=== printing ===
found PATH=/sbin:/usr/sbin:/bin:/usr/bin:/snapd/bin

$ cat /run/path-generator-test.log
current PATH=/sbin:/usr/sbin:/bin:/usr/bin
mode=snapd-only
writing 'PATH=/snap/bin'
=== printing ===
found PATH=/snap/bin

$ cat /run/path-generator-test.log
current PATH=/sbin:/usr/sbin:/bin:/usr/bin
mode=snapd-only
writing 'PATH=/snap/bin'
=== printing ===
found PATH=/snap/bin