diff --git a/msr.go b/msr.go index d1f1a55..3f949f3 100644 --- a/msr.go +++ b/msr.go @@ -27,7 +27,7 @@ func MSRPaths() ([]string, error) { } // MSRs attemps to return all available MSRs. -func MSRs(onErr func(error)) []*MSR { +func MSRs(flag int, perm os.FileMode, onErr func(error)) []*MSR { paths, err := MSRPaths() if err != nil { onErr(err) @@ -35,7 +35,7 @@ func MSRs(onErr func(error)) []*MSR { } msrs := []*MSR{} for _, path := range paths { - msr, err := NewMSR(path) + msr, err := NewMSR(path, flag, perm) if err != nil { onErr(err) continue @@ -51,8 +51,8 @@ type MSR struct { } // NewMSR returns a MSR. -func NewMSR(path string) (*MSR, error) { - f, err := os.OpenFile(path, os.O_RDWR, 0660) +func NewMSR(path string, flag int, perm os.FileMode) (*MSR, error) { + f, err := os.OpenFile(path, flag, perm) if err != nil { return nil, err } diff --git a/msr_test.go b/msr_test.go index 9e29dfe..c653e16 100644 --- a/msr_test.go +++ b/msr_test.go @@ -1,6 +1,7 @@ package perf import ( + "os" "testing" "github.com/stretchr/testify/require" @@ -15,7 +16,7 @@ func TestMSR(t *testing.T) { msrs, err := MSRPaths() require.Nil(t, err) - msr, err := NewMSR(msrs[0]) + msr, err := NewMSR(msrs[0], os.O_RDWR, 0660) require.Nil(t, err) // TODO: This may only work on certain architectures :( @@ -28,7 +29,7 @@ func TestMSR(t *testing.T) { } func TestMSRs(t *testing.T) { - MSRs(func(err error) { + MSRs(os.O_RDWR, 0660, func(err error) { require.Nil(t, err) }) }