Project

General

Profile

« Previous | Next » 

Revision 9210

lib/sh/util.sh: renamed limit_stderr to limit_log_fd, stdout2stderr to stdout2log_fd to clarify their purpose. log_fd is currently assumed to be 2.

View differences:

lib/sh/util.sh
144 144

  
145 145
err_fd=2 # stderr
146 146

  
147
# usage: (stdout2stderr; cmd...) || return
147
# usage: (stdout2log_fd; cmd...) || return
148 148
# `|| return` needed on Mac because of bug where -e doesn't apply to ()
149
stdout2stderr() { exec >&2; }
149
stdout2log_fd() { exec >&2; }
150 150

  
151 151
usage() { echo "Usage: $1" >&2; return 2; }
152 152

  
......
201 201

  
202 202
### command verbose output
203 203

  
204
# usage: (limit_stderr; cmd...) || return
204
# usage: (limit_log_fd; cmd...) || return
205 205
# `|| return` needed on Mac because of bug where -e doesn't apply to ()
206
function limit_stderr() { if ! (log++; can_log); then disable_logging; fi; }
206
function limit_log_fd() { if ! (log++; can_log); then disable_logging; fi; }
207 207

  
208 208

  
209 209
### command echoing
......
228 228
## external commands
229 229

  
230 230
function command()
231
# usage: [limit_stderr=1] [limit_stdout=1] [stderr_is_errors=1] command \
231
# usage: [limit_log_fd=1] [limit_stdout=1] [stderr_is_errors=1] command \
232 232
# extern_cmd...
233 233
# to view only explicitly-displayed errors: explicit_errors_only=1 script...
234 234
{
235
	if test "$limit_stdout"; then local stdout2stderr=1 limit_stderr=1; fi
236
	local stderr_is_errors="${stderr_is_errors-$stdout2stderr}"
235
	if test "$limit_stdout"; then local stdout2log_fd=1 limit_log_fd=1; fi
236
	local stderr_is_errors="${stderr_is_errors-$stdout2log_fd}"
237 237
	
238 238
	cmd2rel_path; (echo_params; can_log) && indent || true
239 239
	(
240 240
		# the following redirections must happen in exactly this order
241
		if test "$limit_stderr"; then limit_stderr; fi
242
		if test "$stdout2stderr"; then stdout2stderr; fi
241
		if test "$limit_log_fd"; then limit_log_fd; fi
242
		if test "$stdout2log_fd"; then stdout2log_fd; fi
243 243
		if test "$stderr_is_errors"; then exec 2>&"$err_fd"; fi
244 244
		
245 245
		exec -- "$@" # -- so cmd name not treated as `exec` option

Also available in: Unified diff