Skip to content

Commit

Permalink
Move locking to caller.
Browse files Browse the repository at this point in the history
Docker-DCO-1.1-Signed-off-by: Mrunal Patel <mrunalp@gmail.com> (github: mrunalp)
  • Loading branch information
mrunalp committed Aug 1, 2014
1 parent ef3c884 commit 7f3bbbb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 2 additions & 3 deletions namespaces/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package namespaces
import (
"fmt"
"os"
"runtime"
"strings"
"syscall"

Expand All @@ -28,6 +27,8 @@ import (
// Move this to libcontainer package.
// Init is the init process that first runs inside a new namespace to setup mounts, users, networking,
// and other options required for the new container.
// The caller of Init function has to ensure that the go runtime is locked to an OS thread
// (using runtime.LockOSThread) else system calls like setns called within Init may not work as intended.
func Init(container *libcontainer.Config, uncleanRootfs, consolePath string, syncPipe *syncpipe.SyncPipe, args []string) (err error) {
defer func() {
if err != nil {
Expand Down Expand Up @@ -87,8 +88,6 @@ func Init(container *libcontainer.Config, uncleanRootfs, consolePath string, syn
}
}

runtime.LockOSThread()

if err := apparmor.ApplyProfile(container.AppArmorProfile); err != nil {
return fmt.Errorf("set apparmor profile %s: %s", container.AppArmorProfile, err)
}
Expand Down
3 changes: 3 additions & 0 deletions nsinit/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nsinit
import (
"log"
"os"
"runtime"
"strconv"

"github.com/codegangsta/cli"
Expand All @@ -23,6 +24,8 @@ var (
)

func initAction(context *cli.Context) {
runtime.LockOSThread()

container, err := loadContainer()
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 7f3bbbb

Please sign in to comment.