提交 003ec8c8 编写于 作者: J jack.wxz 提交者: jia zhang

rune: runelet does not use logpipe if rune create in detach mode

Signed-off-by: Njack.wxz <wangxiaozhe@linux.alibaba.com>
上级 d2e29fc8
...@@ -478,7 +478,7 @@ func (c *linuxContainer) newParentProcess(p *Process) (parentProcess, error) { ...@@ -478,7 +478,7 @@ func (c *linuxContainer) newParentProcess(p *Process) (parentProcess, error) {
} }
logFilePair := filePair{parentLogPipe, childLogPipe} logFilePair := filePair{parentLogPipe, childLogPipe}
cmd := c.commandTemplate(p, childInitPipe, childLogPipe, p.AgentPipe) cmd := c.commandTemplate(p, childInitPipe, childLogPipe, p.AgentPipe, p.Detached)
if !p.Init { if !p.Init {
return c.newSetnsProcess(p, cmd, messageSockPair, logFilePair) return c.newSetnsProcess(p, cmd, messageSockPair, logFilePair)
} }
...@@ -494,7 +494,7 @@ func (c *linuxContainer) newParentProcess(p *Process) (parentProcess, error) { ...@@ -494,7 +494,7 @@ func (c *linuxContainer) newParentProcess(p *Process) (parentProcess, error) {
return c.newInitProcess(p, cmd, messageSockPair, logFilePair) return c.newInitProcess(p, cmd, messageSockPair, logFilePair)
} }
func (c *linuxContainer) commandTemplate(p *Process, childInitPipe *os.File, childLogPipe *os.File, agentPipe *os.File) *exec.Cmd { func (c *linuxContainer) commandTemplate(p *Process, childInitPipe *os.File, childLogPipe *os.File, agentPipe *os.File, detached int) *exec.Cmd {
cmd := exec.Command(c.initPath, c.initArgs[1:]...) cmd := exec.Command(c.initPath, c.initArgs[1:]...)
cmd.Args[0] = c.initArgs[0] cmd.Args[0] = c.initArgs[0]
cmd.Stdin = p.Stdin cmd.Stdin = p.Stdin
...@@ -537,6 +537,9 @@ func (c *linuxContainer) commandTemplate(p *Process, childInitPipe *os.File, chi ...@@ -537,6 +537,9 @@ func (c *linuxContainer) commandTemplate(p *Process, childInitPipe *os.File, chi
if c.config.Enclave.Signer != "server" { if c.config.Enclave.Signer != "server" {
cmd.Env = append(cmd.Env, "_LIBCONTAINER_PAL_ROOTFS=" + string(c.config.Rootfs)) cmd.Env = append(cmd.Env, "_LIBCONTAINER_PAL_ROOTFS=" + string(c.config.Rootfs))
} }
cmd.Env = append(cmd.Env,
fmt.Sprintf("_LIBCONTAINER_DETACHED=%d", detached))
} }
// NOTE: when running a container with no PID namespace and the parent process spawning the container is // NOTE: when running a container with no PID namespace and the parent process spawning the container is
......
...@@ -346,6 +346,7 @@ func (l *LinuxFactory) StartInitialization() (err error) { ...@@ -346,6 +346,7 @@ func (l *LinuxFactory) StartInitialization() (err error) {
envLogPipe = os.Getenv("_LIBCONTAINER_LOGPIPE") envLogPipe = os.Getenv("_LIBCONTAINER_LOGPIPE")
envLogLevel = os.Getenv("_LIBCONTAINER_LOGLEVEL") envLogLevel = os.Getenv("_LIBCONTAINER_LOGLEVEL")
envAgentPipe = os.Getenv("_LIBCONTAINER_AGENTPIPE") envAgentPipe = os.Getenv("_LIBCONTAINER_AGENTPIPE")
envDetached = os.Getenv("_LIBCONTAINER_DETACHED")
) )
// Get the INITPIPE. // Get the INITPIPE.
...@@ -417,7 +418,7 @@ func (l *LinuxFactory) StartInitialization() (err error) { ...@@ -417,7 +418,7 @@ func (l *LinuxFactory) StartInitialization() (err error) {
} }
}() }()
i, err := newContainerInit(it, pipe, consoleSocket, fifofd, logPipe, envLogLevel, agentPipe) i, err := newContainerInit(it, pipe, consoleSocket, fifofd, logPipe, envLogLevel, agentPipe, envDetached)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -73,7 +73,7 @@ type initer interface { ...@@ -73,7 +73,7 @@ type initer interface {
Init() error Init() error
} }
func newContainerInit(t initType, pipe *os.File, consoleSocket *os.File, fifoFd int, logPipe *os.File, logLevel string, agentPipe *os.File) (initer, error) { func newContainerInit(t initType, pipe *os.File, consoleSocket *os.File, fifoFd int, logPipe *os.File, logLevel string, agentPipe *os.File, detached string) (initer, error) {
var config *initConfig var config *initConfig
if err := json.NewDecoder(pipe).Decode(&config); err != nil { if err := json.NewDecoder(pipe).Decode(&config); err != nil {
return nil, err return nil, err
...@@ -90,6 +90,7 @@ func newContainerInit(t initType, pipe *os.File, consoleSocket *os.File, fifoFd ...@@ -90,6 +90,7 @@ func newContainerInit(t initType, pipe *os.File, consoleSocket *os.File, fifoFd
logPipe: logPipe, logPipe: logPipe,
logLevel: logLevel, logLevel: logLevel,
agentPipe: agentPipe, agentPipe: agentPipe,
detached: detached,
}, nil }, nil
case initStandard: case initStandard:
return &linuxStandardInit{ return &linuxStandardInit{
...@@ -101,6 +102,7 @@ func newContainerInit(t initType, pipe *os.File, consoleSocket *os.File, fifoFd ...@@ -101,6 +102,7 @@ func newContainerInit(t initType, pipe *os.File, consoleSocket *os.File, fifoFd
logPipe: logPipe, logPipe: logPipe,
logLevel: logLevel, logLevel: logLevel,
agentPipe: agentPipe, agentPipe: agentPipe,
detached: detached,
}, nil }, nil
} }
return nil, fmt.Errorf("unknown init type %q", t) return nil, fmt.Errorf("unknown init type %q", t)
......
...@@ -81,6 +81,8 @@ type Process struct { ...@@ -81,6 +81,8 @@ type Process struct {
// Provide agent service hosted by main runelet for child runelet. // Provide agent service hosted by main runelet for child runelet.
AgentPipe *os.File AgentPipe *os.File
Detached int
} }
// Wait waits for the process to exit. // Wait waits for the process to exit.
......
...@@ -28,6 +28,7 @@ type linuxSetnsInit struct { ...@@ -28,6 +28,7 @@ type linuxSetnsInit struct {
logPipe *os.File logPipe *os.File
logLevel string logLevel string
agentPipe *os.File agentPipe *os.File
detached string
} }
func (l *linuxSetnsInit) getSessionRingName() string { func (l *linuxSetnsInit) getSessionRingName() string {
...@@ -94,7 +95,7 @@ func (l *linuxSetnsInit) Init() error { ...@@ -94,7 +95,7 @@ func (l *linuxSetnsInit) Init() error {
} }
} }
if l.config.Config.Enclave != nil { if l.config.Config.Enclave != nil {
err := libenclave.StartBootstrap(l.pipe, l.logPipe, l.logLevel, -1, l.agentPipe) err := libenclave.StartBootstrap(l.pipe, l.logPipe, l.logLevel, -1, l.agentPipe, l.detached)
if err != nil { if err != nil {
return newSystemErrorWithCause(err, "libenclave bootstrap") return newSystemErrorWithCause(err, "libenclave bootstrap")
} }
......
...@@ -31,6 +31,7 @@ type linuxStandardInit struct { ...@@ -31,6 +31,7 @@ type linuxStandardInit struct {
logPipe *os.File logPipe *os.File
logLevel string logLevel string
agentPipe *os.File agentPipe *os.File
detached string
} }
func (l *linuxStandardInit) getSessionRingParams() (string, uint32, uint32) { func (l *linuxStandardInit) getSessionRingParams() (string, uint32, uint32) {
...@@ -179,7 +180,7 @@ func (l *linuxStandardInit) Init() error { ...@@ -179,7 +180,7 @@ func (l *linuxStandardInit) Init() error {
return unix.Kill(unix.Getpid(), unix.SIGKILL) return unix.Kill(unix.Getpid(), unix.SIGKILL)
} }
if l.config.Config.Enclave != nil { if l.config.Config.Enclave != nil {
err := libenclave.StartBootstrap(l.pipe, l.logPipe, l.logLevel, l.fifoFd, l.agentPipe) err := libenclave.StartBootstrap(l.pipe, l.logPipe, l.logLevel, l.fifoFd, l.agentPipe, l.detached)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
// environment variable must be staged and then recovered after re-exec. This // environment variable must be staged and then recovered after re-exec. This
// process is so called as libenclave bootstrapping, and the resulting process // process is so called as libenclave bootstrapping, and the resulting process
// is so called as runelet. // is so called as runelet.
func StartBootstrap(initPipe *os.File, logPipe *os.File, logLevel string, fifoFd int, agentPipe *os.File) (err error) { func StartBootstrap(initPipe *os.File, logPipe *os.File, logLevel string, fifoFd int, agentPipe *os.File, detached string) (err error) {
logrus.Debug("bootstrapping libenclave ...") logrus.Debug("bootstrapping libenclave ...")
if err = stageFd("_LIBENCLAVE_INITPIPE", initPipe); err != nil { if err = stageFd("_LIBENCLAVE_INITPIPE", initPipe); err != nil {
...@@ -60,5 +60,7 @@ func StartBootstrap(initPipe *os.File, logPipe *os.File, logLevel string, fifoFd ...@@ -60,5 +60,7 @@ func StartBootstrap(initPipe *os.File, logPipe *os.File, logLevel string, fifoFd
} }
}() }()
os.Setenv("_LIBENCLAVE_DETACHED", detached)
return nil return nil
} }
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"io" "io"
"io/ioutil"
"os" "os"
"os/signal" "os/signal"
"strconv" "strconv"
...@@ -96,6 +97,14 @@ func StartInitialization() (exitCode int32, err error) { ...@@ -96,6 +97,14 @@ func StartInitialization() (exitCode int32, err error) {
} }
} }
// If runelet run as detach mode, close logrus before initpipe closed.
envDetach := os.Getenv("_LIBENCLAVE_DETACHED")
detach, err := strconv.Atoi(envDetach)
if detach != 0 {
logrus.SetOutput(ioutil.Discard)
}
os.Unsetenv("_LIBENCLAVE_DETACHED")
// Close the init pipe to signal that we have completed our init. // Close the init pipe to signal that we have completed our init.
// So `rune create` or the upper half part of `rune run` can return. // So `rune create` or the upper half part of `rune run` can return.
initPipe.Close() initPipe.Close()
......
...@@ -305,6 +305,11 @@ func (r *runner) run(config *specs.Process) (int, error) { ...@@ -305,6 +305,11 @@ func (r *runner) run(config *specs.Process) (int, error) {
var ( var (
detach = r.detach || (r.action == CT_ACT_CREATE) detach = r.detach || (r.action == CT_ACT_CREATE)
) )
if detach {
process.Detached = 1
}
// Setting up IO is a two stage process. We need to modify process to deal // Setting up IO is a two stage process. We need to modify process to deal
// with detaching containers, and then we get a tty after the container has // with detaching containers, and then we get a tty after the container has
// started. // started.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册