Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions cronic
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,14 @@ if ((BASH_VERSINFO[0] > 4 || (BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 1)));
export BASH_XTRACEFD=$cronic_xtrace_fd
fi

# The command runs in a subshell rather than in this shell, so that a builtin
# such as `exit` or `exec` cannot end this script before it reports.
# `command` because a function of this script, such as `cronic_usage`, would
# otherwise run in place of a program of the same name.
set +e
# `command` because the wrapped command runs in this shell, where a function of
# this script, such as `cronic_usage`, would otherwise run in place of a
# program of the same name.
command -- "$@" > "$cronic_out" 2> "$cronic_trace"
(
command -- "$@" > "$cronic_out" 2> "$cronic_trace"
)
cronic_result=$?
set -e

Expand Down
6 changes: 6 additions & 0 deletions tests/cronic-test/cronic-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ for name in $function_names; do
done
PATH="$saved_path"

# The command may be a shell builtin.
check "builtin command" 0 silent :
# A builtin that would end the shell does not prevent the report.
check "exit builtin" 3 report exit 3
check "exec builtin" 3 report exec "$work/trace-only" 3

# The wrapped command sees the caller's exported variables unchanged. For
# each variable that `cronic` assigns, the caller exports that name in
# uppercase, both with and without any "cronic_" prefix (for example,
Expand Down
Loading