diff --git a/agent/proxy/manager.go b/agent/proxy/manager.go index e3c6dd7796..e22079b186 100644 --- a/agent/proxy/manager.go +++ b/agent/proxy/manager.go @@ -432,7 +432,7 @@ func (m *Manager) newProxy(mp *local.ManagedProxy) (Proxy, error) { if err := m.configureLogDir(id, &cmd); err != nil { return nil, fmt.Errorf("error configuring proxy logs: %s", err) } - + cmd.Env = os.Environ() // Build the daemon structure proxy.Command = &cmd proxy.ProxyID = id diff --git a/agent/proxy/manager_test.go b/agent/proxy/manager_test.go index 42286493c7..b3269bf10c 100644 --- a/agent/proxy/manager_test.go +++ b/agent/proxy/manager_test.go @@ -261,6 +261,46 @@ func TestManagerRun_daemonPid(t *testing.T) { require.NotEmpty(pidRaw) } +// Test to check if the parent and the child processes +// have the same environmental variables + +func TestEnvironproxy(t *testing.T) { + t.Parallel() + + require := require.New(t) + state := local.TestState(t) + m, closer := testManager(t) + defer closer() + m.State = state + defer m.Kill() + + // Add the proxy + td, closer := testTempDir(t) + defer closer() + path := filepath.Join(td, "env-variables") + d := &Daemon{ + Command: helperProcess("parent", path), + Logger: testLogger, + } + var currentEnviron []string + currentEnviron = os.Environ() + // Environmental variable of the helper + if err := d.Start(); err != nil { + t.Error("Daemon failed to start") + defer d.Stop() + envProcess := d.Command.Env + var envData []byte + for _, data := range envProcess { + envData = append(envData, []byte(data)...) + envData = append(envData, []byte("\n")...) + } + t.Logf("Env Data:%s", envProcess) + //Get the parent environmental variables in a file + + require.Equal(currentEnviron, envProcess) + } +} + // Test the Snapshot/Restore works. func TestManagerRun_snapshotRestore(t *testing.T) { t.Parallel()