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

Commit82eb5c5

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 parent6c5d591 commit82eb5c5

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
@@ -3450,8 +3450,9 @@ $endif
34503450
If the query results do not fit on the screen, they are piped
34513451
through this command. Typical values are
34523452
<literal>more</literal> or <literal>less</literal>. The default
3453-
is platform-dependent. The use of the pager can be disabled by
3454-
using the <command>\pset</command> command.
3453+
is platform-dependent. Use of the pager can be disabled by setting
3454+
<envar>PAGER</envar> to empty, or by using pager-related options of
3455+
the <command>\pset</command> command.
34553456
</para>
34563457
</listitem>
34573458
</varlistentry>

‎src/bin/psql/print.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,6 +2205,12 @@ PageOutput(int lines, unsigned short int pager)
22052205
pagerprog=getenv("PAGER");
22062206
if (!pagerprog)
22072207
pagerprog=DEFAULT_PAGER;
2208+
else
2209+
{
2210+
/* if PAGER is empty or all-white-space, don't use pager */
2211+
if (strspn(pagerprog," \t\r\n")==strlen(pagerprog))
2212+
returnstdout;
2213+
}
22082214
#ifndefWIN32
22092215
pqsignal(SIGPIPE,SIG_IGN);
22102216
#endif

‎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