@@ -5,13 +5,8 @@ package main
55import (
66 "fmt"
77 "os"
8- "syscall"
98
10- "github.com/Sirupsen/logrus"
119 "github.com/opencontainers/runc/libcontainer"
12- "github.com/opencontainers/runc/libcontainer/configs"
13- "github.com/opencontainers/runc/libcontainer/specconv"
14- "github.com/opencontainers/runtime-spec/specs-go"
1510 "github.com/urfave/cli"
1611)
1712
@@ -92,111 +87,22 @@ using the runc checkpoint command.`,
9287 return fmt .Errorf ("runc restore requires root" )
9388 }
9489
95- imagePath := context .String ("image-path" )
96- id := context .Args ().First ()
97- if id == "" {
98- return errEmptyID
99- }
100- if imagePath == "" {
101- imagePath = getDefaultImagePath (context )
102- }
103- bundle := context .String ("bundle" )
104- if bundle != "" {
105- if err := os .Chdir (bundle ); err != nil {
106- return err
107- }
108- }
109- spec , err := loadSpec (specConfig )
90+ spec , err := setupSpec (context )
11091 if err != nil {
11192 return err
11293 }
113- config , err := specconv .CreateLibcontainerConfig (& specconv.CreateOpts {
114- CgroupName : id ,
115- UseSystemdCgroup : context .GlobalBool ("systemd-cgroup" ),
116- NoPivotRoot : context .Bool ("no-pivot" ),
117- Spec : spec ,
118- })
94+ options := criuOptions (context )
95+ status , err := startContainer (context , spec , CT_ACT_RESTORE , options )
11996 if err != nil {
12097 return err
12198 }
122- status , err := restoreContainer (context , spec , config , imagePath )
123- if err == nil {
124- os .Exit (status )
125- }
126- return err
99+ // exit with the container's exit status so any external supervisor is
100+ // notified of the exit with the correct exit status.
101+ os .Exit (status )
102+ return nil
127103 },
128104}
129105
130- func restoreContainer (context * cli.Context , spec * specs.Spec , config * configs.Config , imagePath string ) (int , error ) {
131- var (
132- rootuid = 0
133- rootgid = 0
134- id = context .Args ().First ()
135- )
136- factory , err := loadFactory (context )
137- if err != nil {
138- return - 1 , err
139- }
140- container , err := factory .Load (id )
141- if err != nil {
142- container , err = factory .Create (id , config )
143- if err != nil {
144- return - 1 , err
145- }
146- }
147- options := criuOptions (context )
148-
149- status , err := container .Status ()
150- if err != nil {
151- logrus .Error (err )
152- }
153- if status == libcontainer .Running {
154- fatalf ("Container with id %s already running" , id )
155- }
156-
157- setManageCgroupsMode (context , options )
158-
159- if err = setEmptyNsMask (context , options ); err != nil {
160- return - 1 , err
161- }
162-
163- // ensure that the container is always removed if we were the process
164- // that created it.
165- detach := context .Bool ("detach" )
166- if ! detach {
167- defer destroy (container )
168- }
169- process := & libcontainer.Process {}
170- tty , err := setupIO (process , rootuid , rootgid , false , detach , "" )
171- if err != nil {
172- return - 1 , err
173- }
174-
175- notifySocket := newNotifySocket (context , os .Getenv ("NOTIFY_SOCKET" ), id )
176- if notifySocket != nil {
177- notifySocket .setupSpec (context , spec )
178- notifySocket .setupSocket ()
179- }
180-
181- handler := newSignalHandler (! context .Bool ("no-subreaper" ), notifySocket )
182- if err := container .Restore (process , options ); err != nil {
183- return - 1 , err
184- }
185- // We don't need to do a tty.recvtty because config.Terminal is always false.
186- defer tty .Close ()
187- if err := tty .ClosePostStart (); err != nil {
188- return - 1 , err
189- }
190- if pidFile := context .String ("pid-file" ); pidFile != "" {
191- if err := createPidFile (pidFile , process ); err != nil {
192- _ = process .Signal (syscall .SIGKILL )
193- _ , _ = process .Wait ()
194- return - 1 , err
195- }
196- }
197- return handler .forward (process , tty , detach )
198- }
199-
200106func criuOptions (context * cli.Context ) * libcontainer.CriuOpts {
201107 imagePath := getCheckpointImagePath (context )
202108 if err := os .MkdirAll (imagePath , 0655 ); err != nil {
0 commit comments