@@ -25,6 +25,26 @@ set -o errexit
25
25
set -o nounset
26
26
set -o pipefail
27
27
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
+
28
48
# A handler for when we exit automatically on an error.
29
49
# Borrowed from kubernetes, which was borrowed from
30
50
# https://gist.github.com/ahendrix/7030300
@@ -33,10 +53,13 @@ function errexit() {
33
53
# don't dump stacks.
34
54
set +o | grep -qe " -o errexit" || return
35
55
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} "
40
63
}
41
64
42
65
# trap ERR to provide an error handler whenever a command exits nonzero this
@@ -68,10 +91,13 @@ function _indent() {
68
91
}
69
92
70
93
# run "$@" and indent the output
94
+ #
95
+ # See the workaround in errexit before you rename this.
71
96
function indent() {
72
97
# 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
75
101
}
76
102
77
103
# Track these globally so we only load it once.
@@ -189,6 +215,7 @@ function stage_file_and_deps() {
189
215
190
216
# stage dependencies of binaries
191
217
if [[ -x " $file " ]]; then
218
+ DBG " staging deps of file ${file} "
192
219
while read -r lib; do
193
220
indent stage_file_and_deps " ${staging} " " ${lib} "
194
221
done < <( binary_to_libraries " ${file} " )
@@ -300,9 +327,9 @@ function binary_to_libraries() {
300
327
ldd " ${bin} " \
301
328
` # skip static binaries` \
302
329
| 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` \
304
331
` # 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' \
306
333
` # strip the leading '${name} => ' if any so only '/lib-foo.so (0xf00)' remains` \
307
334
| sed -E ' s#.* => /#/#' \
308
335
` # we want only the path remaining, not the (0x${LOCATION})` \
0 commit comments