Skip to content

Commit

Permalink
Clarify that by default we only pass through the TERM variable
Browse files Browse the repository at this point in the history
Also, refactor the environment variable logic to keep the core function
`runCommandSync` as freestanding as possible, in preparation for #10
  • Loading branch information
1player committed Oct 12, 2022
1 parent dd3168e commit ddefc3c
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
var Version string = "HEAD"

// Command line options
var flagNoPty = flag.Bool("no-pty", false, "do not allocate a pseudo-terminal for the host process")
var flagVersion = flag.Bool("version", false, "show this program's version")
var flagEnvironmentVariables = flag.String("env", "", "comma separated list of environment variables to pass to the host process")
var flagNoPty = flag.Bool("no-pty", false, "Do not allocate a pseudo-terminal for the host process")
var flagVersion = flag.Bool("version", false, "Show this program's version")
var flagEnvironmentVariables = flag.String("env", "TERM", "Comma separated list of environment variables to pass to the host process.")

const OUR_BASENAME = "host-spawn"

Expand All @@ -39,7 +39,7 @@ func interpretWaitStatus(status uint32) (int, bool) {
return 0, false
}

func runCommandSync(args []string, allocatePty bool) (int, error) {
func runCommandSync(args []string, allocatePty bool, envsToPassthrough []string) (int, error) {

// Connect to the dbus session to talk with flatpak-session-helper process.
conn, err := dbus.ConnectSessionBus()
Expand Down Expand Up @@ -74,12 +74,9 @@ func runCommandSync(args []string, allocatePty bool) (int, error) {
argv[i] = nullTerminatedByteString(arg)
}

envs := map[string]string{"TERM": os.Getenv("TERM")}
if len(*flagEnvironmentVariables) != 0 {
envVars := strings.Split(*flagEnvironmentVariables, ",")
for _, e := range envVars {
envs = map[string]string{e: os.Getenv(e)}
}
envs := make(map[string]string)
for _, e := range envsToPassthrough {
envs[e] = os.Getenv(e)
}

fds := map[uint32]dbus.UnixFD{
Expand Down Expand Up @@ -170,7 +167,10 @@ func main() {
}

allocatePty := !*flagNoPty
exitCode, err := runCommandSync(command, allocatePty)

envsToPassthrough := strings.Split(*flagEnvironmentVariables, ",")

exitCode, err := runCommandSync(command, allocatePty, envsToPassthrough)
if err != nil {
fmt.Fprintln(os.Stderr, err)
exitCode = 127
Expand Down

0 comments on commit ddefc3c

Please sign in to comment.