Clean up 'container' environment variable injected by lxc-start

This commit is contained in:
Solomon Hykes 2013-03-23 19:11:00 -07:00
parent 57e2126a02
commit f7eaaa3adb

View file

@ -8,6 +8,7 @@ import (
"os/exec"
"os/user"
"strconv"
"strings"
"syscall"
)
@ -52,6 +53,22 @@ func changeUser(u string) {
}
}
// Clear environment pollution introduced by lxc-start
func cleanupEnv() {
env := os.Environ()
os.Clearenv()
for _, kv := range env {
parts := strings.SplitN(kv, "=", 2)
if len(parts) == 1 {
parts = append(parts, "")
}
if parts[0] == "container" {
continue
}
os.Setenv(parts[0], parts[1])
}
}
func executeProgram(name string, args []string) {
path, err := exec.LookPath(name)
if err != nil {
@ -78,6 +95,7 @@ func SysInit() {
flag.Parse()
setupNetworking(*gw)
cleanupEnv()
changeUser(*u)
executeProgram(flag.Arg(0), flag.Args())
}