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


** Description changed:

  systemd units have broken PATH in recent cloud images.
  The PATH set for them is
    PATH=:/snap/bin.
  Previously value is
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  
  # cat /etc/cloud/build.info
  build_name: server
  serial: 20180906
  
  Booted in lxc that fails like:
  # lxc launch ubuntu-daily:cosmic c3
  # lxc exec c3 cat /run/cloud-init/result.json
  {
   "v1": {
    "datasource": null,
    "errors": [
     "Unexpected error while running command.\nCommand: ['netplan', 
'generate']\nExit code: -\nReason: [Errno 2] No such file or directory: 
b'netplan': b'netplan'\nStdout: -\nStderr: -",
     "Unexpected error while running command.\nCommand: ['netplan', 
'generate']\nExit code: -\nReason: [Errno 2] No such file or directory: 
b'netplan': b'netplan'\nStdout: -\nStderr: -",
     "('ssh-authkey-fingerprints', KeyError('getpwnam(): name not found: 
ubuntu',))"
    ]
   }
  }
+ 
+ 
+ Related bugs:
+  * bug 1771382: ds-identify: does not have expected PATH.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1791691

Title:
  PATH broken in systemd units

To manage notifications about this bug go to:
https://bugs.launchpad.net/cloud-images/+bug/1791691/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to