Re: fix psql \conninfo & \connect when using hostaddr - Mailing list pgsql-hackers

From Arthur Zakirov
Subject Re: fix psql \conninfo & \connect when using hostaddr
Date
Msg-id 4414f348-4482-2bcb-dc93-9c3d073f2431@postgrespro.ru
Whole thread Raw
In response to Re: fix psql \conninfo & \connect when using hostaddr  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: fix psql \conninfo & \connect when using hostaddr
List pgsql-hackers
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.

> /* 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


pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: valgrind on initdb
Next
From: Tom Lane
Date:
Subject: Re: plruby: rb_iterate symbol clash with libruby.so