Provide better message when memfd_create fails with ENOSYS

Updates #100

PiperOrigin-RevId: 213414821
Change-Id: I90c2e6c18c54a6afcd7ad6f409f670aa31577d37
This commit is contained in:
Fabricio Voznika
2018-09-18 02:09:28 -07:00
committed by Shentubot
parent 5d9816be41
commit da20559137
2 changed files with 6 additions and 0 deletions
+3
View File
@@ -233,6 +233,9 @@ func newFromFile(file *os.File) (*FileMem, error) {
func New(name string) (*FileMem, error) {
fd, err := memutil.CreateMemFD(name, 0)
if err != nil {
if e, ok := err.(syscall.Errno); ok && e == syscall.ENOSYS {
return nil, fmt.Errorf("memfd_create(2) is not implemented. Check that you have Linux 3.17 or higher")
}
return nil, err
}
return newFromFile(os.NewFile(uintptr(fd), name))
+3
View File
@@ -122,6 +122,9 @@ func Init() error {
const name = "memory-usage"
fd, err := memutil.CreateMemFD(name, 0)
if err != nil {
if e, ok := err.(syscall.Errno); ok && e == syscall.ENOSYS {
return fmt.Errorf("memfd_create(2) is not implemented. Check that you have Linux 3.17 or higher")
}
return fmt.Errorf("error creating usage file: %v", err)
}
file := os.NewFile(uintptr(fd), name)