-
Notifications
You must be signed in to change notification settings - Fork 357
Closed
Description
From #291 it was concluded that the current parsing code is limited to kernels older than 3.8.
Problematic code is:
Lines 189 to 233 in 7a44272
| func parseCPUInfoARM(info []byte) ([]CPUInfo, error) { | |
| scanner := bufio.NewScanner(bytes.NewReader(info)) | |
| firstLine := firstNonEmptyLine(scanner) | |
| if !strings.HasPrefix(firstLine, "Processor") || !strings.Contains(firstLine, ":") { | |
| return nil, errors.New("invalid cpuinfo file: " + firstLine) | |
| } | |
| field := strings.SplitN(firstLine, ": ", 2) | |
| commonCPUInfo := CPUInfo{VendorID: field[1]} | |
| cpuinfo := []CPUInfo{} | |
| i := -1 | |
| featuresLine := "" | |
| for scanner.Scan() { | |
| line := scanner.Text() | |
| if !strings.Contains(line, ":") { | |
| continue | |
| } | |
| field := strings.SplitN(line, ": ", 2) | |
| switch strings.TrimSpace(field[0]) { | |
| case "processor": | |
| cpuinfo = append(cpuinfo, commonCPUInfo) // start of the next processor | |
| i++ | |
| v, err := strconv.ParseUint(field[1], 0, 32) | |
| if err != nil { | |
| return nil, err | |
| } | |
| cpuinfo[i].Processor = uint(v) | |
| case "BogoMIPS": | |
| v, err := strconv.ParseFloat(field[1], 64) | |
| if err != nil { | |
| return nil, err | |
| } | |
| cpuinfo[i].BogoMips = v | |
| case "Features": | |
| featuresLine = line | |
| } | |
| } | |
| fields := strings.SplitN(featuresLine, ": ", 2) | |
| for i := range cpuinfo { | |
| cpuinfo[i].Flags = strings.Fields(fields[1]) | |
| } | |
| return cpuinfo, nil | |
| } |
This code should be changed to either drop support for older kernels, or be capable of parsing both new and old kernels alike - probably with reduced functionality for the older ones.