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  	var errno syscall.Errno
    25  	if errors.As(err, &errno) {
    26  		switch errno {
    27  		case syscall.EPERM, syscall.EROFS:
    28  			// User lacks permission: either the call requires root permission and the
    29  			// user is not root, or the call is denied by a container security policy.
    30  			return true
    31  		case syscall.EINVAL:
    32  			// Some containers return EINVAL instead of EPERM if a system call is
    33  			// denied by security policy.
    34  			return true
    35  		}
    36  	}
    37  
    38  	if errors.Is(err, fs.ErrPermission) || errors.Is(err, errors.ErrUnsupported) {
    39  		return true
    40  	}
    41  
    42  	return false
    43  }
    44  

View as plain text