Thread: BUG #2459: psql 8.1.4 vs 8.0.x behaves differently with tty / con / stdin recent fixes
BUG #2459: psql 8.1.4 vs 8.0.x behaves differently with tty / con / stdin recent fixes
From
"Silvio Macedo"
Date:
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; }
Re: BUG #2459: psql 8.1.4 vs 8.0.x behaves differently with tty / con / stdin recent fixes
From
Alvaro Herrera
Date:
Silvio Macedo wrote: > 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. You can use PGPASSWORD or a pgpass.conf file instead. -- Alvaro Herrera http://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc.
Re: BUG #2459: psql 8.1.4 vs 8.0.x behaves differently with tty / con / stdin recent fixes
From
Tom Lane
Date:
"Silvio Macedo" <smacedo@calmetric.pt> writes: > 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. That's how it's been on Unix for a long time (/dev/tty is not stdin), so I'd say this is a bug fix not a bug. regards, tom lane
Unix always prompted from /dev/tty, but on Win32 we didn't have that working until 8.1.4. It should be that way. --------------------------------------------------------------------------- Silvio Macedo wrote: > > 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; > } > > ---------------------------(end of broadcast)--------------------------- > TIP 5: don't forget to increase your free space map settings > -- Bruce Momjian http://candle.pha.pa.us EnterpriseDB http://www.enterprisedb.com + If your life is a hard drive, Christ can be your backup. +
Re: BUG #2459: psql 8.1.4 vs 8.0.x behaves differently with tty / con / stdin recent fixes
From
"Silvio Macedo"
Date:
> From: Tom Lane [mailto:tgl@sss.pgh.pa.us]=20 > Sent: 29 May 2006 18:16 > "Silvio Macedo" <smacedo@calmetric.pt> writes: > > I've been using stdin/stdout of psql on Windows to run a=20 > script, without > > messing with "expect". > > Before v8.1.4, one could include the password in the string=20 > fed to psql via > > stdin to authenticate the connection. > > With 8.1.4, it doesn't work. >=20 > That's how it's been on Unix for a long time (/dev/tty is not stdin), > so I'd say this is a bug fix not a bug. >=20 > regards, tom lane Thanks Alvaro, Tom and Bruce for the quick replies. What an honour! Regarding UNIX, I know - I helped a tiny bit the port of PGSql to Linux Sparc64.;) In this case, I think users upgrading from 8.0.x to 8.1. should be warned.(think interfacing with old software, no source available, "upgraded" to PGSql via messy console stub scripts) Users uncomfortable with writing down the password on a PGPASSWORD environment var or pgpass.conf, ___*on the machine running PSQL client*___, seem to have no solution then... I know - something to ask in pgsql-general. Thanks again, Silvio calmetric.pt
Silvio Macedo wrote: > In this case, I think users upgrading from 8.0.x to 8.1. should be > warned.(think interfacing with old software, no source available, > "upgraded" to PGSql via messy console stub scripts) > > Users uncomfortable with writing down the password on a PGPASSWORD > environment var or pgpass.conf, ___*on the machine running PSQL > client*___, seem to have no solution then... I know - something to ask > in pgsql-general. This change is actually new in 8.1.4. It was not in 8.1.3, and the 8.1.4 release notes mention it: * Fix problem with password prompting on some Win32 systems (Robert Kinberg) Not sure what more we could do. Since you are the first person to notice a problem, we probably had it at the right level of prominence. -- Bruce Momjian http://candle.pha.pa.us EnterpriseDB http://www.enterprisedb.com + If your life is a hard drive, Christ can be your backup. +