From 711a9869e54743b05fc3478be5adce31d45cefe5 Mon Sep 17 00:00:00 2001 From: Brielle Broder Date: Tue, 12 Jun 2018 13:24:22 -0700 Subject: Runsc checkpoint works. This is the first iteration of checkpoint that actually saves to a file. Tests for checkpoint are included. Ran into an issue when private unix sockets are enabled. An error message was added for this case and the mutex state was set. PiperOrigin-RevId: 200269470 Change-Id: I28d29a9f92c44bf73dc4a4b12ae0509ee4070e93 --- runsc/cmd/checkpoint.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'runsc/cmd') diff --git a/runsc/cmd/checkpoint.go b/runsc/cmd/checkpoint.go index 9b045da1c..927027c2b 100644 --- a/runsc/cmd/checkpoint.go +++ b/runsc/cmd/checkpoint.go @@ -15,6 +15,8 @@ package cmd import ( + "os" + "context" "flag" "github.com/google/subcommands" @@ -24,6 +26,7 @@ import ( // Checkpoint implements subcommands.Command for the "checkpoint" command. type Checkpoint struct { + imagePath string } // Name implements subcommands.Command.Name. @@ -44,6 +47,7 @@ func (*Checkpoint) Usage() string { // SetFlags implements subcommands.Command.SetFlags. func (c *Checkpoint) SetFlags(f *flag.FlagSet) { + f.StringVar(&c.imagePath, "image-path", "", "path to saved container image") } // Execute implements subcommands.Command.Execute. @@ -62,7 +66,18 @@ func (c *Checkpoint) Execute(_ context.Context, f *flag.FlagSet, args ...interfa Fatalf("error loading container: %v", err) } - if err := cont.Checkpoint(); err != nil { + if c.imagePath == "" { + Fatalf("image-path flag must be provided") + } + + // Create the image file and open for writing. + file, err := os.OpenFile(c.imagePath, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0644) + if err != nil { + Fatalf("os.OpenFile(%q) failed: %v", c.imagePath, err) + } + defer file.Close() + + if err := cont.Checkpoint(file); err != nil { Fatalf("checkpoint failed: %v", err) } -- cgit v1.2.3