Project

General

Profile

« Previous | Next » 

Revision 11360

bugfix: lib/sh/db.sh: avoid outputting to /dev/fd/# when running as sudo on Linux, because this causes a "Permission denied" error (due to the /dev/fd/# file being owned by a different user). this is not a problem with normal redirects (>&#), because they do not use /dev/fd/# files which can have access permissions.

View differences:

lib/sh/db.sh
269 269
if self_being_included; then
270 270

  
271 271
psql() # usage: [stdin=copy_pstdin_file] psql <<<"cmds, e.g. \copy from pstdin"
272
# SUDO_USER: when set, avoids outputting to /dev/fd/#, because this causes a
273
# "Permission denied" error when running as sudo on Linux
272 274
{
273 275
	echo_func; kw_params stdin
276
	local verbose_="$(! isset SUDO_USER; exit2bool)"; echo_vars verbose_
274 277
	
275
	if can_log; then set -- --echo-all --echo-hidden "$@"; fi
278
	if test "$verbose_" && can_log; then set -- --echo-all --echo-hidden "$@";fi
276 279
	local redirs=("${redirs[@]}" '40<&0' "0<${stdin:-&20}" '41>&1')
277 280
	(
278 281
		# hide stack traces/DETAIL sections of error messages at verbosity <2
279 282
		if ! clog++ can_log; then echo '\set VERBOSITY terse'; fi
280
		if can_log; then cat <<'EOF'
283
		if test "$verbose_" && can_log; then cat <<'EOF'
281 284
\timing on
282 285
SET client_min_messages = NOTICE;
283 286
EOF
284 287
		fi
285 288
		cat
286
	)|cmd_log_fd=1 pg_cmd --file /dev/fd/40 --output /dev/fd/41 \
287
--set ON_ERROR_STOP=1 --quiet "$@"
289
	)|cmd_log_fd=${verbose_:+1} pg_cmd --file /dev/fd/40 \
290
${verbose_:+--output /dev/fd/41 }--set ON_ERROR_STOP=1 --quiet "$@"
288 291
		# --output is for query *results*, not echoed statements
289 292
}
290 293

  

Also available in: Unified diff