From 3ad6daa90a66d74de8a52185d7ecae04f1d69b87 Mon Sep 17 00:00:00 2001 From: Andrey Konovalov Date: Thu, 22 Jun 2017 13:21:33 +0200 Subject: report: add get maintainers function --- pkg/report/guilty.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'pkg/report') diff --git a/pkg/report/guilty.go b/pkg/report/guilty.go index 087d2f275..272f63063 100644 --- a/pkg/report/guilty.go +++ b/pkg/report/guilty.go @@ -4,8 +4,12 @@ package report import ( + "net/mail" "regexp" "strings" + "time" + + "github.com/google/syzkaller/pkg/osutil" ) var ( @@ -52,3 +56,40 @@ nextFile: } return "" } + +func getMaintainersImpl(linux, file string, blame bool) ([]string, error) { + // ./scripts/get_maintainer.pl is a Linux kernel script. + args := []string{"--no-n", "--no-rolestats"} + if blame { + args = append(args, "--git-blame") + } + args = append(args, file) + output, err := osutil.RunCmd(time.Minute, linux, "./scripts/get_maintainer.pl", args...) + if err != nil { + return nil, err + } + lines := strings.Split(string(output), "\n") + var mtrs []string + for _, line := range lines { + addr, err := mail.ParseAddress(line) + if err != nil { + continue + } + mtrs = append(mtrs, addr.Address) + } + return mtrs, nil +} + +func GetMaintainers(linux, file string) ([]string, error) { + mtrs, err := getMaintainersImpl(linux, file, false) + if err != nil { + return nil, err + } + if len(mtrs) <= 1 { + mtrs, err = getMaintainersImpl(linux, file, true) + if err != nil { + return nil, err + } + } + return mtrs, nil +} -- cgit mrf-deployment