Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit18f8f78

Browse files
committed
Handle empty or all-blank PAGER setting more sanely in psql.
If the PAGER environment variable is set but contains an empty string,psql would pass it to "sh" which would silently exit, causing whateverquery output we were printing to vanish entirely. This is quitemystifying; it took a long time for us to figure out that this was thecause of Joseph Brenner's trouble report. Rather than allowing thatto happen, we should treat this as another way to specify "no pager".(We could alternatively treat it as selecting the default pager, butit seems more likely that the former is what the user meant to achieveby setting PAGER this way.)Nonempty, but all-white-space, PAGER values have the same behavior, andit's pretty easy to test for that, so let's handle that case the same way.Most other cases of faulty PAGER values will result in the shell printingsome kind of complaint to stderr, which should be enough to diagnose theproblem, so we don't need to work harder than this. (Note that there'sbeen an intentional decision not to be very chatty about apparent failurereturns from the pager process, since that may happen if, eg, the userquits the pager with control-C or some such. I'd just as soon not startsplitting hairs about which exit codes might merit making our own report.)libpq's old PQprint() function was already on board with ignoring emptyPAGER values, but for consistency, make it ignore all-white-space valuesas well.It's been like this a long time, so back-patch to all supported branches.Discussion:https://postgr.es/m/CAFfgvXWLOE2novHzYjmQK8-J6TmHz42G8f3X0SORM44+stUGmw@mail.gmail.com
1 parent81f2e51 commit18f8f78

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3801,8 +3801,9 @@ $endif
38013801
If the query results do not fit on the screen, they are piped
38023802
through this command. Typical values are
38033803
<literal>more</literal> or <literal>less</literal>. The default
3804-
is platform-dependent. The use of the pager can be disabled by
3805-
using the <command>\pset</command> command.
3804+
is platform-dependent. Use of the pager can be disabled by setting
3805+
<envar>PAGER</envar> to empty, or by using pager-related options of
3806+
the <command>\pset</command> command.
38063807
</para>
38073808
</listitem>
38083809
</varlistentry>

‎src/fe_utils/print.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2874,6 +2874,12 @@ PageOutput(int lines, const printTableOpt *topt)
28742874
pagerprog=getenv("PAGER");
28752875
if (!pagerprog)
28762876
pagerprog=DEFAULT_PAGER;
2877+
else
2878+
{
2879+
/* if PAGER is empty or all-white-space, don't use pager */
2880+
if (strspn(pagerprog," \t\r\n")==strlen(pagerprog))
2881+
returnstdout;
2882+
}
28772883
disable_sigpipe_trap();
28782884
pagerpipe=popen(pagerprog,"w");
28792885
if (pagerpipe)

‎src/interfaces/libpq/fe-print.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ PQprint(FILE *fout, const PGresult *res, const PQprintOpt *po)
166166
screen_size.ws_col=80;
167167
#endif
168168
pagerenv=getenv("PAGER");
169+
/* if PAGER is unset, empty or all-white-space, don't use pager */
169170
if (pagerenv!=NULL&&
170-
pagerenv[0]!='\0'&&
171+
strspn(pagerenv," \t\r\n")!=strlen(pagerenv)&&
171172
!po->html3&&
172173
((po->expanded&&
173174
nTups* (nFields+1) >=screen_size.ws_row)||

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp