@@ -4,13 +4,8 @@ package main
44
55import (
66 "os"
7- "syscall"
87
9- "github.com/Sirupsen/logrus"
108 "github.com/opencontainers/runc/libcontainer"
11- "github.com/opencontainers/runc/libcontainer/configs"
12- "github.com/opencontainers/runc/libcontainer/specconv"
13- "github.com/opencontainers/runtime-spec/specs-go"
149 "github.com/urfave/cli"
1510)
1611
@@ -86,111 +81,25 @@ using the runc checkpoint command.`,
8681 if err := checkArgs (context , 1 , exactArgs ); err != nil {
8782 return err
8883 }
89- imagePath := context .String ("image-path" )
90- id := context .Args ().First ()
91- if id == "" {
92- return errEmptyID
93- }
94- if imagePath == "" {
95- imagePath = getDefaultImagePath (context )
96- }
97- bundle := context .String ("bundle" )
98- if bundle != "" {
99- if err := os .Chdir (bundle ); err != nil {
100- return err
101- }
84+ if err := revisePidFile (context ); err != nil {
85+ return err
10286 }
103- spec , err := loadSpec ( specConfig )
87+ spec , err := setupSpec ( context )
10488 if err != nil {
10589 return err
10690 }
107- config , err := specconv .CreateLibcontainerConfig (& specconv.CreateOpts {
108- CgroupName : id ,
109- UseSystemdCgroup : context .GlobalBool ("systemd-cgroup" ),
110- NoPivotRoot : context .Bool ("no-pivot" ),
111- Spec : spec ,
112- })
91+ options := criuOptions (context )
92+ status , err := startContainer (context , spec , CT_ACT_RESTORE , options )
11393 if err != nil {
11494 return err
11595 }
116- status , err := restoreContainer (context , spec , config , imagePath )
117- if err == nil {
118- os .Exit (status )
119- }
120- return err
96+ // exit with the container's exit status so any external supervisor is
97+ // notified of the exit with the correct exit status.
98+ os .Exit (status )
99+ return nil
121100 },
122101}
123102
124- func restoreContainer (context * cli.Context , spec * specs.Spec , config * configs.Config , imagePath string ) (int , error ) {
125- var (
126- rootuid = 0
127- rootgid = 0
128- id = context .Args ().First ()
129- )
130- factory , err := loadFactory (context )
131- if err != nil {
132- return - 1 , err
133- }
134- container , err := factory .Load (id )
135- if err != nil {
136- container , err = factory .Create (id , config )
137- if err != nil {
138- return - 1 , err
139- }
140- }
141- options := criuOptions (context )
142-
143- status , err := container .Status ()
144- if err != nil {
145- logrus .Error (err )
146- }
147- if status == libcontainer .Running {
148- fatalf ("Container with id %s already running" , id )
149- }
150-
151- setManageCgroupsMode (context , options )
152-
153- if err = setEmptyNsMask (context , options ); err != nil {
154- return - 1 , err
155- }
156-
157- // ensure that the container is always removed if we were the process
158- // that created it.
159- detach := context .Bool ("detach" )
160- if ! detach {
161- defer destroy (container )
162- }
163- process := & libcontainer.Process {}
164- tty , err := setupIO (process , rootuid , rootgid , false , detach )
165- if err != nil {
166- return - 1 , err
167- }
168-
169- notifySocket := newNotifySocket (context , os .Getenv ("NOTIFY_SOCKET" ), id )
170- if notifySocket != nil {
171- notifySocket .setupSpec (context , spec )
172- notifySocket .setupSocket ()
173- }
174-
175- handler := newSignalHandler (! context .Bool ("no-subreaper" ), notifySocket )
176- if err := container .Restore (process , options ); err != nil {
177- return - 1 , err
178- }
179- // We don't need to do a tty.recvtty because config.Terminal is always false.
180- defer tty .Close ()
181- if err := tty .ClosePostStart (); err != nil {
182- return - 1 , err
183- }
184- if pidFile := context .String ("pid-file" ); pidFile != "" {
185- if err := createPidFile (pidFile , process ); err != nil {
186- _ = process .Signal (syscall .SIGKILL )
187- _ , _ = process .Wait ()
188- return - 1 , err
189- }
190- }
191- return handler .forward (process , tty , detach )
192- }
193-
194103func criuOptions (context * cli.Context ) * libcontainer.CriuOpts {
195104 imagePath := getCheckpointImagePath (context )
196105 if err := os .MkdirAll (imagePath , 0655 ); err != nil {
0 commit comments