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

Function logCriuErrors

libcontainer/criu_linux.go:821–867  ·  view source on GitHub ↗

logCriuErrors tries to find and log errors from a criu log file. The output is similar to what "grep -n -B5 Error" does.

(dir, file string)

Source from the content-addressed store, hash-verified

819// logCriuErrors tries to find and log errors from a criu log file.
820// The output is similar to what "grep -n -B5 Error" does.
821func logCriuErrors(dir, file string) {
822 lookFor := []byte("Error") // Print the line that contains this...
823 const max = 5 + 1 // ... and a few preceding lines.
824
825 logFile := filepath.Join(dir, file)
826 f, err := os.Open(logFile)
827 if err != nil {
828 logrus.Warn(err)
829 return
830 }
831 defer f.Close()
832
833 var lines [max][]byte
834 var idx, lineNo, printedLineNo int
835 s := bufio.NewScanner(f)
836 for s.Scan() {
837 lineNo++
838 lines[idx] = s.Bytes()
839 idx = (idx + 1) % max
840 if !bytes.Contains(s.Bytes(), lookFor) {
841 continue
842 }
843 // Found an error.
844 if printedLineNo == 0 {
845 logrus.Warnf("--- Quoting %q", logFile)
846 } else if lineNo-max > printedLineNo {
847 // Mark the gap.
848 logrus.Warn("...")
849 }
850 // Print the last lines.
851 for add := range max {
852 i := (idx + add) % max
853 s := lines[i]
854 actLineNo := lineNo + add - max + 1
855 if len(s) > 0 && actLineNo > printedLineNo {
856 logrus.Warnf("%d:%s", actLineNo, s)
857 printedLineNo = actLineNo
858 }
859 }
860 }
861 if printedLineNo != 0 {
862 logrus.Warn("---") // End of "Quoting ...".
863 }
864 if err := s.Err(); err != nil {
865 logrus.Warnf("read %q: %v", logFile, err)
866 }
867}
868
869func (c *Container) criuApplyCgroups(pid int, req *criurpc.CriuReq) error {
870 // need to apply cgroups only on restore

Callers 2

CheckpointMethod · 0.85
RestoreMethod · 0.85

Calls 2

ContainsMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…