diff options
author | Sverker Eriksson <[email protected]> | 2010-06-07 16:42:40 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2010-06-10 10:44:52 +0200 |
commit | 65ccc309a0225863913d991f56f17e2aa4f85266 (patch) | |
tree | 854ef04106740e83f0c20f1ea9ae3e30ef0a5648 /erts/emulator | |
parent | 6925a0da3cf0fd299e5e468fd95c4d0a697b86ae (diff) | |
download | otp-65ccc309a0225863913d991f56f17e2aa4f85266.tar.gz otp-65ccc309a0225863913d991f56f17e2aa4f85266.tar.bz2 otp-65ccc309a0225863913d991f56f17e2aa4f85266.zip |
fix open_port with many unset env vars
The erlang:open_port spawn and spawn_executable directives can include
an {env, Env} directive to set up environment variables for the
spawned process. Variables can be unset with {"NameOfVariable",false}.
A bug in ert/emulator/sys/unix/sys.c could cause unset variables
to not be unset. This would typically happen if there where more
variables to be unset than there where already set variables in the
destination evironment.
Fix this problem for unix and add a new regression test for it to
the port test suite. Windows does not seem to have the same problem.
Diffstat (limited to 'erts/emulator')
-rw-r--r-- | erts/emulator/sys/unix/sys.c | 10 | ||||
-rw-r--r-- | erts/emulator/test/port_SUITE.erl | 11 |
2 files changed, 18 insertions, 3 deletions
diff --git a/erts/emulator/sys/unix/sys.c b/erts/emulator/sys/unix/sys.c index 151fa06e8e..737ffd9f94 100644 --- a/erts/emulator/sys/unix/sys.c +++ b/erts/emulator/sys/unix/sys.c @@ -1328,10 +1328,18 @@ static char **build_unix_environment(char *block) } } - for (j = 0; j < i; j++) { + for (j = 0; j < i; ) { size_t last = strlen(cpp[j])-1; if (cpp[j][last] == '=' && strchr(cpp[j], '=') == cpp[j]+last) { cpp[j] = cpp[--len]; + if (len < i) { + i--; + } else { + j++; + } + } + else { + j++; } } diff --git a/erts/emulator/test/port_SUITE.erl b/erts/emulator/test/port_SUITE.erl index 66aff307a3..77fa75b78f 100644 --- a/erts/emulator/test/port_SUITE.erl +++ b/erts/emulator/test/port_SUITE.erl @@ -878,13 +878,20 @@ env2(Config) -> "nisse" = os:getenv(Long) end), - + ?line env_slave(Temp, [{"must_define_something","some_value"}, - {"certainly_not_existing",false}, + {"certainly_not_existing",false}, {"ends_with_equal", "value="}, {Long,false}, {"glurf","a glorfy string"}]), + %% A lot of non existing variables (mingled with existing) + NotExistingList = [{lists:flatten(io_lib:format("V~p_not_existing",[X])),false} + || X <- lists:seq(1,150)], + ExistingList = [{lists:flatten(io_lib:format("V~p_existing",[X])),"a_value"} + || X <- lists:seq(1,150)], + ?line env_slave(Temp, lists:sort(ExistingList ++ NotExistingList)), + ?line test_server:timetrap_cancel(Dog), ok. |