Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions pkg/snap/snap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"os/exec"
"strings"

"github.com/canonical/go-snapctl"
Expand Down Expand Up @@ -47,16 +48,16 @@ func (*snap) HardwareObservable() (bool, error) {
return true, nil
}

_, err = os.ReadDir("/sys/bus/pci/devices")
if err == nil {
// Hardware access is available also if the snap is installed without confinement.
// Verify by running lscpu from the system path (not staged in the snap)
if err := exec.Command("/usr/bin/lscpu", "-V").Run(); err != nil {
if errors.Is(err, os.ErrPermission) {
return false, nil
}
return false, fmt.Errorf("checking lscpu availability: %w", err)
} else {
return true, nil
}
Comment thread
farshidtz marked this conversation as resolved.

if errors.Is(err, os.ErrPermission) || os.IsPermission(err) {
return false, nil
}

return false, fmt.Errorf("reading /sys/bus/pci/devices: %w", err)
}

// InstallComponent installs a single snap component.
Expand All @@ -81,4 +82,3 @@ func (*snap) ServiceStatuses() (map[string]string, error) {
}
return statuses, nil
}

Loading