4 Commits (6500f75954f9d96d35d4aa2749d36807704c1cb3)

Author SHA1 Message Date
Iain Patterson 620fc9f569 Fixed broken environment on restart.
We were calling duplicate_environment() to copy the service's initial
environment prior to restarting it.  However the duplicate_environment()
function modified its input by replacing = characters with NULLs.  That
is not allowed; the memory returned by GetEnvironmentStrings() must be
treated as readonly.

After two restarts the application would run with a null environment and
probably crash.

We now copy the initial environment on to the heap and operate on the
copy, ensuring that the corruption does not occur.

Thanks Alessandro Gherardi.
11 years ago
Iain Patterson 5380a4a53d Renamed un/format_environment().
The format_environment() and unformat_environment() functions could be
used to format any double null-terminated string list, and are not
specificially tied to formatting environment blocks.
11 years ago
Iain Patterson 2e3a41e1d5 Added more environment functions.
useful_environment() skips the uninteresting variables at the start of
an environment block, returning a pointer to the first useful variable.

expand_environment_string() expands a string with
ExpandEnvironmentStrings() and returns a pointer to the expanded string,
which must be freed after use.

set_environment_block() iterates through all the variables in an
environment block, expands each one with expand_environment_string() and
calls SetEnvironmentVariable() with the expanded value.

clear_environment() removes all variables from the current environment.

duplicate_environment() duplicates an environment block by first calling
clear_environment() then set_environment_block() with the source block.
Thus it ensures that the variables in the block - and only those - are
set in the current environment.
11 years ago
Iain Patterson e3b93d0c37 Moved environment functions to a new file.
Moved format_environment(), unformat_environment() and
test_environment() to env.cpp.
11 years ago