[4.0.7] hook environment does not contain snap-specific PATH and LD_LIBRARY_PATH (as it used to)
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Snapcraft |
Expired
|
Undecided
|
Unassigned | ||
snapd |
Invalid
|
Undecided
|
Unassigned |
Bug Description
snapcraft used to generate hook wrappers under meta/hooks/
#!/bin/sh
export PATH="$
export LD_LIBRARY_
export LD_LIBRARY_
export LD_LIBRARY_
exec "$SNAP/
https:/
https:/
However, this is no longer the case which leads to subtle errors.
Example (only visible if SNAPD_DEBUG=1 is set for snapd):
* the remove hook gets called during the snap removal;
* a binary gets executed in the hook which needs a shared library from a snap-specific LD_LIBRARY_PATH;
* the hook silently fails without performing the necessary cleanup.
Jun 26 13:17:01 node-hagecius snapd[28196]: taskrunner.go:437: DEBUG: Running task 7199 on Do: Run remove hook of "microstack" snap if present
Jun 26 13:17:01 node-hagecius snapd[28196]: task.go:337: DEBUG: 2020-06-
Jun 26 13:17:01 node-hagecius snapd[28196]: -----
...
Jun 26 13:17:01 node-hagecius snapd[28196]: DEBUG: execv(/
Jun 26 13:17:01 node-hagecius snapd[28196]: DEBUG: argv[1] = --hook=remove
Jun 26 13:17:01 node-hagecius snapd[28196]: DEBUG: argv[2] = microstack
Jun 26 13:17:01 node-hagecius snapd[28196]: DEBUG: umask restored to 022
Jun 26 13:17:01 node-hagecius snapd[28196]: DEBUG: working directory re-interpreted to /
Jun 26 13:17:01 node-hagecius snapd[28196]: + /snap/microstac
Jun 26 13:17:01 node-hagecius snapd[28196]: /snap/microstac
Jun 26 13:17:01 node-hagecius snapd[28196]: -----
Jun 26 13:17:01 node-hagecius snapd[28196]: taskrunner.go:437: DEBUG: Running task 7200 on Do: Disconnect interfaces of snap "microstack"
I understand that there was a design goal to remove wrappers
https:/
but this seems like a major breaking change.
Could snap.yaml be modified for a generated snap to include PATH and LD_LIBRARY_PATH (seeing how https:/
Hooks can accept a command-chain: ROOT/snap/ hooks/remove) then it is assumed you setup everything correctly and we just copy it over.
- if the hook was "installed" through a part we probably want to add the snapcraft-runner script into command-chain as we do for apps (I believe we do this already in the form of a wrapper and we need to upgrade to command chain)
- if the hook was in the project root ($PROJECT_
This behavior has not changed for hooks.
We don't add environment as it is not a list and there would be no easy way to override for a developers point of view.
Silently failing hooks is a snapd issue.