Source file src/internal/poll/error_linux_test.go

     1  // Copyright 2019 The Go 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 poll_test
     6  
     7  import (
     8  	"errors"
     9  	"internal/poll"
    10  	"os"
    11  	"syscall"
    12  )
    13  
    14  func badStateFile() (*os.File, error) {
    15  	if os.Getuid() != 0 {
    16  		return nil, errors.New("must be root")
    17  	}
    18  	// Using OpenFile for a device file is an easy way to make a
    19  	// file attached to the runtime-integrated network poller and
    20  	// configured in halfway.
    21  	return os.OpenFile("/dev/net/tun", os.O_RDWR, 0)
    22  }
    23  
    24  func isBadStateFileError(err error) (string, bool) {
    25  	switch err {
    26  	case poll.ErrNotPollable, syscall.EBADFD:
    27  		return "", true
    28  	default:
    29  		return "not pollable or file in bad state error", false
    30  	}
    31  }
    32  

View as plain text