Re: The problems of PQhost()

From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Noah Misch <noah(at)leadboat(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, MauMau <maumau307(at)gmail(dot)com>
Subject: Re: The problems of PQhost()
Date: 2014-11-27 18:11:06
Message-ID: CAHGQGwFyZ50gLVfHTdSQUcjQ46E_UxVmUA8tzSb8PtSh=0jsLA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Nov 27, 2014 at 12:38 PM, Noah Misch <noah(at)leadboat(dot)com> wrote:
> On Tue, Nov 25, 2014 at 09:53:10PM +0900, Fujii Masao wrote:
>> On Tue, Nov 25, 2014 at 12:37 PM, Noah Misch <noah(at)leadboat(dot)com> wrote:
>> > On Wed, Jan 22, 2014 at 11:48:26PM +0900, Fujii Masao wrote:
>> >> (3) PQhost() cannot return the hostaddr.
>> >
>> >> We can fix the problem (3) by changing PQhost() so that it also
>> >> returns the hostaddr. But this change might break the existing
>> >> application using PQhost(). So, I added new libpq function PQhostaddr()
>> >> which returns the hostaddr, and changed \conninfo so that it reports
>> >> correct connection information by using both PQhost() and PQhostaddr().
>> >
>> >> + <varlistentry id="libpq-pqhostaddr">
>> >> + <term>
>> >> + <function>PQhostaddr</function>
>> >> + <indexterm>
>> >> + <primary>PQhostaddr</primary>
>> >> + </indexterm>
>> >> + </term>
>> >> +
>> >> + <listitem>
>> >> + <para>
>> >> + Returns the server numeric IP address or host name of the connection.
>> >> + <synopsis>
>> >> + char *PQhostaddr(const PGconn *conn);
>> >> + </synopsis>
>> >> + </para>
>> >> + </listitem>
>> >> + </varlistentry>
>> >
>> > From reading this documentation, I assumed this function would return a
>> > non-empty value for every TCP connection. After all, every TCP connection has
>> > a peer IP address. In fact, PQhostaddr() returns the raw value of the
>> > "hostaddr" connection parameter, whether from a libpq function argument or
>> > from the PGHOSTADDR environment variable. (If the parameter and environment
>> > variable are absent, it returns NULL. Adding "hostaddr=" to the connection
>> > string makes it return the empty string.) A caller wanting the specific raw
>> > value of a parameter could already use PQconninfo(). I suspect this new
>> > function will confuse more than help. What do you think of reverting it and
>> > having \conninfo use PQconninfo() to discover any "hostaddr" value?
>>
>> Sounds reasonable to me. Are you planning to implement and commit the patch?
>
> Sure. I'll first issue "git revert 9f80f48", then apply the attached patch.
> Since libpq ignores a hostaddr parameter equal to the empty string, this
> implementation does likewise. Apart from that, I anticipate behavior
> identical to today's code.

+ fprintf(stderr, _("out of memory\n"));

psql_error() should be used instead of fprintf()?

+ if (host == NULL) /* can't happen */

Is this comment true? ISTM that "host" can be NULL when the default socket
directory is used, i.e., neither host nor hostaddr are supplied by the user.

Regards,

--
Fujii Masao

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2014-11-27 18:24:11 Re: [BUGS] BUG #12071: Stat collector went crasy (50MB/s constant writes)
Previous Message Fujii Masao 2014-11-27 17:56:08 Re: why is PG_AUTOCONF_FILENAME is pg_config_manual.h?