Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
1d752981
Commit
1d752981
authored
25 years ago
by
Peter Eisentraut
Browse files
Options
Downloads
Patches
Plain Diff
Karel Zakr's revised patch to fix psql prompt for local host connections.
parent
73f5b084
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
doc/src/sgml/ref/psql-ref.sgml
+3
-3
3 additions, 3 deletions
doc/src/sgml/ref/psql-ref.sgml
src/bin/psql/prompt.c
+65
-17
65 additions, 17 deletions
src/bin/psql/prompt.c
with
68 additions
and
20 deletions
doc/src/sgml/ref/psql-ref.sgml
+
3
−
3
View file @
1d752981
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.2
7
2000/03/
0
1
21:09:56
petere Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.2
8
2000/03/
1
1
13:56:23
petere Exp $
Postgres documentation
-->
...
...
@@ -1966,8 +1966,8 @@ testdb=> <userinput>\set content `sed -e "s/'/\\\\\\'/g" < my_file.txt`</userinp
<variablelist>
<varlistentry>
<term><literal>%M</literal></term>
<listitem><para>The hostname of the database server (or
<quote>.</quote>
if Unix domain socket
).</para></listitem>
<listitem><para>The
full
hostname
(with domainname)
of the database server (or
<quote>localhost</quote> if hostname information is not available
).</para></listitem>
</varlistentry>
<varlistentry>
...
...
This diff is collapsed.
Click to expand it.
src/bin/psql/prompt.c
+
65
−
17
View file @
1d752981
...
...
@@ -3,8 +3,8 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.1
0
2000/03/
08 01:38:59 momjian
Exp $
*/
* $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.1
1
2000/03/
11 13:56:24 petere
Exp $
*/
#include
"postgres.h"
#include
"prompt.h"
...
...
@@ -19,7 +19,10 @@
#include
<win32.h>
#endif
#include
<sys/utsname.h>
#if !defined(WIN32) && !defined(__CYGWIN32__) && !defined(__QNX__)
#include
<unistd.h>
#include
<netdb.h>
#endif
/*--------------------------
* get_prompt
...
...
@@ -29,9 +32,10 @@
* (might not be completely multibyte safe)
*
* 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)
* %M - database server "hostname.domainname" (or "localhost" if this
* information is not available)
* %m - like %M, but hostname only (before first dot)
* %> - database server port number
* %n - database user name
* %/ - current database
* %~ - like %/ but "~" when database name equals user name
...
...
@@ -56,6 +60,51 @@
* will be empty (not NULL!).
*--------------------------
*/
/*
* We need hostname information, only if connection is via UNIX socket
*/
#if !defined(WIN32) && !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
)
{
...
...
@@ -115,23 +164,22 @@ get_prompt(promptStatus_t status)
case
'm'
:
if
(
pset
.
db
)
{
/* INET socket */
if
(
PQhost
(
pset
.
db
))
{
strncpy
(
buf
,
PQhost
(
pset
.
db
),
MAX_PROMPT_SIZE
);
if
(
*
p
==
'm'
)
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
);
}
/* UNIX socket */
#if !defined(WIN32) && !defined(__CYGWIN32__) && !defined(__QNX__)
else
{
if
(
*
p
==
'm'
)
localhost
(
HOSTNAME
,
buf
,
MAX_PROMPT_SIZE
);
else
localhost
(
DOMAINNAME
,
buf
,
MAX_PROMPT_SIZE
);
}
#endif
}
break
;
/* DB server port number */
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment