From 65ccc309a0225863913d991f56f17e2aa4f85266 Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Mon, 7 Jun 2010 16:42:40 +0200 Subject: 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. --- erts/emulator/sys/unix/sys.c | 10 +++++++++- 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. -- cgit v1.2.3