|
3 | 3 | *
|
4 | 4 | * Copyright 2000 by PostgreSQL Global Development Group
|
5 | 5 | *
|
6 |
| - * $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.18 2001/03/22 04:00:22 momjian Exp $ |
| 6 | + * $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.19 2001/05/06 17:21:11 petere Exp $ |
7 | 7 | */
|
8 | 8 | #include"postgres_fe.h"
|
9 | 9 | #include"prompt.h"
|
|
32 | 32 | * (might not be completely multibyte safe)
|
33 | 33 | *
|
34 | 34 | * Defined interpolations are:
|
35 |
| - * %M - database server "hostname.domainname" (or "localhost" if this |
36 |
| - *information isnotavailable) |
37 |
| - * %m - like %M, but hostname only (before first dot) |
| 35 | + * %M - database server "hostname.domainname", "[local]" for AF_UNIX |
| 36 | + * sockets, "[local:/dir/name]" ifnotdefault |
| 37 | + * %m - like %M, but hostname only (before first dot), or always "[local]" |
38 | 38 | * %> - database server port number
|
39 | 39 | * %n - database user name
|
40 | 40 | * %/ - current database
|
|
61 | 61 | *--------------------------
|
62 | 62 | */
|
63 | 63 |
|
64 |
| -/* |
65 |
| - * We need hostname information, only if connection is via UNIX socket |
66 |
| - */ |
67 |
| -#ifdefHAVE_UNIX_SOCKETS |
68 |
| - |
69 |
| -#defineDOMAINNAME1 |
70 |
| -#defineHOSTNAME2 |
71 |
| - |
72 |
| -/* |
73 |
| - * Return full hostname for localhost. |
74 |
| - *- informations are init only in firts time - not queries DNS or NIS |
75 |
| - * for every localhost() call |
76 |
| - */ |
77 |
| -staticchar* |
78 |
| -localhost(inttype,char*buf,intsiz) |
79 |
| -{ |
80 |
| -staticstructhostent*hp=NULL; |
81 |
| -staticinterr=0; |
82 |
| - |
83 |
| -if (hp==NULL&&err==0) |
84 |
| -{ |
85 |
| -charhname[256]; |
86 |
| - |
87 |
| -if (gethostname(hname,256)==0) |
88 |
| -{ |
89 |
| -if (!(hp=gethostbyname(hname))) |
90 |
| -err=1; |
91 |
| -} |
92 |
| -else |
93 |
| -err=1; |
94 |
| -} |
95 |
| - |
96 |
| -if (hp==NULL) |
97 |
| -returnstrncpy(buf,"localhost",siz); |
98 |
| - |
99 |
| -strncpy(buf,hp->h_name,siz);/* full aaa.bbb.ccc */ |
100 |
| - |
101 |
| -if (type==HOSTNAME) |
102 |
| -buf[strcspn(buf,".")]='\0'; |
103 |
| - |
104 |
| -returnbuf; |
105 |
| -} |
106 |
| - |
107 |
| -#endif/* HAVE_UNIX_SOCKETS */ |
108 |
| - |
109 |
| - |
110 | 64 | char*
|
111 | 65 | get_prompt(promptStatus_tstatus)
|
112 | 66 | {
|
@@ -166,23 +120,25 @@ get_prompt(promptStatus_t status)
|
166 | 120 | case'm':
|
167 | 121 | if (pset.db)
|
168 | 122 | {
|
| 123 | +constchar*host=PQhost(pset.db); |
| 124 | + |
169 | 125 | /* INET socket */
|
170 |
| -if (PQhost(pset.db)) |
| 126 | +if (host&&host[0]&&host[0]!='/') |
171 | 127 | {
|
172 |
| -strncpy(buf,PQhost(pset.db),MAX_PROMPT_SIZE); |
| 128 | +strncpy(buf,host,MAX_PROMPT_SIZE); |
173 | 129 | if (*p=='m')
|
174 | 130 | buf[strcspn(buf,".")]='\0';
|
175 | 131 | }
|
176 | 132 | /* UNIX socket */
|
177 |
| -#ifdefHAVE_UNIX_SOCKETS |
178 | 133 | else
|
179 | 134 | {
|
180 |
| -if (*p=='m') |
181 |
| -localhost(HOSTNAME,buf,MAX_PROMPT_SIZE); |
| 135 | +if (!host |
| 136 | +||strcmp(host,DEFAULT_PGSOCKET_DIR)==0 |
| 137 | +||*p=='m') |
| 138 | +strncpy(buf,"[local]",MAX_PROMPT_SIZE); |
182 | 139 | else
|
183 |
| -localhost(DOMAINNAME,buf,MAX_PROMPT_SIZE); |
| 140 | +snprintf(buf,MAX_PROMPT_SIZE,"[local:%s]",host); |
184 | 141 | }
|
185 |
| -#endif/* HAVE_UNIX_SOCKETS */ |
186 | 142 | }
|
187 | 143 | break;
|
188 | 144 | /* DB server port number */
|
|