Re: fix psql \conninfo & \connect when using hostaddr

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Re: fix psql \conninfo & \connect when using hostaddr
Date: 2018-11-07 17:11:56
Message-ID: CAFj8pRBecUDqUeLONi29fSyvwHqg29wNWzv-TgQqs6bs6swxHQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

st 7. 11. 2018 v 15:11 odesílatel Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)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(at)cri(dot)ensmp(dot)fr
> > <mailto:coelho(at)cri(dot)ensmp(dot)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
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2018-11-07 17:17:57 Re: Calculate total_table_pages after set_base_rel_sizes()
Previous Message Andres Freund 2018-11-07 17:09:09 Re: valgrind on initdb