浏览代码

Merge pull request #1 from crosbymichael/nsenter-path

Move environment loading to nsenter
Victor Marmol 11 年之前
父节点
当前提交
a0137e104c
共有 2 个文件被更改,包括 9 次插入9 次删除
  1. 7 8
      pkg/libcontainer/namespaces/execin.go
  2. 2 1
      pkg/libcontainer/namespaces/nsenter.go

+ 7 - 8
pkg/libcontainer/namespaces/execin.go

@@ -14,12 +14,6 @@ import (
 
 
 // ExecIn uses an existing pid and joins the pid's namespaces with the new command.
 // ExecIn uses an existing pid and joins the pid's namespaces with the new command.
 func ExecIn(container *libcontainer.Container, nspid int, args []string) error {
 func ExecIn(container *libcontainer.Container, nspid int, args []string) error {
-	// clear the current processes env and replace it with the environment
-	// defined on the container
-	if err := LoadContainerEnvironment(container); err != nil {
-		return err
-	}
-
 	// TODO(vmarmol): If this gets too long, send it over a pipe to the child.
 	// TODO(vmarmol): If this gets too long, send it over a pipe to the child.
 	// Marshall the container into JSON since it won't be available in the namespace.
 	// Marshall the container into JSON since it won't be available in the namespace.
 	containerJson, err := json.Marshal(container)
 	containerJson, err := json.Marshal(container)
@@ -36,7 +30,7 @@ func ExecIn(container *libcontainer.Container, nspid int, args []string) error {
 	// Enter the namespace and then finish setup
 	// Enter the namespace and then finish setup
 	finalArgs := []string{os.Args[0], "nsenter", strconv.Itoa(nspid), processLabel, string(containerJson)}
 	finalArgs := []string{os.Args[0], "nsenter", strconv.Itoa(nspid), processLabel, string(containerJson)}
 	finalArgs = append(finalArgs, args...)
 	finalArgs = append(finalArgs, args...)
-	if err := system.Execv(finalArgs[0], finalArgs[0:], container.Env); err != nil {
+	if err := system.Execv(finalArgs[0], finalArgs[0:], os.Environ()); err != nil {
 		return err
 		return err
 	}
 	}
 	panic("unreachable")
 	panic("unreachable")
@@ -44,13 +38,18 @@ func ExecIn(container *libcontainer.Container, nspid int, args []string) error {
 
 
 // NsEnter is run after entering the namespace.
 // NsEnter is run after entering the namespace.
 func NsEnter(container *libcontainer.Container, processLabel string, nspid int, args []string) error {
 func NsEnter(container *libcontainer.Container, processLabel string, nspid int, args []string) error {
+	// clear the current processes env and replace it with the environment
+	// defined on the container
+	if err := LoadContainerEnvironment(container); err != nil {
+		return err
+	}
 	if err := FinalizeNamespace(container); err != nil {
 	if err := FinalizeNamespace(container); err != nil {
 		return err
 		return err
 	}
 	}
 	if err := label.SetProcessLabel(processLabel); err != nil {
 	if err := label.SetProcessLabel(processLabel); err != nil {
 		return err
 		return err
 	}
 	}
-	if err := system.Execv(args[0], args[0:], os.Environ()); err != nil {
+	if err := system.Execv(args[0], args[0:], container.Env); err != nil {
 		return err
 		return err
 	}
 	}
 	panic("unreachable")
 	panic("unreachable")

+ 2 - 1
pkg/libcontainer/namespaces/nsenter.go

@@ -85,8 +85,9 @@ void nsenter() {
 		fprintf(stderr, "nsenter: Failed to open directory \"%s\" with error: \"%s\"\n", ns_dir, strerror(errno));
 		fprintf(stderr, "nsenter: Failed to open directory \"%s\" with error: \"%s\"\n", ns_dir, strerror(errno));
 		exit(1);
 		exit(1);
 	}
 	}
+
 	while((dent = readdir(dir)) != NULL) {
 	while((dent = readdir(dir)) != NULL) {
-		if(strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0) {
+		if(strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0 || strcmp(dent->d_name, "user") == 0) {
 			continue;
 			continue;
 		}
 		}