Skip to content

Commit ef3f7c3

Browse files
committed
Avoid trying to open /dev/tty on Win32. Some Win32 systems have
/dev/tty, but it isn't a device file and doesn't work as expected. This fixes a known bug where psql does not prompt for a password on some Win32 systems. Backpatch to 8.1.X. Robert Kinberg
1 parent decdaf3 commit ef3f7c3

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/bin/psql/command.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.161 2006/02/12 04:04:32 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.162 2006/03/03 23:49:12 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "command.h"
@@ -753,8 +753,11 @@ exec_command(const char *cmd,
753753

754754
expand_tilde(&fname);
755755
/* This scrolls off the screen when using /dev/tty */
756+
#ifndef WIN32
756757
success = saveHistory(fname ? fname : "/dev/tty");
757-
758+
#else
759+
success = saveHistory(fname ? fname : stderr);
760+
#endif
758761
if (success && !quiet && fname)
759762
printf(gettext("Wrote history to file \"%s/%s\".\n"),
760763
pset.dirname ? pset.dirname : ".", fname);

src/port/sprompt.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/port/sprompt.c,v 1.12 2005/10/15 02:49:51 momjian Exp $
11+
* $PostgreSQL: pgsql/src/port/sprompt.c,v 1.13 2006/03/03 23:49:12 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -40,8 +40,8 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
4040
{
4141
int length;
4242
char *destination;
43-
FILE *termin,
44-
*termout;
43+
FILE *termin = NULL,
44+
*termout = NULL;
4545

4646
#ifdef HAVE_TERMIOS_H
4747
struct termios t_orig,
@@ -63,8 +63,14 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
6363
* Do not try to collapse these into one "w+" mode file. Doesn't work on
6464
* some platforms (eg, HPUX 10.20).
6565
*/
66+
#ifndef WIN32
67+
/*
68+
* Some win32 platforms actually have a /dev/tty file, but it isn't
69+
* a device file, and it doesn't work as expected, so we avoid trying.
70+
*/
6671
termin = fopen("/dev/tty", "r");
6772
termout = fopen("/dev/tty", "w");
73+
#endif
6874
if (!termin || !termout)
6975
{
7076
if (termin)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy