diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2023-05-12 16:11:14 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2023-05-12 16:11:14 -0400 |
commit | bc478a0a85bc8660bfa251866f85c673e4be84ac (patch) | |
tree | e93e2a286e2fbf5d936b38a6a0117e26d4ff2c66 /src | |
parent | 95f2827c80acc06fecf4b47e46d95a038e0c8664 (diff) | |
download | postgresql-bc478a0a85bc8660bfa251866f85c673e4be84ac.tar.gz postgresql-bc478a0a85bc8660bfa251866f85c673e4be84ac.zip |
Tighten usage of PSQL_WATCH_PAGER.
Don't use PSQL_WATCH_PAGER when stdin/stdout are not a terminal.
This corresponds to the restrictions on when other commands will
use [PSQL_]PAGER. There isn't a lot of sense in trying to use a
pager in non-interactive cases, and doing so allows an environment
setting to break our tests.
Also, ignore PSQL_WATCH_PAGER if it is set but empty or all-blank,
for the same reasons we ignore such settings of [PSQL_]PAGER (see
commit 18f8f784c).
No documentation change is really needed, since there is nothing
suggesting that these constraints on [PSQL_]PAGER didn't already
apply to PSQL_WATCH_PAGER too. But I rearranged the text
a little to make it read more naturally (IMHO anyway).
Per report from Pavel Stehule. Back-patch to v15 where
PSQL_WATCH_PAGER was introduced.
Discussion: https://postgr.es/m/CAFj8pRDTwFzmEWdA-gdAcUh0ZnxUioSfTMre71WyB_wNJy-8gw@mail.gmail.com
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/psql/command.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index bb94df50a63..897fbee8d6c 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -5020,14 +5020,20 @@ do_watch(PQExpBuffer query_buf, double sleep) /* * For \watch, we ignore the size of the result and always use the pager - * if PSQL_WATCH_PAGER is set. We also ignore the regular PSQL_PAGER or - * PAGER environment variables, because traditional pagers probably won't - * be very useful for showing a stream of results. + * as long as we're talking to a terminal and "\pset pager" is enabled. + * However, we'll only use the pager identified by PSQL_WATCH_PAGER. We + * ignore the regular PSQL_PAGER or PAGER environment variables, because + * traditional pagers probably won't be very useful for showing a stream + * of results. */ #ifdef HAVE_POSIX_DECL_SIGWAIT pagerprog = getenv("PSQL_WATCH_PAGER"); + /* if variable is empty or all-white-space, don't use pager */ + if (pagerprog && strspn(pagerprog, " \t\r\n") == strlen(pagerprog)) + pagerprog = NULL; #endif - if (pagerprog && myopt.topt.pager) + if (pagerprog && myopt.topt.pager && + isatty(fileno(stdin)) && isatty(fileno(stdout))) { disable_sigpipe_trap(); pagerpipe = popen(pagerprog, "w"); |