Re: fix psql \conninfo & \connect when using hostaddr
Pavel Stehule <pavel.stehule@gmail.com>
From: Pavel Stehule <pavel.stehule@gmail.com>
To: Artur Zakirov <a.zakirov@postgrespro.ru>
Cc: Fabien COELHO <coelho@cri.ensmp.fr>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>,
Robert Haas <robertmhaas@gmail.com>
Date: 2018-11-07T17:11:56Z
Lists: pgsql-hackers
st 7. 11. 2018 v 15:11 odesílatel Arthur Zakirov <a.zakirov@postgrespro.ru>
napsal:
> Hello all,
>
> On 07.11.2018 16:23, Pavel Stehule wrote:
> > pá 26. 10. 2018 v 15:55 odesílatel Fabien COELHO <coelho@cri.ensmp.fr
> > <mailto:coelho@cri.ensmp.fr>> napsal:
> > >
> > > This is a follow-up to another patch I posted about libpq confusing
> > > documentation & psql resulting behavior under host/hostaddr
> settings.
> > >
> > > Although the first mostly documentation patch did not gather much
> > > enthousiasm, I still think both issues deserve a fix.
> >
> > I checked this patch, and it looks well. The documentation is correct,
> > all tests passed. It does what is proposed.
> >
> > I think so some redundant messages can be reduced - see function
> > printConnInfo - attached patch
>
> I have few notes about patches.
>
> > /* If the host is an absolute path, the connection is via socket unless
> overriden by hostaddr */
> > if (is_absolute_path(host))
> > if (hostaddr && *hostaddr)
> > printf(_("You are connected to database \"%s\" as user
> \"%s\" on address \"%s\" at port \"%s\".\n"),
> > db, PQuser(pset.db), hostaddr, PQport(pset.db));
> > else
> > printf(_("You are connected to database \"%s\" as user
> \"%s\" via socket in \"%s\" at port \"%s\".\n"),
> > db, PQuser(pset.db), host, PQport(pset.db));
> > else
> > if (hostaddr && *hostaddr && strcmp(host, hostaddr) != 0)
> > printf(_("You are connected to database \"%s\" as user
> \"%s\" on host \"%s\" (address \"%s\") at port \"%s\".\n"),
> > db, PQuser(pset.db), host, hostaddr,
> PQport(pset.db));
> > else
> > printf(_("You are connected to database \"%s\" as user
> \"%s\" on host \"%s\" at port \"%s\".\n"),
> > db, PQuser(pset.db), host, PQport(pset.db));
>
> I think there is lack of necessary braces here for first if and second
> else branches. This is true for both patches.
>
?
Pavel
>
> > /* set connip */
> > if (conn->connip != NULL)
> > {
> > free(conn->connip);
> > conn->connip = NULL;
> > }
> >
> > {
> > char host_addr[NI_MAXHOST];
> > getHostaddr(conn, host_addr);
> > if (strcmp(host_addr, "???") != 0)
> > conn->connip = strdup(host_addr);
> > }
>
> Maybe it is better to move this code into the PQhostaddr() function?
> Since connip is used only in PQhostaddr() it might be not worth to do
> additional work in main PQconnectPoll().
>
> --
> Arthur Zakirov
> Postgres Professional: http://www.postgrespro.com
> Russian Postgres Company
>
Commits
-
Tweak libpq's PQhost, PQhostaddr, and psql's \connect
- 313f56ce2d1b 12.0 landed
-
psql: Show IP address in \conninfo
- 6e5f8d489acc 12.0 landed