Add close stdin
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
277cc920a4
commit
a42eb9fd63
12 changed files with 358 additions and 157 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/containerd/util"
|
||||
"github.com/docker/docker/pkg/term"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -40,6 +41,7 @@ func main() {
|
|||
// or if runc exits before we hit the handler
|
||||
signals := make(chan os.Signal, 2048)
|
||||
signal.Notify(signals)
|
||||
setupLogger()
|
||||
// set the shim as the subreaper for all orphaned processes created by the container
|
||||
if err := util.SetSubreaper(1); err != nil {
|
||||
logrus.WithField("error", err).Fatal("shim: set as subreaper")
|
||||
|
@ -50,6 +52,11 @@ func main() {
|
|||
logrus.WithField("error", err).Fatal("shim: open exit pipe")
|
||||
}
|
||||
defer f.Close()
|
||||
control, err := os.OpenFile("control", syscall.O_RDWR, 0)
|
||||
if err != nil {
|
||||
logrus.WithField("error", err).Fatal("shim: open control pipe")
|
||||
}
|
||||
defer control.Close()
|
||||
p, err := newProcess(flag.Arg(0), flag.Arg(1), fexec, fcheckpoint)
|
||||
if err != nil {
|
||||
logrus.WithField("error", err).Fatal("shim: create new process")
|
||||
|
@ -57,6 +64,29 @@ func main() {
|
|||
if err := p.start(); err != nil {
|
||||
logrus.WithField("error", err).Fatal("shim: start process")
|
||||
}
|
||||
go func() {
|
||||
for {
|
||||
var msg, w, h int
|
||||
if _, err := fmt.Fscanf(control, "%d %d %d\n", &msg, &w, &h); err != nil {
|
||||
logrus.WithField("error", err).Error("shim: reading from control")
|
||||
}
|
||||
logrus.Info("got control message")
|
||||
switch msg {
|
||||
case 0:
|
||||
// close stdin
|
||||
p.shimIO.Stdin.Close()
|
||||
case 1:
|
||||
if p.console == nil {
|
||||
continue
|
||||
}
|
||||
ws := term.Winsize{
|
||||
Width: uint16(w),
|
||||
Height: uint16(h),
|
||||
}
|
||||
term.SetWinsize(p.console.Fd(), &ws)
|
||||
}
|
||||
}
|
||||
}()
|
||||
var exitShim bool
|
||||
for s := range signals {
|
||||
logrus.WithField("signal", s).Debug("shim: received signal")
|
||||
|
|
|
@ -23,6 +23,9 @@ type process struct {
|
|||
exec bool
|
||||
containerPid int
|
||||
checkpoint *runtime.Checkpoint
|
||||
shimIO *IO
|
||||
console libcontainer.Console
|
||||
consolePath string
|
||||
}
|
||||
|
||||
func newProcess(id, bundle string, exec bool, checkpoint string) (*process, error) {
|
||||
|
@ -86,7 +89,7 @@ func (p *process) start() error {
|
|||
if p.exec {
|
||||
args = append(args, "exec",
|
||||
"--process", filepath.Join(cwd, "process.json"),
|
||||
"--console", p.stdio.console,
|
||||
"--console", p.consolePath,
|
||||
)
|
||||
} else if p.checkpoint != nil {
|
||||
args = append(args, "restore",
|
||||
|
@ -107,7 +110,7 @@ func (p *process) start() error {
|
|||
} else {
|
||||
args = append(args, "start",
|
||||
"--bundle", p.bundle,
|
||||
"--console", p.stdio.console,
|
||||
"--console", p.consolePath,
|
||||
)
|
||||
}
|
||||
args = append(args,
|
||||
|
@ -161,7 +164,8 @@ func (p *process) openIO() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.stdio.console = console.Path()
|
||||
p.console = console
|
||||
p.consolePath = console.Path()
|
||||
stdin, err := os.OpenFile("stdin", syscall.O_RDWR, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -181,6 +185,7 @@ func (p *process) openIO() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.shimIO = i
|
||||
// non-tty
|
||||
for name, dest := range map[string]func(f *os.File){
|
||||
"stdin": func(f *os.File) {
|
||||
|
@ -251,10 +256,9 @@ func (p *process) Close() error {
|
|||
}
|
||||
|
||||
type stdio struct {
|
||||
stdin *os.File
|
||||
stdout *os.File
|
||||
stderr *os.File
|
||||
console string
|
||||
stdin *os.File
|
||||
stdout *os.File
|
||||
stderr *os.File
|
||||
}
|
||||
|
||||
func (s *stdio) Close() error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue