@@ -25,6 +25,26 @@ set -o errexit
2525set -o nounset
2626set -o pipefail
2727
28+ # Dump the call stack.
29+ #
30+ # $1: frames to skip
31+ function stack() {
32+ local frame=" ${1:- 0} "
33+ frame=" $(( frame+ 1 )) " # for this frame
34+ local indent=" "
35+ while [[ -n " ${FUNCNAME["${frame}"]:- } " ]]; do
36+ if [[ -n " $indent " ]]; then
37+ echo -ne " from "
38+ fi
39+ indent=" true"
40+ local file=" $( basename " ${BASH_SOURCE["${frame}"]} " ) "
41+ local line=" ${BASH_LINENO["$((frame-1))"]} " # ???
42+ local func=" ${FUNCNAME["${frame}"]:- } "
43+ echo -e " ${func} () ${file} :${line} "
44+ frame=" $(( frame+ 1 )) "
45+ done
46+ }
47+
2848# A handler for when we exit automatically on an error.
2949# Borrowed from kubernetes, which was borrowed from
3050# https://gist.github.com/ahendrix/7030300
@@ -33,10 +53,13 @@ function errexit() {
3353 # don't dump stacks.
3454 set +o | grep -qe " -o errexit" || return
3555
36- local file=" $( basename " ${BASH_SOURCE[1]} " ) "
37- local line=" ${BASH_LINENO[0]} "
38- local func=" ${FUNCNAME[1]:- } "
39- echo " FATAL: error at ${func} () ${file} :${line} " >&2
56+ # Dump stack
57+ echo -n " FATAL: error at " >&2
58+ stack 1 >&2 # skip this frame
59+
60+ # Exit, really, right now.
61+ local pgid=" $( cat /proc/self/stat | awk ' {print $5}' ) "
62+ kill -- -" ${pgid} "
4063}
4164
4265# trap ERR to provide an error handler whenever a command exits nonzero this
@@ -68,10 +91,13 @@ function _indent() {
6891}
6992
7093# run "$@" and indent the output
94+ #
95+ # See the workaround in errexit before you rename this.
7196function indent() {
7297 # This lets us process stderr and stdout without merging them, without
73- # bash-isms.
74- { " $@ " 2>&1 1>&3 | _indent; } 3>&1 1>&2 | _indent
98+ # bash-isms. This MUST NOT be wrapped in a conditional, or else errexit no
99+ # longer applies to the executed command.
100+ { set -o errexit; " $@ " 2>&1 1>&3 | _indent; } 3>&1 1>&2 | _indent
75101}
76102
77103# Track these globally so we only load it once.
@@ -189,6 +215,7 @@ function stage_file_and_deps() {
189215
190216 # stage dependencies of binaries
191217 if [[ -x " $file " ]]; then
218+ DBG " staging deps of file ${file} "
192219 while read -r lib; do
193220 indent stage_file_and_deps " ${staging} " " ${lib} "
194221 done < <( binary_to_libraries " ${file} " )
@@ -300,9 +327,9 @@ function binary_to_libraries() {
300327 ldd " ${bin} " \
301328 ` # skip static binaries` \
302329 | grep_allow_nomatch -v " statically linked" \
303- ` # linux-vdso.so.1 is a special virtual shared object from the kernel` \
330+ ` # linux-vdso is a special virtual shared object from the kernel` \
304331 ` # see: http://man7.org/linux/man-pages/man7/vdso.7.html` \
305- | grep_allow_nomatch -v ' linux-vdso.so.1 ' \
332+ | grep_allow_nomatch -v ' linux-vdso' \
306333 ` # strip the leading '${name} => ' if any so only '/lib-foo.so (0xf00)' remains` \
307334 | sed -E ' s#.* => /#/#' \
308335 ` # we want only the path remaining, not the (0x${LOCATION})` \
0 commit comments