gitee.com/mirrors_u-root/u-root@v7.0.0+incompatible/pkg/checker/dmesg.go (about) 1 // Copyright 2017-2019 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package checker 6 7 import ( 8 "strings" 9 10 "golang.org/x/sys/unix" 11 ) 12 13 func getDmesg() (string, error) { 14 b := make([]byte, 256*1024) 15 n, err := unix.Klogctl(unix.SYSLOG_ACTION_READ_ALL, b) 16 if err != nil { 17 return "", err 18 } 19 return string(b[:n]), nil 20 } 21 22 func grep(b, pattern string) []string { 23 lines := strings.Split(b, "\n") 24 ret := make([]string, 0) 25 for _, line := range lines { 26 if strings.Contains(line, pattern) { 27 ret = append(ret, line) 28 } 29 } 30 return ret 31 }