Permalink
Browse files

Manually pass the env to docker-init instead of relying on lxc to pas…

…s it
  • Loading branch information...
1 parent fc72a80 commit 7b0e96f1f4639f869703ed32f885cec9b666b127 @creack creack committed Apr 16, 2013
Showing with 19 additions and 16 deletions.
  1. +14 −13 container.go
  2. +5 −3 sysinit.go
View
27 container.go
@@ -390,21 +390,26 @@ func (container *Container) Start() error {
params = append(params, "-u", container.Config.User)
}
+ if container.Config.Tty {
+ params = append(params, "-e", "TERM=xterm")
+ }
+
+ // Setup environment
+ params = append(params,
+ "-e", "HOME=/",
+ "-e", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
+ )
+
+ for _, elem := range container.Config.Env {
+ params = append(params, "-e", elem)
+ }
+
// Program
params = append(params, "--", container.Path)
params = append(params, container.Args...)
container.cmd = exec.Command("lxc-start", params...)
- // Setup environment
- container.cmd.Env = append(
- []string{
- "HOME=/",
- "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
- },
- container.Config.Env...,
- )
-
// Setup logging of stdout and stderr to disk
if err := container.runtime.LogToDisk(container.stdout, container.logPath("stdout")); err != nil {
return err
@@ -415,10 +420,6 @@ func (container *Container) Start() error {
var err error
if container.Config.Tty {
- container.cmd.Env = append(
- []string{"TERM=xterm"},
- container.cmd.Env...,
- )
err = container.startPty()
} else {
err = container.start()
View
8 sysinit.go
@@ -53,8 +53,7 @@ func changeUser(u string) {
}
// Clear environment pollution introduced by lxc-start
-func cleanupEnv() {
- env := os.Environ()
+func cleanupEnv(env ListOpts) {
os.Clearenv()
for _, kv := range env {
parts := strings.SplitN(kv, "=", 2)
@@ -91,10 +90,13 @@ func SysInit() {
var u = flag.String("u", "", "username or uid")
var gw = flag.String("g", "", "gateway address")
+ var flEnv ListOpts
+ flag.Var(&flEnv, "e", "Set environment variables")
+
flag.Parse()
+ cleanupEnv(flEnv)
setupNetworking(*gw)
- cleanupEnv()
changeUser(*u)
executeProgram(flag.Arg(0), flag.Args())
}

0 comments on commit 7b0e96f

Please sign in to comment.