@@ -18,6 +18,8 @@ import (
1818 "syscall"
1919 "time"
2020
21+ "golang.org/x/sys/unix"
22+
2123 "github.com/Sirupsen/logrus"
2224 "github.com/golang/protobuf/proto"
2325 "github.com/opencontainers/runc/libcontainer/cgroups"
@@ -1033,7 +1035,7 @@ func (c *linuxContainer) criuApplyCgroups(pid int, req *criurpc.CriuReq) error {
10331035}
10341036
10351037func (c * linuxContainer ) criuSwrk (process * Process , req * criurpc.CriuReq , opts * CriuOpts , applyCgroups bool ) error {
1036- fds , err := syscall .Socketpair (syscall .AF_LOCAL , syscall .SOCK_SEQPACKET | syscall .SOCK_CLOEXEC , 0 )
1038+ fds , err := unix .Socketpair (syscall .AF_LOCAL , syscall .SOCK_SEQPACKET | syscall .SOCK_CLOEXEC , 0 )
10371039 if err != nil {
10381040 return err
10391041 }
@@ -1164,38 +1166,28 @@ func (c *linuxContainer) criuSwrk(process *Process, req *criurpc.CriuReq, opts *
11641166 continue
11651167 case t == criurpc .CriuReqType_RESTORE :
11661168 case t == criurpc .CriuReqType_DUMP :
1167- break
11681169 case t == criurpc .CriuReqType_PRE_DUMP :
1169- // In pre-dump mode CRIU is in a loop and waits for
1170- // the final DUMP command.
1171- // The current runc pre-dump approach, however, is
1172- // start criu in PRE_DUMP once for a single pre-dump
1173- // and not the whole series of pre-dump, pre-dump, ...m, dump
1174- // If we got the message CriuReqType_PRE_DUMP it means
1175- // CRIU was successful and we need to forcefully stop CRIU
1176- logrus .Debugf ("PRE_DUMP finished. Send close signal to CRIU service" )
1177- criuClient .Close ()
1178- // Process status won't be success, because one end of sockets is closed
1179- _ , err := cmd .Process .Wait ()
1180- if err != nil {
1181- logrus .Debugf ("After PRE_DUMP CRIU exiting failed" )
1182- return err
1183- }
1184- return nil
11851170 default :
11861171 return fmt .Errorf ("unable to parse the response %s" , resp .String ())
11871172 }
11881173
11891174 break
11901175 }
11911176
1177+ unix .Shutdown (fds [0 ], syscall .SHUT_WR )
11921178 // cmd.Wait() waits cmd.goroutines which are used for proxying file descriptors.
11931179 // Here we want to wait only the CRIU process.
11941180 st , err := cmd .Process .Wait ()
11951181 if err != nil {
11961182 return err
11971183 }
1198- if ! st .Success () {
1184+
1185+ // In pre-dump mode CRIU is in a loop and waits for
1186+ // the final DUMP command.
1187+ // The current runc pre-dump approach, however, is
1188+ // start criu in PRE_DUMP once for a single pre-dump
1189+ // and not the whole series of pre-dump, pre-dump, ...m, dump
1190+ if ! st .Success () && * req .Type != criurpc .CriuReqType_PRE_DUMP {
11991191 return fmt .Errorf ("criu failed: %s\n log file: %s" , st .String (), logPath )
12001192 }
12011193 return nil
0 commit comments