зеркало из https://github.com/microsoft/docker.git
Fix tests with dockerinit lookup path
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Родитель
8f20058307
Коммит
01f9815b55
|
@ -17,7 +17,7 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
if selfPath := utils.SelfPath(); selfPath == "/sbin/init" || strings.Contains(selfPath, "/.dockerinit") {
|
||||
if selfPath := utils.SelfPath(); selfPath == "/sbin/init" || strings.Contains(selfPath, ".dockerinit") {
|
||||
// Running in init mode
|
||||
sysinit.SysInit()
|
||||
return
|
||||
|
|
|
@ -86,7 +86,7 @@ func (d *driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba
|
|||
return -1, err
|
||||
}
|
||||
args := append([]string{c.Entrypoint}, c.Arguments...)
|
||||
return nsinit.Exec(container, factory, stateWriter, term, "/nsinit.log", args)
|
||||
return nsinit.Exec(container, factory, stateWriter, term, "", args)
|
||||
}
|
||||
|
||||
func (d *driver) Kill(p *execdriver.Command, sig int) error {
|
||||
|
@ -146,6 +146,7 @@ func (d *dockerCommandFactory) Create(container *libcontainer.Container,
|
|||
"-driver", DriverName,
|
||||
"-console", console,
|
||||
"-pipe", fmt.Sprint(syncFd),
|
||||
"-log", logFile,
|
||||
}, args...)
|
||||
c.SysProcAttr = &syscall.SysProcAttr{
|
||||
Cloneflags: uintptr(nsinit.GetNamespaceFlags(container.Namespaces)),
|
||||
|
|
|
@ -85,7 +85,7 @@ func init() {
|
|||
os.Setenv("TEST", "1")
|
||||
|
||||
// Hack to run sys init during unit testing
|
||||
if selfPath := utils.SelfPath(); selfPath == "/sbin/init" || selfPath == "/.dockerinit" {
|
||||
if selfPath := utils.SelfPath(); selfPath == "/sbin/init" || strings.Contains(selfPath, ".dockerinit") {
|
||||
sysinit.SysInit()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ var (
|
|||
ErrWrongArguments = errors.New("Wrong argument count")
|
||||
)
|
||||
|
||||
func init() {
|
||||
func registerFlags() {
|
||||
flag.StringVar(&console, "console", "", "console (pty slave) path")
|
||||
flag.StringVar(&logFile, "log", "none", "log options (none, stderr, or a file path)")
|
||||
flag.IntVar(&pipeFd, "pipe", 0, "sync pipe fd")
|
||||
|
@ -33,6 +33,8 @@ func init() {
|
|||
}
|
||||
|
||||
func main() {
|
||||
registerFlags()
|
||||
|
||||
if flag.NArg() < 1 {
|
||||
log.Fatal(ErrWrongArguments)
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/dotcloud/docker/execdriver"
|
||||
_ "github.com/dotcloud/docker/execdriver/chroot"
|
||||
_ "github.com/dotcloud/docker/execdriver/lxc"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
|
@ -55,9 +56,14 @@ func SysInit() {
|
|||
driver = flag.String("driver", "", "exec driver")
|
||||
pipe = flag.Int("pipe", 0, "sync pipe fd")
|
||||
console = flag.String("console", "", "console (pty slave) path")
|
||||
logFile = flag.String("log", "", "log file path")
|
||||
)
|
||||
flag.Parse()
|
||||
|
||||
if err := setupLogging(*logFile); err != nil {
|
||||
log.Fatalf("setup logging %s", err)
|
||||
}
|
||||
|
||||
// Get env
|
||||
var env []string
|
||||
content, err := ioutil.ReadFile("/.dockerenv")
|
||||
|
@ -67,7 +73,6 @@ func SysInit() {
|
|||
if err := json.Unmarshal(content, &env); err != nil {
|
||||
log.Fatalf("Unable to unmarshal environment variables: %v", err)
|
||||
}
|
||||
|
||||
// Propagate the plugin-specific container env variable
|
||||
env = append(env, "container="+os.Getenv("container"))
|
||||
|
||||
|
@ -89,3 +94,20 @@ func SysInit() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func setupLogging(logFile string) (err error) {
|
||||
var writer io.Writer
|
||||
switch logFile {
|
||||
case "stderr":
|
||||
writer = os.Stderr
|
||||
case "none", "":
|
||||
writer = ioutil.Discard
|
||||
default:
|
||||
writer, err = os.OpenFile(logFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
log.SetOutput(writer)
|
||||
return nil
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче