Make nsinit a proper go pkg and add the main in another dir
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
52fa4de610
commit
5d71533d4e
7 changed files with 20 additions and 12 deletions
|
@ -1,6 +1,6 @@
|
|||
// +build linux
|
||||
|
||||
package main
|
||||
package nsinit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -16,7 +16,9 @@ import (
|
|||
"syscall"
|
||||
)
|
||||
|
||||
func execCommand(container *libcontainer.Container, tty bool, args []string) (int, error) {
|
||||
// Exec performes setup outside of a namespace so that a container can be
|
||||
// executed. Exec is a high level function for working with container namespaces.
|
||||
func Exec(container *libcontainer.Container, tty bool, args []string) (int, error) {
|
||||
var (
|
||||
master *os.File
|
||||
console string
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package nsinit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -11,7 +11,8 @@ import (
|
|||
"syscall"
|
||||
)
|
||||
|
||||
func execinCommand(container *libcontainer.Container, nspid int, args []string) (int, error) {
|
||||
// ExecIn uses an existing pid and joins the pid's namespaces with the new command.
|
||||
func ExecIn(container *libcontainer.Container, nspid int, args []string) (int, error) {
|
||||
for _, ns := range container.Namespaces {
|
||||
if err := system.Unshare(namespaceMap[ns]); err != nil {
|
||||
return -1, err
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// +build linux
|
||||
|
||||
package main
|
||||
package nsinit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -15,7 +15,9 @@ import (
|
|||
"syscall"
|
||||
)
|
||||
|
||||
func initCommand(container *libcontainer.Container, console string, pipe io.ReadCloser, args []string) error {
|
||||
// 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.
|
||||
func Init(container *libcontainer.Container, console string, pipe io.ReadCloser, args []string) error {
|
||||
rootfs, err := resolveRootfs()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// +build linux
|
||||
|
||||
package main
|
||||
package nsinit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package nsinit
|
||||
|
||||
import (
|
||||
"github.com/dotcloud/docker/pkg/libcontainer"
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"errors"
|
||||
"flag"
|
||||
"github.com/dotcloud/docker/pkg/libcontainer"
|
||||
"github.com/dotcloud/docker/pkg/libcontainer/nsinit"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
|
@ -42,9 +43,9 @@ func main() {
|
|||
}
|
||||
}
|
||||
if nspid > 0 {
|
||||
exitCode, err = execinCommand(container, nspid, flag.Args()[1:])
|
||||
exitCode, err = nsinit.ExecIn(container, nspid, flag.Args()[1:])
|
||||
} else {
|
||||
exitCode, err = execCommand(container, *tty, flag.Args()[1:])
|
||||
exitCode, err = nsinit.Exec(container, *tty, flag.Args()[1:])
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -54,7 +55,7 @@ func main() {
|
|||
if flag.NArg() < 2 {
|
||||
log.Fatal(ErrWrongArguments)
|
||||
}
|
||||
if err := initCommand(container, *console, os.NewFile(uintptr(*pipeFd), "pipe"), flag.Args()[1:]); err != nil {
|
||||
if err := nsinit.Init(container, *console, os.NewFile(uintptr(*pipeFd), "pipe"), flag.Args()[1:]); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
default:
|
Loading…
Add table
Add a link
Reference in a new issue