Skip to content

exit: fix no /usr/bin/env error

Lyndon Brown requested to merge jnqnfe/live-build:no_env into master

if you execute the bootstrap stage with no internet connection, you get the following output:

[2020-03-10 19:18:46] lb bootstrap
P: Setting up clean exit handler
[2020-03-10 19:18:46] lb bootstrap_cache restore
[2020-03-10 19:18:46] lb bootstrap_debootstrap
P: Begin bootstrapping system...
P: If the following stage fails, the most likely cause of the problem is with your mirror configuration or a caching proxy.
P: Running debootstrap (download-only)...
I: Retrieving InRelease
I: Retrieving Release
E: Failed getting release file http://deb.debian.org/debian/dists/buster/Release
P: Begin unmounting filesystems...
P: Saving caches...
chroot: failed to run command ‘/usr/bin/env’: No such file or directory

the last line looked suspicious. investigating it turns out that there was a deficiency in the exit handler.

when debootstrap fails to download what it needs due to lack of a connection, that failure due to set -e causes the Exit() handler to kick in. Part of this includes outputting the Saving caches... line, before then making a call to Save_package_cache(). That in turn runs the command Chroot chroot "apt-get autoclean" || true. The Chroot() function includes a line starting with ${_LINUX32} chroot "${CHROOT}" /usr/bin/env which is the source of the last output line.

the reason we see this unexpected output is that with bootstrapping having failed, there is no /usr/bin/env within the chroot so it is bound to fail.

the fact is, the exit handler has no business trying to do pretty much anything that it does if the bootstrap_debootstrap stage has not completed.

this implements such a restriction and thus resolves the problem of this unexpected and confusing output in the described situation.

we will now see:

[2020-03-10 19:18:46] lb bootstrap
P: Setting up clean exit handler
[2020-03-10 19:18:46] lb bootstrap_cache restore
[2020-03-10 19:18:46] lb bootstrap_debootstrap
P: Begin bootstrapping system...
P: If the following stage fails, the most likely cause of the problem is with your mirror configuration or a caching proxy.
P: Running debootstrap (download-only)...
I: Retrieving InRelease
I: Retrieving Release
E: Failed getting release file http://deb.debian.org/debian/dists/buster/Release
Edited by Lyndon Brown

Merge request reports

Loading