in auparse/mk_audit_exit_codes.go [103:143]
func readErrorNumbers() ([]ErrorNumber, error) {
cmd := exec.Command("gcc", "-E", "-dD", "-")
cmd.Stdin = bytes.NewBufferString(includeErrno)
out, err := cmd.Output()
if err != nil {
return nil, err
}
errorToNum := map[string]int{}
s := bufio.NewScanner(bytes.NewReader(out))
for s.Scan() {
matches := errnoDefRegex.FindStringSubmatch(s.Text())
if len(matches) != 3 {
continue
}
errno, err := strconv.Atoi(matches[2])
if err != nil {
errorToNum[matches[1]] = -1
continue
}
errorToNum[matches[1]] = errno
}
var errnos []ErrorNumber
for name, value := range errorToNum {
errnos = append(errnos, ErrorNumber{
Name: name,
Value: value,
})
}
sort.Slice(errnos, func(i, j int) bool {
if errnos[i].Value == errnos[j].Value {
return errnos[i].Name < errnos[j].Name
}
return errnos[i].Value < errnos[j].Value
})
return errnos, nil
}