Vladimir Serbinenko | 3129f79 | 2014-10-15 21:51:47 +0200 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "io" |
| 5 | "io/ioutil" |
| 6 | "log" |
| 7 | "os" |
| 8 | "os/exec" |
| 9 | "strings" |
| 10 | ) |
| 11 | |
| 12 | func RunAndSave(output string, name string, arg ...string) { |
| 13 | cmd := exec.Command(name, arg...) |
| 14 | |
| 15 | f, err := os.Create(output) |
| 16 | if err != nil { |
| 17 | log.Fatal(err) |
| 18 | } |
| 19 | |
| 20 | cmd.Stdout = f |
| 21 | cmd.Stderr = f |
| 22 | |
| 23 | err = cmd.Start() |
| 24 | if err != nil { |
| 25 | log.Fatal(err) |
| 26 | } |
| 27 | cmd.Wait() |
| 28 | } |
| 29 | |
| 30 | func MakeLogs(outDir string) { |
| 31 | os.MkdirAll(outDir, 0700) |
| 32 | RunAndSave(outDir+"/lspci.log", "lspci", "-nnvvvxxxx") |
| 33 | RunAndSave(outDir+"/dmidecode.log", "dmidecode") |
| 34 | RunAndSave(outDir+"/acpidump.log", "acpidump") |
| 35 | /* FIXME:XX */ |
| 36 | RunAndSave(outDir+"/inteltool.log", "../inteltool/inteltool", "-a") |
| 37 | RunAndSave(outDir+"/ectool.log", "../ectool/ectool", "-a") |
| 38 | |
| 39 | SysDir := "/sys/class/sound/card0/" |
| 40 | files, _ := ioutil.ReadDir(SysDir) |
| 41 | for _, f := range files { |
| 42 | if (strings.HasPrefix(f.Name(), "hw") || strings.HasPrefix(f.Name(), "hdaudio")) && f.IsDir() { |
| 43 | in, err := os.Open(SysDir + f.Name() + "/init_pin_configs") |
| 44 | defer in.Close() |
| 45 | if err != nil { |
| 46 | log.Fatal(err) |
| 47 | } |
| 48 | out, err := os.Create(outDir + "/pin_" + strings.Replace(f.Name(), "hdaudio", "hw", -1)) |
| 49 | if err != nil { |
| 50 | log.Fatal(err) |
| 51 | } |
| 52 | defer out.Close() |
| 53 | io.Copy(out, in) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | ProcDir := "/proc/asound/card0/" |
| 58 | files, _ = ioutil.ReadDir(ProcDir) |
| 59 | for _, f := range files { |
| 60 | if strings.HasPrefix(f.Name(), "codec#") && !f.IsDir() { |
| 61 | in, err := os.Open(ProcDir + f.Name()) |
| 62 | defer in.Close() |
| 63 | if err != nil { |
| 64 | log.Fatal(err) |
| 65 | } |
| 66 | out, err := os.Create(outDir + "/" + f.Name()) |
| 67 | if err != nil { |
| 68 | log.Fatal(err) |
| 69 | } |
| 70 | defer out.Close() |
| 71 | io.Copy(out, in) |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | for _, fname := range []string{"cpuinfo", "ioports"} { |
| 76 | in, err := os.Open("/proc/" + fname) |
| 77 | defer in.Close() |
| 78 | if err != nil { |
| 79 | log.Fatal(err) |
| 80 | } |
| 81 | out, err := os.Create(outDir + "/" + fname + ".log") |
| 82 | if err != nil { |
| 83 | log.Fatal(err) |
| 84 | } |
| 85 | defer out.Close() |
| 86 | io.Copy(out, in) |
| 87 | } |
| 88 | } |