Revision 9436
Added by Aaron Marcuse-Kubitza over 11 years ago
util.sh | ||
---|---|---|
534 | 534 |
# if no cmd_log_fd, limit log_fd in case command uses util.sh |
535 | 535 |
local cmd_log_fd="${cmd_log_fd-$log_fd}" |
536 | 536 |
|
537 |
cmd2rel_path; echo_params; if can_log; then indent; fi |
|
537 |
# determine redirections now so they can be logged along with the command |
|
538 |
local _redirs=() # prepend _ to avoid collisions with command's kw params |
|
539 |
# the following redirections must happen in exactly this order |
|
540 |
if test "$cmd_log_fd"; then |
|
541 |
if can_log; then |
|
542 |
if test "$cmd_log_fd" != "$log_fd"; then |
|
543 |
_redirs+=("$cmd_log_fd>&$log_fd") |
|
544 |
fi # else no redir needed |
|
545 |
else _redirs+=("$cmd_log_fd>/dev/null"); |
|
546 |
fi |
|
547 |
fi |
|
548 |
if test "$cmd_log_fd" != 2; then # fd 2 not used for logging |
|
549 |
_redirs+=("2>&$err_fd") # assume fd 2 used for errors |
|
550 |
fi |
|
551 |
|
|
552 |
cmd2rel_path; echo_cmd "$@" "${_redirs[@]}"; if can_log; then indent; fi |
|
538 | 553 |
( |
539 |
# the following redirections must happen in exactly this order |
|
540 |
if test "$cmd_log_fd"; then command__set_fds; fi |
|
541 |
if test "$cmd_log_fd" != 2; then # fd 2 not used for logging |
|
542 |
exec 2>&"$err_fd" # assume fd 2 used for errors |
|
543 |
fi |
|
554 |
log++ set_fds "${_redirs[@]}" |
|
544 | 555 |
|
545 | 556 |
if test "$verbosity_min"; then verbosity_min "$verbosity_min"; fi |
546 | 557 |
|
547 | 558 |
exec -- "$@" # -- so cmd name not treated as `exec` option |
548 | 559 |
) || return |
549 | 560 |
} |
550 |
function command__set_fds() |
|
551 |
{ |
|
552 |
ensure_nested_func |
|
553 |
if can_log; then |
|
554 |
if test "$cmd_log_fd" = "$log_fd"; then return 0; fi # no redir needed |
|
555 |
local src="&$log_fd" |
|
556 |
else local src=/dev/null |
|
557 |
fi |
|
558 |
log++ set_fds "$cmd_log_fd>$src" |
|
559 |
} |
|
560 | 561 |
|
561 | 562 |
# auto-echo common external commands |
562 | 563 |
for cmd in env rm; do alias "$cmd=command $cmd"; done; unset cmd |
Also available in: Unified diff
lib/sh/util.sh: command(): determine redirections before echoing the command so they can be logged along with the command, instead of as separate exec statements. (these had a higher log_level to avoid cluttering the output with `exec` lines, which usually suppressed the redirections completely.) inline the command__set_fds() nested func so the redirections are all in one place.