From ff79dc979322be71b5e538b633a2a3604b402551 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Tue, 22 Nov 2016 18:02:42 +1100 Subject: [PATCH] Catch errors in DIB_INIT_SYSTEM export When you source a file that just does export FOO=$(bar) you miss any invalid return codes from "bar" (even under -e) because bash returns the value of the "export", which is 0 On centos-minimal, we stopped bringing in systemd early and this was causing dib-init-system to not know what init was available. Since it did not fail correctly, it lead to confusing errors much later in the build when service files were not copied correctly. See also I24ce648485c3d6f3c27ab8f87a638516b3727017 A dib-lint check is added. One minor fixup is in 00-set-apt-sources (this one is less likely to cause problems). I have run dib-lint over project-config elements and none use this pattern. Change-Id: I076c08190d40c315ad6a6d96a3823e9fc52630be --- bin/dib-lint | 9 +++++++++ .../test-sources/environment.d/00-set-apt-sources | 3 ++- .../environment.d/10-dib-init-system.bash | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bin/dib-lint b/bin/dib-lint index c58865e5..8301ff2a 100755 --- a/bin/dib-lint +++ b/bin/dib-lint @@ -158,6 +158,15 @@ for i in $(find elements -type f \ fi fi + # check for + # export FOO=$(bar) + # calls. These are dangerous, because the export hides the return + # code of the $(bar) call. Split this into 2 lines and -e will + # fail on the assignment + if grep -q 'export .*\$(' $i; then + error "Split export and assignments in $i" + fi + # check that sudo calls in phases run outside the chroot look # "safe"; meaning that they seem to operate within the chroot # somehow. This is not fool-proof, but catches egregious errors, diff --git a/elements/apt-sources/test-elements/test-sources/environment.d/00-set-apt-sources b/elements/apt-sources/test-elements/test-sources/environment.d/00-set-apt-sources index 8442fc17..8034daf6 100644 --- a/elements/apt-sources/test-elements/test-sources/environment.d/00-set-apt-sources +++ b/elements/apt-sources/test-elements/test-sources/environment.d/00-set-apt-sources @@ -1 +1,2 @@ -export DIB_APT_SOURCES=$(mktemp) +DIB_APT_SOURCES=$(mktemp) +export DIB_APT_SOURCES diff --git a/elements/dib-init-system/environment.d/10-dib-init-system.bash b/elements/dib-init-system/environment.d/10-dib-init-system.bash index db640993..d683ce89 100644 --- a/elements/dib-init-system/environment.d/10-dib-init-system.bash +++ b/elements/dib-init-system/environment.d/10-dib-init-system.bash @@ -1 +1,2 @@ -export DIB_INIT_SYSTEM=$(PATH="$PATH:$(dirname $BASH_SOURCE)/.." dib-init-system) +DIB_INIT_SYSTEM=$(PATH="$PATH:$(dirname $BASH_SOURCE)/.." dib-init-system) +export DIB_INIT_SYSTEM