getenv used in libpq caused missing values under Windows - Mailing list pgsql-hackers

From Pavel Golub
Subject getenv used in libpq caused missing values under Windows
Date
Msg-id 1811682879.20140110171711@gf.microolap.com
Whole thread Raw
List 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@gf.microolap.com




pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: INSERT...ON DUPLICATE KEY LOCK FOR UPDATE
Next
From: Simon Riggs
Date:
Subject: Re: Add CREATE support to event triggers