Refactor saving fds slightly, set the restored process fds correctly.
Docker-DCO-1.1-Signed-off-by: Ross Boucher <rboucher@gmail.com> (github: boucher)
This commit is contained in:
parent
38635c5a11
commit
3d59a7fe8b
|
@ -558,6 +558,14 @@ func (c *linuxContainer) criuSwrk(process *Process, req *criurpc.CriuReq, opts *
|
|||
log.Warn(st.String())
|
||||
}()
|
||||
|
||||
if process != nil {
|
||||
fds, err := getPipeFds(cmd.Process.Pid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.initProcess.setStdFds(fds)
|
||||
}
|
||||
|
||||
data, err := proto.Marshal(req)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -692,7 +700,7 @@ func (c *linuxContainer) criuNotifications(resp *criurpc.CriuResp, process *Proc
|
|||
|
||||
case notify.GetScript() == "post-restore":
|
||||
pid := notify.GetPid()
|
||||
r, err := newRestoredProcess(int(pid))
|
||||
r, err := newRestoredProcess(int(pid), c.initProcess.stdFds())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@ type parentProcess interface {
|
|||
signal(os.Signal) error
|
||||
|
||||
stdFds() [3]string
|
||||
|
||||
setStdFds(fds [3]string)
|
||||
}
|
||||
|
||||
type setnsProcess struct {
|
||||
|
@ -43,6 +45,7 @@ type setnsProcess struct {
|
|||
childPipe *os.File
|
||||
cgroupPaths map[string]string
|
||||
config *initConfig
|
||||
fds [3]string
|
||||
}
|
||||
|
||||
func (p *setnsProcess) startTime() (string, error) {
|
||||
|
@ -147,7 +150,11 @@ func (p *setnsProcess) pid() int {
|
|||
}
|
||||
|
||||
func (p *setnsProcess) stdFds() [3]string {
|
||||
return [3]string{"", "", ""}
|
||||
return p.fds
|
||||
}
|
||||
|
||||
func (p *setnsProcess) setStdFds(newFds [3]string) {
|
||||
p.fds = newFds
|
||||
}
|
||||
|
||||
type initProcess struct {
|
||||
|
@ -178,16 +185,11 @@ func (p *initProcess) start() error {
|
|||
// Save the standard descriptor names before the container process
|
||||
// can potentially move them (e.g., via dup2()). If we don't do this now,
|
||||
// we won't know at checkpoint time which file descriptor to look up.
|
||||
// we need this info to restore the container
|
||||
dirPath := filepath.Join("/proc", strconv.Itoa(p.pid()), "/fd")
|
||||
for i := 0; i < 3; i++ {
|
||||
f := filepath.Join(dirPath, strconv.Itoa(i))
|
||||
target, err := os.Readlink(f)
|
||||
if err != nil {
|
||||
return newSystemError(err)
|
||||
}
|
||||
p.fds[i] = target
|
||||
fds, err := getPipeFds(p.pid())
|
||||
if err != nil {
|
||||
return newSystemError(err)
|
||||
}
|
||||
p.setStdFds(fds);
|
||||
|
||||
// Do this before syncing with child so that no children
|
||||
// can escape the cgroup
|
||||
|
@ -278,3 +280,22 @@ func (p *initProcess) signal(sig os.Signal) error {
|
|||
}
|
||||
return syscall.Kill(p.cmd.Process.Pid, s)
|
||||
}
|
||||
|
||||
func (p *initProcess) setStdFds(newFds [3]string) {
|
||||
p.fds = newFds
|
||||
}
|
||||
|
||||
func getPipeFds(pid int) ([3]string, error) {
|
||||
var fds [3]string;
|
||||
|
||||
dirPath := filepath.Join("/proc", strconv.Itoa(pid), "/fd")
|
||||
for i := 0; i < 3; i++ {
|
||||
f := filepath.Join(dirPath, strconv.Itoa(i))
|
||||
target, err := os.Readlink(f)
|
||||
if err != nil {
|
||||
return fds, err
|
||||
}
|
||||
fds[i] = target
|
||||
}
|
||||
return fds, nil
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/docker/libcontainer/system"
|
||||
)
|
||||
|
||||
func newRestoredProcess(pid int) (*restoredProcess, error) {
|
||||
func newRestoredProcess(pid int, fds [3]string) (*restoredProcess, error) {
|
||||
var (
|
||||
err error
|
||||
)
|
||||
|
@ -24,12 +24,14 @@ func newRestoredProcess(pid int) (*restoredProcess, error) {
|
|||
return &restoredProcess{
|
||||
proc: proc,
|
||||
processStartTime: started,
|
||||
fds: fds,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type restoredProcess struct {
|
||||
proc *os.Process
|
||||
processStartTime string
|
||||
fds [3]string
|
||||
}
|
||||
|
||||
func (p *restoredProcess) start() error {
|
||||
|
@ -67,7 +69,11 @@ func (p *restoredProcess) signal(s os.Signal) error {
|
|||
}
|
||||
|
||||
func (p *restoredProcess) stdFds() [3]string {
|
||||
return [3]string{"", "", ""}
|
||||
return p.fds
|
||||
}
|
||||
|
||||
func (p *restoredProcess) setStdFds(newFds [3]string) {
|
||||
p.fds = newFds
|
||||
}
|
||||
|
||||
// nonChildProcess represents a process where the calling process is not
|
||||
|
@ -76,6 +82,7 @@ func (p *restoredProcess) stdFds() [3]string {
|
|||
type nonChildProcess struct {
|
||||
processPid int
|
||||
processStartTime string
|
||||
fds [3]string
|
||||
}
|
||||
|
||||
func (p *nonChildProcess) start() error {
|
||||
|
@ -103,5 +110,9 @@ func (p *nonChildProcess) signal(s os.Signal) error {
|
|||
}
|
||||
|
||||
func (p *nonChildProcess) stdFds() [3]string {
|
||||
return [3]string{"", "", ""}
|
||||
return p.fds
|
||||
}
|
||||
|
||||
func (p *nonChildProcess) setStdFds(newFds [3]string) {
|
||||
p.fds = newFds
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue