mirror of
https://github.com/moparisthebest/pacman
synced 2024-08-13 17:03:46 -04:00
makepkg: restrict usage of errexit to user functions
It's expected that this will lead to unwanted behavior, and needs widespread testing. It's desirable to commit this for a few reasons: - there's no reason we can't do our own error checking for code that we write. - it avoids the need for ||true hacks scattered about in the code. - it makes us immune to upstream changes in exit codes (FS#28248) Signed-off-by: Dave Reisner <dreisner@archlinux.org>
This commit is contained in:
parent
3a82885348
commit
dca10b062f
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash -e
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
# makepkg - make packages compatible for use with pacman
|
# makepkg - make packages compatible for use with pacman
|
||||||
# @configure_input@
|
# @configure_input@
|
||||||
@ -437,13 +437,10 @@ run_pacman() {
|
|||||||
check_deps() {
|
check_deps() {
|
||||||
(( $# > 0 )) || return 0
|
(( $# > 0 )) || return 0
|
||||||
|
|
||||||
# Disable error trap in pacman subshell call as this breaks bash-3.2 compatibility
|
|
||||||
# Also, a non-zero return value is not unexpected and we are manually dealing them
|
|
||||||
set +E
|
|
||||||
local ret=0
|
local ret=0
|
||||||
local pmout
|
local pmout
|
||||||
pmout=$(run_pacman -T "$@") || ret=$?
|
pmout=$(run_pacman -T "$@")
|
||||||
set -E
|
ret=$?
|
||||||
|
|
||||||
if (( ret == 127 )); then #unresolved deps
|
if (( ret == 127 )); then #unresolved deps
|
||||||
printf "%s\n" "$pmout"
|
printf "%s\n" "$pmout"
|
||||||
@ -476,13 +473,7 @@ handle_deps() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# we might need the new system environment
|
# we might need the new system environment
|
||||||
# avoid triggering the ERR trap and exiting
|
|
||||||
set +e
|
|
||||||
local restoretrap=$(trap -p ERR)
|
|
||||||
trap - ERR
|
|
||||||
source /etc/profile &>/dev/null
|
source /etc/profile &>/dev/null
|
||||||
eval $restoretrap
|
|
||||||
set -e
|
|
||||||
|
|
||||||
return $R_DEPS_SATISFIED
|
return $R_DEPS_SATISFIED
|
||||||
}
|
}
|
||||||
@ -882,6 +873,23 @@ cd_safe() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run_function_safe() {
|
||||||
|
local restoretrap
|
||||||
|
|
||||||
|
set -e
|
||||||
|
set -E
|
||||||
|
|
||||||
|
restoretrap=$(trap -p ERR)
|
||||||
|
trap 'error_function $pkgfunc' ERR
|
||||||
|
|
||||||
|
run_function "$1"
|
||||||
|
|
||||||
|
eval $restoretrap
|
||||||
|
|
||||||
|
set +E
|
||||||
|
set +e
|
||||||
|
}
|
||||||
|
|
||||||
run_function() {
|
run_function() {
|
||||||
if [[ -z $1 ]]; then
|
if [[ -z $1 ]]; then
|
||||||
return 1
|
return 1
|
||||||
@ -907,7 +915,6 @@ run_function() {
|
|||||||
local shellopts=$(shopt -p)
|
local shellopts=$(shopt -p)
|
||||||
|
|
||||||
local ret=0
|
local ret=0
|
||||||
local restoretrap
|
|
||||||
if (( LOGGING )); then
|
if (( LOGGING )); then
|
||||||
local fullver=$(get_full_version)
|
local fullver=$(get_full_version)
|
||||||
local BUILDLOG="${startdir}/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log"
|
local BUILDLOG="${startdir}/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log"
|
||||||
@ -929,18 +936,12 @@ run_function() {
|
|||||||
tee "$BUILDLOG" < "$logpipe" &
|
tee "$BUILDLOG" < "$logpipe" &
|
||||||
local teepid=$!
|
local teepid=$!
|
||||||
|
|
||||||
restoretrap=$(trap -p ERR)
|
|
||||||
trap 'error_function $pkgfunc' ERR
|
|
||||||
$pkgfunc &>"$logpipe"
|
$pkgfunc &>"$logpipe"
|
||||||
eval $restoretrap
|
|
||||||
|
|
||||||
wait $teepid
|
wait $teepid
|
||||||
rm "$logpipe"
|
rm "$logpipe"
|
||||||
else
|
else
|
||||||
restoretrap=$(trap -p ERR)
|
|
||||||
trap 'error_function $pkgfunc' ERR
|
|
||||||
$pkgfunc 2>&1
|
$pkgfunc 2>&1
|
||||||
eval $restoretrap
|
|
||||||
fi
|
fi
|
||||||
# reset our shell options
|
# reset our shell options
|
||||||
eval "$shellopts"
|
eval "$shellopts"
|
||||||
@ -958,11 +959,11 @@ run_build() {
|
|||||||
[[ -d /usr/lib/ccache/bin ]] && export PATH="/usr/lib/ccache/bin:$PATH"
|
[[ -d /usr/lib/ccache/bin ]] && export PATH="/usr/lib/ccache/bin:$PATH"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
run_function "build"
|
run_function_safe "build"
|
||||||
}
|
}
|
||||||
|
|
||||||
run_check() {
|
run_check() {
|
||||||
run_function "check"
|
run_function_safe "check"
|
||||||
}
|
}
|
||||||
|
|
||||||
run_package() {
|
run_package() {
|
||||||
@ -973,7 +974,7 @@ run_package() {
|
|||||||
pkgfunc="package_$1"
|
pkgfunc="package_$1"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
run_function "$pkgfunc"
|
run_function_safe "$pkgfunc"
|
||||||
}
|
}
|
||||||
|
|
||||||
tidy_install() {
|
tidy_install() {
|
||||||
@ -2009,7 +2010,6 @@ for signal in TERM HUP QUIT; do
|
|||||||
done
|
done
|
||||||
trap 'trap_exit INT "$(gettext "Aborted by user! Exiting...")"' INT
|
trap 'trap_exit INT "$(gettext "Aborted by user! Exiting...")"' INT
|
||||||
trap 'trap_exit USR1 "$(gettext "An unknown error has occurred. Exiting...")"' ERR
|
trap 'trap_exit USR1 "$(gettext "An unknown error has occurred. Exiting...")"' ERR
|
||||||
set -E
|
|
||||||
|
|
||||||
# preserve environment variables and canonicalize path
|
# preserve environment variables and canonicalize path
|
||||||
[[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST})
|
[[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST})
|
||||||
|
Loading…
Reference in New Issue
Block a user