Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit84e8e5b

Browse files
committed
Make prompt customization work with changeable Unix socket location.
1 parent36161b3 commit84e8e5b

File tree

2 files changed

+31
-62
lines changed

2 files changed

+31
-62
lines changed

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.47 2001/03/24 23:03:26 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.48 2001/05/06 17:21:11 petere Exp $
33
Postgres documentation
44
-->
55

@@ -1970,14 +1970,27 @@ testdb=> <userinput>\set content `sed -e "s/'/\\\\\\'/g" < my_file.txt`</userinp
19701970
<variablelist>
19711971
<varlistentry>
19721972
<term><literal>%M</literal></term>
1973-
<listitem><para>The full hostname (with domain name) of the database server (or
1974-
<quote>localhost</quote> if hostname information is not available).</para></listitem>
1973+
<listitem>
1974+
<para>
1975+
The full hostname (with domain name) of the database server,
1976+
or <literal>[local]</literal> if the connection is over a
1977+
Unix domain socket, or
1978+
<literal>[local:<replaceable>/dir/name</replaceable>]</literal>,
1979+
if the Unix domain socket is not at the compiled in default
1980+
location.
1981+
</para>
1982+
</listitem>
19751983
</varlistentry>
19761984

19771985
<varlistentry>
19781986
<term><literal>%m</literal></term>
1979-
<listitem><para>The hostname of the database server, truncated after the
1980-
first dot.</para></listitem>
1987+
<listitem>
1988+
<para>
1989+
The hostname of the database server, truncated after the
1990+
first dot, or <literal>[local]</literal> if the connection
1991+
is over a Unix domain socket.
1992+
</para>
1993+
</listitem>
19811994
</varlistentry>
19821995

19831996
<varlistentry>

‎src/bin/psql/prompt.c

Lines changed: 13 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
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 $
77
*/
88
#include"postgres_fe.h"
99
#include"prompt.h"
@@ -32,9 +32,9 @@
3232
* (might not be completely multibyte safe)
3333
*
3434
* 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]"
3838
* %> - database server port number
3939
* %n - database user name
4040
* %/ - current database
@@ -61,52 +61,6 @@
6161
*--------------------------
6262
*/
6363

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-
11064
char*
11165
get_prompt(promptStatus_tstatus)
11266
{
@@ -166,23 +120,25 @@ get_prompt(promptStatus_t status)
166120
case'm':
167121
if (pset.db)
168122
{
123+
constchar*host=PQhost(pset.db);
124+
169125
/* INET socket */
170-
if (PQhost(pset.db))
126+
if (host&&host[0]&&host[0]!='/')
171127
{
172-
strncpy(buf,PQhost(pset.db),MAX_PROMPT_SIZE);
128+
strncpy(buf,host,MAX_PROMPT_SIZE);
173129
if (*p=='m')
174130
buf[strcspn(buf,".")]='\0';
175131
}
176132
/* UNIX socket */
177-
#ifdefHAVE_UNIX_SOCKETS
178133
else
179134
{
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);
182139
else
183-
localhost(DOMAINNAME,buf,MAX_PROMPT_SIZE);
140+
snprintf(buf,MAX_PROMPT_SIZE,"[local:%s]",host);
184141
}
185-
#endif/* HAVE_UNIX_SOCKETS */
186142
}
187143
break;
188144
/* DB server port number */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp