Project

General

Profile

« Previous | Next » 

Revision 9651

bugfix: lib/sh/util.sh: convention of fds to use for command-specific alternate stdin/stdout/stderr: changed to 40/41/42 because 10/11/12 are used by eval (which is used by set_fds()). use of fd 10/11/12 will cause hard-to-find silent bugs because exec will not print an error when these are used. documented why not to use other series of fds for this purpose:

  1. do NOT use 1x, which are used by eval (which is used by set_fds())
  2. do NOT use 2x, which are used as global stdin/stdout/stderr
  3. do NOT use 3x, which are used for logging

View differences:

lib/sh/util.sh
488 488
	set_fds "$1"
489 489
}
490 490

  
491
# convention: use fd 10/11/12 for command-specific alternate stdin/stdout/stderr
491
# convention: use fd 40/41/42 for command-specific alternate stdin/stdout/stderr
492
# do NOT use 1x, which are used by eval (which is used by set_fds())
493
# do NOT use 2x, which are used as global stdin/stdout/stderr
494
# do NOT use 3x, which are used for logging
492 495

  
493 496
setup_log_fd() # view logging output at verbosity >= 5
494 497
{
lib/sh/db.sh
136 136
	mysql_load_data_format="${mysql_load_data_format%
137 137
}"
138 138
	ssh2local # ssh does not tunnel nonstandard fds
139
	mysql_ANSI "$@" 10<&0 <<EOF
140
LOAD DATA LOCAL INFILE '/dev/fd/10'
139
	mysql_ANSI "$@" 40<&0 <<EOF
140
LOAD DATA LOCAL INFILE '/dev/fd/40'
141 141
INTO TABLE $table_esc
142 142
$mysql_load_data_format
143 143
IGNORE 1 LINES
......
233 233
	log+ 2
234 234
	
235 235
	if can_log; then set -- --echo-all --echo-hidden "$@"; fi
236
	local redirs=("${redirs[@]}" '10<&0' "0<${stdin:-&20}" '13>&1')
237
		# not 11 (for 13) because it gives a "/dev/fd/11: Bad file descriptor"
238
		# error when 11 is set with exec right before the command instead of on
239
		# the subshell it's executed in
236
	local redirs=("${redirs[@]}" '40<&0' "0<${stdin:-&20}" '41>&1')
240 237
	(
241 238
		if can_log; then cat <<'EOF'
242 239
\timing on
......
244 241
EOF
245 242
		fi
246 243
		cat
247
	)|cmd_log_fd=1 command psql --file /dev/fd/10 --output /dev/fd/13 \
244
	)|cmd_log_fd=1 command psql --file /dev/fd/40 --output /dev/fd/41 \
248 245
--set ON_ERROR_STOP=1 --quiet "$@"
249 246
		# --output is for query *results*, not echoed statements
250 247
}

Also available in: Unified diff