mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-14 23:55:49 +00:00
tools/packaging: Fix error path in 'kata-deploy-binaries.sh -s'
`make kata-tarball` relies on `kata-deploy-binaries.sh -s` which
silently ignores errors, and you may end up with an incomplete
tarball without noticing it because `make`'s exit status is 0.
`kata-deploy-binaries.sh` does set the `errexit` option and all the
code in the script seems to assume that since it doesn't do error
checking. Unfortunately, bash automatically disables `errexit` when
calling a function from a conditional pipeline, like done in the `-s`
case:
if [ "${silent}" == true ]; then
if ! handle_build "${t}" &>"$log_file"; then
^^^^^^
this disables `errexit`
and `handle_build` ends with a `tar tvf` that always succeeds.
Adding error checking all over the place isn't really an option
as it would seriously obfuscate the code. Drop the conditional
pipeline instead and print the final error message from a `trap`
handler on the special ERR signal. This requires the `errtrace`
option as `trap`s aren't propagated to functions by default.
Since all outputs of `handle_build` are redirected to the build
log file, some file descriptor duplication magic is needed for
the handler to be able to write to the orignal stdout and stderr.
Fixes #3757
Signed-off-by: Greg Kurz <groug@kaod.org>
(cherry picked from commit a779e19bee
)
Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
This commit is contained in:
parent
c9c7751184
commit
d1197ee8e5
@ -8,6 +8,7 @@
|
|||||||
set -o errexit
|
set -o errexit
|
||||||
set -o nounset
|
set -o nounset
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
set -o errtrace
|
||||||
|
|
||||||
readonly project="kata-containers"
|
readonly project="kata-containers"
|
||||||
|
|
||||||
@ -196,6 +197,18 @@ handle_build() {
|
|||||||
tar tvf "${tarball_name}"
|
tar tvf "${tarball_name}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
silent_mode_error_trap() {
|
||||||
|
local stdout="$1"
|
||||||
|
local stderr="$2"
|
||||||
|
local t="$3"
|
||||||
|
local log_file="$4"
|
||||||
|
exec 1>&${stdout}
|
||||||
|
exec 2>&${stderr}
|
||||||
|
error "Failed to build: $t, logs:"
|
||||||
|
cat "${log_file}"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
local build_targets
|
local build_targets
|
||||||
local silent
|
local silent
|
||||||
@ -248,11 +261,15 @@ main() {
|
|||||||
(
|
(
|
||||||
cd "${builddir}"
|
cd "${builddir}"
|
||||||
if [ "${silent}" == true ]; then
|
if [ "${silent}" == true ]; then
|
||||||
if ! handle_build "${t}" &>"$log_file"; then
|
local stdout
|
||||||
error "Failed to build: $t, logs:"
|
local stderr
|
||||||
cat "${log_file}"
|
# Save stdout and stderr, to be restored
|
||||||
exit 1
|
# by silent_mode_error_trap() in case of
|
||||||
fi
|
# build failure.
|
||||||
|
exec {stdout}>&1
|
||||||
|
exec {stderr}>&2
|
||||||
|
trap "silent_mode_error_trap $stdout $stderr $t \"$log_file\"" ERR
|
||||||
|
handle_build "${t}" &>"$log_file"
|
||||||
else
|
else
|
||||||
handle_build "${t}"
|
handle_build "${t}"
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user