Add some comments and a better error message if ls-iommu returns an error

This commit is contained in:
HikariKnight 2023-04-07 14:06:06 +02:00
parent 67ff7d185f
commit 654685d1e4

View file

@ -234,27 +234,30 @@ func App() {
func GetIOMMU(args ...string) []list.Item { func GetIOMMU(args ...string) []list.Item {
var stdout, stderr bytes.Buffer var stdout, stderr bytes.Buffer
// Configure the ls-iommu command
cmd := exec.Command("utils/ls-iommu", args...) cmd := exec.Command("utils/ls-iommu", args...)
cmd.Stderr = &stderr cmd.Stderr = &stderr
cmd.Stdout = &stdout cmd.Stdout = &stdout
// Execute the command
err := cmd.Run() err := cmd.Run()
errorcheck.ErrorCheck(err)
// If ls-iommu returns an error then IOMMU is disabled
errorcheck.ErrorCheck(err, "IOMMU disabled in either UEFI/BIOS or in bootloader!")
// Read the output
items := []list.Item{} items := []list.Item{}
output, _ := io.ReadAll(&stdout) output, _ := io.ReadAll(&stdout)
// If we get an error from ls-iommu then print the error and exit // Parse the output line by line
// As the system might not have IOMMU enabled
if stderr.String() != "" {
log.Fatal(stderr.String())
}
scanner := bufio.NewScanner(strings.NewReader(string(output))) scanner := bufio.NewScanner(strings.NewReader(string(output)))
for scanner.Scan() { for scanner.Scan() {
// Get the current line and split by :
objects := strings.Split(scanner.Text(), ": ") objects := strings.Split(scanner.Text(), ": ")
// Write the objects into the list
items = append(items, item{title: objects[1], desc: objects[0]}) items = append(items, item{title: objects[1], desc: objects[0]})
} }
// Return our list of items
return items return items
} }