Skip to content

Commit 8e4a50c

Browse files
committed
Do not clear out default env. variables on command exec.
1 parent bf45a0f commit 8e4a50c

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

docs/content/payloads/commands.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ note that these commands must be pre-configured in the [Configuration file]({{<r
130130
}
131131
{{< /highlight >}}
132132

133+
**Note:** the given environment variables will be extended to the environment
134+
variables that are already exposed to the "main" process.
135+
133136
### Protobuf
134137

135138
This message is defined by the `GatewayCommandExecRequest` Protobuf message.

internal/commands/commands.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"io/ioutil"
7+
"os"
78
"os/exec"
89
"sync"
910
"time"
@@ -112,6 +113,11 @@ func execute(command string, stdin []byte, environment map[string]string) ([]byt
112113
defer cancel()
113114

114115
cmdCtx := exec.CommandContext(ctx, cmdArgs[0], cmdArgs[1:]...)
116+
117+
// The default is that when cmdCtx.Env is nil, os.Environ() are being used
118+
// automatically. As we want to add additional env. variables, we want to
119+
// extend this list, thus first need to set them to os.Environ()
120+
cmdCtx.Env = os.Environ()
115121
for k, v := range environment {
116122
cmdCtx.Env = append(cmdCtx.Env, fmt.Sprintf("%s=%s", k, v))
117123
}

0 commit comments

Comments
 (0)