BUG #2459: psql 8.1.4 vs 8.0.x behaves differently with tty / con / stdin recent fixes - Mailing list pgsql-bugs

From Silvio Macedo
Subject BUG #2459: psql 8.1.4 vs 8.0.x behaves differently with tty / con / stdin recent fixes
Date
Msg-id 200605291653.k4TGrxKm081029@wwwmaster.postgresql.org
Whole thread Raw
Responses Re: BUG #2459: psql 8.1.4 vs 8.0.x behaves differently with tty / con / stdin recent fixes  (Alvaro Herrera <alvherre@commandprompt.com>)
Re: BUG #2459: psql 8.1.4 vs 8.0.x behaves differently with tty / con / stdin recent fixes  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: BUG #2459: psql 8.1.4 vs 8.0.x behaves differently with  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-bugs
The following bug has been logged online:

Bug reference:      2459
Logged by:          Silvio Macedo
Email address:      smacedo@calmetric.pt
PostgreSQL version: 8.1.4
Operating system:   Windows XP SP2
Description:        psql 8.1.4 vs 8.0.x behaves differently with  tty / con
/ stdin recent fixes
Details:

Hi,

I've been using stdin/stdout of psql on Windows to run a script, without
messing with "expect".

Before v8.1.4, one could include the password in the string fed to psql via
stdin to authenticate the connection.

With 8.1.4, it doesn't work.

All of this *seems* to be related to patch introduced by Bruce:
http://archives.postgresql.org/pgsql-patches/2006-03/msg00051.php
to avoid relying  on /dev/con on Msys.

Is this a BUG or a design decision? If it's by design, people should be
warned about this different behaviour (getting a password on the stdin
doesn't work in 8.1.4)
If it's a bug, correction should be on file
\src\port\sprompt.c:69
This, together with what is in file port.h, seems to be wrong :
#ifdef WIN32
        /* See DEVTTY comment for msys */
        || (getenv("OSTYPE") && strcmp(getenv("OSTYPE"), "msys") == 0)
#endif


Below, reference material with relevant excerpts of different versions of
\src\include\port.h and \src\port\sprompt.c

Thanks for any tip or feedback!
Silvio
calmetric.pt

\postgresql-8.0.7\src\include\port.h:81 to 85

#if defined(WIN32) && !defined(__CYGWIN__)
#define DEVNULL "nul"


#else
#define DEVNULL "/dev/null"

#endif



\postgresql-8.1.4\src\include\port.h:85 to 92

#if defined(WIN32) && !defined(__CYGWIN__)
#define DEVNULL "nul"
/* "con" does not work from the Msys 1.0.10 console (part of MinGW). */
#define DEVTTY    "con"
#else
#define DEVNULL "/dev/null"
#define DEVTTY "/dev/tty"
#endif






\postgresql-8.0.7\src\port\sprompt.c:64 to 78

     * Do not try to collapse these into one "w+" mode file. Doesn't work
     * on some platforms (eg, HPUX 10.20).
     */
    termin = fopen("/dev/tty", "r");
    termout = fopen("/dev/tty", "w");
    if (!termin || !termout)





    {
        if (termin)
            fclose(termin);
        if (termout)
            fclose(termout);
        termin = stdin;
        termout = stderr;
    }




\postgresql-8.1.4\src\port\sprompt.c:63 to 82
     * Do not try to collapse these into one "w+" mode file. Doesn't work on
     * some platforms (eg, HPUX 10.20).
     */
    termin = fopen(DEVTTY, "r");
    termout = fopen(DEVTTY, "w");
    if (!termin || !termout
#ifdef WIN32
        /* See DEVTTY comment for msys */
        || (getenv("OSTYPE") && strcmp(getenv("OSTYPE"), "msys") == 0)
#endif
        )
    {
        if (termin)
            fclose(termin);
        if (termout)
            fclose(termout);
        termin = stdin;
        termout = stderr;
    }

pgsql-bugs by date:

Previous
From: imacat
Date:
Subject: Re: BUG #2424: initdb Did Not Escape the Password
Next
From: Alvaro Herrera
Date:
Subject: Re: BUG #2459: psql 8.1.4 vs 8.0.x behaves differently with tty / con / stdin recent fixes