Revision 13285
Added by Aaron Marcuse-Kubitza almost 11 years ago
db.sh | ||
---|---|---|
287 | 287 |
|
288 | 288 |
psql() # usage: [stdin=copy_pstdin_file|<(pstdin_cmd)] [output_data=1] psql \ |
289 | 289 |
# <<<"cmds (eg. \copy from pstdin)" |
290 |
# $as_root: when on, avoids redirections as these are not passed through by sudo |
|
290 | 291 |
# SUDO_USER: when set, avoids outputting to /dev/fd/#, because this causes a |
291 | 292 |
# "Permission denied" error when running as sudo on Linux |
292 | 293 |
{ |
293 | 294 |
echo_func; kw_params stdin output_data |
294 |
local can_redir="$(! isset SUDO_USER; exit2bool)"; echo_vars can_redir |
|
295 |
local can_redir="$(! test "$as_root" && ! isset SUDO_USER; exit2bool)" |
|
296 |
echo_vars can_redir |
|
295 | 297 |
if test "$stdin"; then |
296 | 298 |
test "$can_redir" || die 'custom $stdin not supported with sudo' |
297 | 299 |
fi |
... | ... | |
301 | 303 |
echo_vars data2stdout |
302 | 304 |
|
303 | 305 |
if test "$verbose_"; then set -- --echo-all --echo-hidden "$@"; fi |
304 |
local redirs=("${redirs[@]}" '40<&0' "0<${stdin:-&20}" '41>&1')
|
|
306 |
local redirs=("${redirs[@]}" '40<&0' ${can_redir:+"0<${stdin:-&20}" }'41>&1')
|
|
305 | 307 |
( |
306 | 308 |
# hide stack traces/DETAIL sections of error messages at verbosity <2 |
307 | 309 |
if ! log++ can_log; then echo '\set VERBOSITY terse'; fi |
Also available in: Unified diff
bugfix: psql(): when as_root is on, need to avoid redirections as these are not passed through by sudo