diff -r -B -C 2 pgsql.ORIG/doc/src/sgml/ref/psql-ref.sgml pgsql.NEW/doc/src/sgml/ref/psql-ref.sgml
*** pgsql.ORIG/doc/src/sgml/ref/psql-ref.sgml Wed Mar 1 22:09:56 2000
--- pgsql.NEW/doc/src/sgml/ref/psql-ref.sgml Fri Mar 10 15:55:12 2000
***************
*** 1967,1972 ****
%M
! The hostname of the database server (or .
! if Unix domain socket).
--- 1967,1972 ----
%M
! The full hostname (with domainname) of the database server (or
! localhost
if hostname information is not available).
diff -r -B -C 2 pgsql.ORIG/src/bin/psql/prompt.c pgsql.NEW/src/bin/psql/prompt.c
*** pgsql.ORIG/src/bin/psql/prompt.c Fri Mar 10 15:44:43 2000
--- pgsql.NEW/src/bin/psql/prompt.c Fri Mar 10 15:40:02 2000
***************
*** 4,9 ****
* Copyright 2000 by PostgreSQL Global Development Group
*
! * $Header: /usr/local/cvsroot/pgsql/src/bin/psql/prompt.c,v 1.10 2000/03/08 01:38:59 momjian Exp $
! */
#include "postgres.h"
#include "prompt.h"
--- 4,9 ----
* Copyright 2000 by PostgreSQL Global Development Group
*
! * $Header: /usr/local/cvsroot/pgsql/src/bin/psql/prompt.c,v 1.9 2000/02/16 13:15:26 momjian Exp $
! */
#include "postgres.h"
#include "prompt.h"
***************
*** 20,24 ****
#endif
! #include
/*--------------------------
--- 20,27 ----
#endif
! #if !defined(__CYGWIN32__) && !defined(__QNX__)
! #include
! #include
! #endif
/*--------------------------
***************
*** 30,35 ****
*
* Defined interpolations are:
! * %M - database server hostname (or "." if not TCP/IP)
! * %m - like %M but hostname truncated after first dot
* %> - database server port number (or "." if not TCP/IP)
* %n - database user name
--- 33,39 ----
*
* Defined interpolations are:
! * %M - database server "hostname.domainname" (or "localhost" if this
! * information is not available)
! * %m - like %M, but hostname only (before firts dot)
* %> - database server port number (or "." if not TCP/IP)
* %n - database user name
***************
*** 57,60 ****
--- 61,106 ----
*--------------------------
*/
+
+ /*
+ * We need hostname information, only if connection is via UNIX socket
+ */
+ #if !defined(__CYGWIN32__) && !defined(__QNX__)
+
+ #define DOMAINNAME 1
+ #define HOSTNAME 2
+
+ /*
+ * Return full hostname for localhost.
+ * - informations are init only in firts time - not queries DNS or NIS
+ * for every localhost() call
+ */
+ static char *
+ localhost(int type, char *buf, int siz)
+ {
+ static struct hostent *hp = NULL;
+ static int err = 0;
+
+ if (hp==NULL && err==0) {
+ char hname[256];
+
+ if (gethostname(hname, 256) == 0)
+ if (!(hp = gethostbyname(hname)))
+ err = 1;
+ else
+ err = 1;
+ }
+
+ if (hp==NULL)
+ return strncpy(buf, "localhost", siz);
+
+ strncpy(buf, hp->h_name, siz); /* full aaa.bbb.ccc */
+
+ if (type==HOSTNAME)
+ buf[strcspn(buf, ".")] = '\0';
+
+ return buf;
+ }
+ #endif
+
char *
get_prompt(promptStatus_t status)
***************
*** 116,119 ****
--- 162,166 ----
if (pset.db)
{
+ /* INET socket */
if (PQhost(pset.db))
{
***************
*** 122,136 ****
buf[strcspn(buf, ".")] = '\0';
}
! else if (*p == 'M')
! buf[0] = '.';
! else
! {
! struct utsname ubuf;
!
! if (uname(&ubuf) < 0)
! buf[0] = '.';
! else
! strncpy(buf, ubuf.nodename, MAX_PROMPT_SIZE);
! }
}
break;
--- 169,181 ----
buf[strcspn(buf, ".")] = '\0';
}
! /* UNIX socket */
! #if !defined(__CYGWIN32__) && !defined(__QNX__)
! else {
! if (*p == 'm')
! localhost(HOSTNAME, buf, MAX_PROMPT_SIZE);
! else
! localhost(DOMAINNAME, buf, MAX_PROMPT_SIZE);
! }
! #endif
}
break;