Source file src/internal/testenv/testenv_unix.go

     1  // Copyright 2021 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  //go:build unix
     6  
     7  package testenv
     8  
     9  import (
    10  	"errors"
    11  	"io/fs"
    12  	"syscall"
    13  )
    14  
    15  // Sigquit is the signal to send to kill a hanging subprocess.
    16  // Send SIGQUIT to get a stack trace.
    17  var Sigquit = syscall.SIGQUIT
    18  
    19  func syscallIsNotSupported(err error) bool {
    20  	if err == nil {
    21  		return false
    22  	}
    23  
    24  	if errno, ok := errors.AsType[syscall.Errno](err); ok {
    25  		switch errno {
    26  		case syscall.EPERM, syscall.EROFS:
    27  			// User lacks permission: either the call requires root permission and the
    28  			// user is not root, or the call is denied by a container security policy.
    29  			return true
    30  		case syscall.EINVAL:
    31  			// Some containers return EINVAL instead of EPERM if a system call is
    32  			// denied by security policy.
    33  			return true
    34  		}
    35  	}
    36  
    37  	if errors.Is(err, fs.ErrPermission) || errors.Is(err, errors.ErrUnsupported) {
    38  		return true
    39  	}
    40  
    41  	return false
    42  }
    43  

View as plain text