github.com/ck00004/CobaltStrikeParser-Go@v1.0.14/lib/internal/poll/error_linux_test.go (about)

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