Fix for "q" with psql display paging dumps out of psql - Mailing list pgadmin-hackers

From jseymour@linxnet.com (Jim Seymour)
Subject Fix for "q" with psql display paging dumps out of psql
Date
Msg-id 20041121135127.C223E430E@jimsun.linxnet.com
Whole thread Raw
List pgadmin-hackers
Hi,

Environment:

    SunOS 5.7 Generic_106541-29 sun4u sparc SUNW,UltraSPARC-IIi-Engine
    Postgresql-7.4.6
        Build config: --with-java --enable-thread-safety
    gcc version 3.3.1
    less-381
    readline-4.3

    $ echo $PAGER
    /usr/local/bin/less
    $ echo $LESS
    -e

I recently upgraded from 7.4.2 to 7.4.6 and ran into an annoying
problem.  Thereafter, most times, "q"uitting out of paged display
output would dump me straight out of psql if the query result was
sufficiently large.

A bit of debugging revealed psql receiving a SIGPIPE to be the
problem.

Building pgsql w/o --enable-thread-safety eliminated the problem.

It looks like the culprit is asynchronous SIGPIPE signals under Solaris
7 when using thread-safe libraries.  Here's a reference:
<http://www.lambdacs.com/cpt/FAQ.html#Q339>.

I do not know if Solaris 8 and beyond behave this way.  (Apparently
async SIGPIPE is not POSIX-compliant, so one hopes Sun has fixed this
broken behaviour.)

Here's a fix that's simple, effective and doesn't hurt anything else:

------------------------- begin included text --------------------------
*** src/bin/psql/print.c-orig   Wed Nov 17 08:04:47 2004
--- src/bin/psql/print.c        Sat Nov 20 10:43:22 2004
***************
*** 1119,1124 ****
--- 1119,1128 ----
        {
                pclose(output);
  #ifndef WIN32
+               /* The SIG_IGN is to compensate for broken Solaris 7
+                * (async) SIGPIPE handling with --enable-thread-safety
+                */
+               pqsignal(SIGPIPE, SIG_IGN);
                pqsignal(SIGPIPE, SIG_DFL);
  #endif
        }
-------------------------- end included text ---------------------------

Thanks to Andrew, over at SuperNews, for the idea.

Regards,
Jim

pgadmin-hackers by date:

Previous
From: "Dave Page"
Date:
Subject: Re: RC2 announcement
Next
From: Raphaël Enrici
Date:
Subject: Re: RC2 announcement