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

From Pavel Stehule
Subject Re: fix psql \conninfo & \connect when using hostaddr
Date
Msg-id CAFj8pRBecUDqUeLONi29fSyvwHqg29wNWzv-TgQqs6bs6swxHQ@mail.gmail.com
Whole thread Raw
In response to Re: fix psql \conninfo & \connect when using hostaddr  (Arthur Zakirov <a.zakirov@postgrespro.ru>)
Responses Re: fix psql \conninfo & \connect when using hostaddr
List 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

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: valgrind on initdb
Next
From: Tom Lane
Date:
Subject: Re: Calculate total_table_pages after set_base_rel_sizes()