getenv used in libpq caused missing values under Windows

From: Pavel Golub <pavel(at)microolap(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: getenv used in libpq caused missing values under Windows
Date: 2014-01-10 15:17:11
Message-ID: 1811682879.20140110171711@gf.microolap.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello, Pgsql-hackers.

As you probably know dealing with Windows MSVCRT is some kind of hell.
That's why we have src/port/win32env.c particulalry, because there may
be several CRT's loaded at the same time.

libpq unfortunately is using standard "getenv" function call to
fill connection parameters inside "conninfo_add_defaults()", see
http://www.postgresql.org/docs/9.3/interactive/libpq-envars.html

This happens because MSVCRT has it's own local copy of environment
variables table, and this table is not updated during execution. So if
one used "SetEnvironmentVariable()" Windows API to set any variable,
e.g. PGHOST, then this change will not be visible inside libpq's
"conninfo_add_defaults()" function where all default values are
obtained.

This situation especially unpleasant for non-C developers, since there
is no opportunity to use standard "putenv" function or ported
"pgwin32_putenv".

My proposal is to implement "pgwin32_getenv" function which will call
GetEnvironmentVariable first and if it's NULL then call MSVCRT's
"getenv" in the same way as "pgwin32_putenv" does.

So now the bad scenario is:

1. SetEnvironmentVariable('PGHOST=192.188.9.9')
2. PQconnectdbParams without specifying host parameter will fail

--
With best wishes,
Pavel mailto:pavel(at)gf(dot)microolap(dot)com

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2014-01-10 15:36:08 Re: Add CREATE support to event triggers
Previous Message Heikki Linnakangas 2014-01-10 15:12:31 Re: INSERT...ON DUPLICATE KEY LOCK FOR UPDATE