Skip to content

Instantly share code, notes, and snippets.

@boucher
Created April 27, 2015 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boucher/d1c6e8cd434099c698f2 to your computer and use it in GitHub Desktop.
Save boucher/d1c6e8cd434099c698f2 to your computer and use it in GitHub Desktop.
diff --git a/container_linux.go b/container_linux.go
index f76c777..1e596b5 100644
--- a/container_linux.go
+++ b/container_linux.go
@@ -5,6 +5,7 @@ package libcontainer
import (
"encoding/json"
"fmt"
+ "io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -353,7 +354,7 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error {
extMnt := new(criurpc.ExtMountMap)
extMnt.Key = proto.String(mountDest)
- extMnt.Val = proto.String(m.Destination)
+ extMnt.Val = proto.String(mountDest)
req.Opts.ExtMnt = append(req.Opts.ExtMnt, extMnt)
}
}
@@ -364,6 +365,12 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error {
return err
}
+ // Write the FD info to a file in the image directory
+ fdsJSON, _ := json.Marshal(c.config.StdFds)
+ log.Debugf("Going to write: %s", fdsJSON)
+
+ err = ioutil.WriteFile(filepath.Join(criuOpts.ImagesDirectory, "std_fds.json"), fdsJSON, 0655)
+
log.Info("Checkpointed")
return nil
}
@@ -443,8 +450,13 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
}
for _, m := range c.config.Mounts {
if m.Device == "bind" {
+ mountDest := m.Destination
+ if strings.HasPrefix(mountDest, c.config.Rootfs) {
+ mountDest = mountDest[len(c.config.Rootfs):]
+ }
+
extMnt := new(criurpc.ExtMountMap)
- extMnt.Key = proto.String(m.Destination)
+ extMnt.Key = proto.String(mountDest)
extMnt.Val = proto.String(m.Source)
req.Opts.ExtMnt = append(req.Opts.ExtMnt, extMnt)
}
@@ -463,9 +475,14 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
}
// Pipes that were previously set up for std{in,out,err}
// were removed after checkpoint. Use the new ones.
+ var fds [3]string
+ fdJSON, err := ioutil.ReadFile(filepath.Join(criuOpts.ImagesDirectory, "std_fds.json"))
+ err = json.Unmarshal(fdJSON, &fds)
+ log.Debugf("Read JSON: %v", fds)
+
var i int32
for i = 0; i < 3; i++ {
- if s := c.config.StdFds[i]; strings.Contains(s, "pipe:") {
+ if s := fds[i]; strings.Contains(s, "pipe:") {
inheritFd := new(criurpc.InheritFd)
inheritFd.Key = proto.String(s)
inheritFd.Fd = proto.Int32(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment