Skip to content

Commit aec6495

Browse files
authored
Merge pull request #4211 from flatcar/chewi/die-faster
common.sh: Make `die` in a subshell actually stop everything immediately
2 parents 8ea7880 + cadc674 commit aec6495

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

  • sdk_container/src/third_party/coreos-overlay/coreos/config/env/sys-process

common.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,30 @@ die_notrace() {
161161
for line in "$@"; do
162162
error "${DIE_PREFIX}${line}"
163163
done
164+
165+
# `exit` only leaves the current shell. When die is reached inside a $(...)
166+
# command substitution or other subshell, the parent keeps running with bad
167+
# data and usually hits another die, so the same failure gets reported several
168+
# times. BASHPID (unlike $$, which stays the top-level PID even in subshells)
169+
# lets us detect that case and signal the main script so the whole run stops
170+
# immediately. Passing 0 to kill terminates the whole process group.
171+
[[ ${BASHPID:-$$} != $$ ]] && kill -s TERM 0
164172
exit 1
165173
}
166174

175+
# When die fires inside a subshell it uses `kill -s TERM 0` to bring the whole
176+
# process group down (see die_notrace). Without a handler the main shell is
177+
# terminated by that signal and reports exit code 143. Trap SIGTERM in the
178+
# top-level shell so it exits with the conventional failure code 1 instead.
179+
# Subshells reset traps to their default, so they are unaffected and still die
180+
# immediately from the group signal.
181+
#
182+
# Only arm this in the real top-level shell (BASHPID == $$), and never clobber
183+
# an existing TERM trap. The latter keeps re-sourcing common.sh idempotent and
184+
# defers to any caller that installed its own handler first. Note that `trap -p`
185+
# reports the parent's traps even from a command substitution.
186+
[[ ${BASHPID:-$$} == $$ && -z $(trap -p TERM) ]] && trap 'exit 1' TERM
187+
167188
# Simple version comparison routine
168189
# Note: not a true semver comparison and build revisions are ignored
169190
cmp_ver() {
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# Do not install Gentoo-provided audit rules, we will install our own
22
# in coreos-base/misc-files. Also skip installing legacy initscripts
33
# stuff in /usr/libexec.
4-
audit_install_mask=" /etc/audit/audit.rules* /usr/libexec "
5-
INSTALL_MASK+="${audit_install_mask}"
6-
PKG_INSTALL_MASK+="${audit_install_mask}"
7-
unset audit_install_mask
4+
INSTALL_MASK+=" /etc/audit/audit.rules* /usr/libexec "
5+
6+
cros_post_src_install_audit_flatcar_modifications() {
7+
# Upstream installs its tmpfiles config file with unnecessarilly
8+
# restrictive mode, relax it.
9+
#
10+
# https://github.com/linux-audit/audit-userspace/pull/547
11+
fperms 0644 /usr/lib/tmpfiles.d/audit.conf
12+
}

0 commit comments

Comments
 (0)