MCPcopy
hub / github.com/opencontainers/runc / criuSwrk

Method criuSwrk

libcontainer/criu_linux.go:903–1081  ·  view source on GitHub ↗
(process *Process, req *criurpc.CriuReq, opts *CriuOpts, extraFiles []*os.File)

Source from the content-addressed store, hash-verified

901}
902
903func (c *Container) criuSwrk(process *Process, req *criurpc.CriuReq, opts *CriuOpts, extraFiles []*os.File) error {
904 fds, err := unix.Socketpair(unix.AF_LOCAL, unix.SOCK_SEQPACKET|unix.SOCK_CLOEXEC, 0)
905 if err != nil {
906 return err
907 }
908
909 criuClient := os.NewFile(uintptr(fds[0]), "criu-transport-client")
910 criuClientFileCon, err := net.FileConn(criuClient)
911 criuClient.Close()
912 if err != nil {
913 return err
914 }
915
916 criuClientCon := criuClientFileCon.(*net.UnixConn)
917 defer criuClientCon.Close()
918
919 criuServer := os.NewFile(uintptr(fds[1]), "criu-transport-server")
920 defer criuServer.Close()
921
922 if c.criuVersion != 0 {
923 // If the CRIU Version is still '0' then this is probably
924 // the initial CRIU run to detect the version. Skip it.
925 logrus.Debugf("Using CRIU %d", c.criuVersion)
926 }
927 cmd := exec.Command("criu", "swrk", "3")
928 if process != nil {
929 cmd.Stdin = process.Stdin
930 cmd.Stdout = process.Stdout
931 cmd.Stderr = process.Stderr
932 }
933 cmd.ExtraFiles = append(cmd.ExtraFiles, criuServer)
934 if extraFiles != nil {
935 cmd.ExtraFiles = append(cmd.ExtraFiles, extraFiles...)
936 }
937
938 if err := cmd.Start(); err != nil {
939 return err
940 }
941 // we close criuServer so that even if CRIU crashes or unexpectedly exits, runc will not hang.
942 criuServer.Close()
943 // cmd.Process will be replaced by a restored init.
944 criuProcess := cmd.Process
945
946 var criuProcessState *os.ProcessState
947 defer func() {
948 if criuProcessState == nil {
949 criuClientCon.Close()
950 _, err := criuProcess.Wait()
951 if err != nil {
952 logrus.Warnf("wait on criuProcess returned %v", err)
953 }
954 }
955 }()
956
957 if err := c.criuApplyCgroups(criuProcess.Pid, req); err != nil {
958 return err
959 }
960

Callers 3

checkCriuFeaturesMethod · 0.95
CheckpointMethod · 0.95
RestoreMethod · 0.95

Calls 9

criuApplyCgroupsMethod · 0.95
criuNotificationsMethod · 0.95
getPipeFdsFunction · 0.85
StartMethod · 0.80
WaitMethod · 0.80
WriteMethod · 0.80
mkPtrFunction · 0.70
CloseMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected