mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-11-03 23:40:03 +00:00 
			
		
		
		
	Main upgrades: - github.com/opencontainers/runc v1.0.0-rc93 - github.com/containerd/containerd v1.4.4 - github.com/docker/docker v20.10.2 - github.com/mrunalp/fileutils v0.5.0 - github.com/opencontainers/selinux v1.8.0 - github.com/cilium/ebpf v0.2.0
		
			
				
	
	
		
			39 lines
		
	
	
		
			871 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			871 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package selinux
 | 
						|
 | 
						|
import (
 | 
						|
	"golang.org/x/sys/unix"
 | 
						|
)
 | 
						|
 | 
						|
// lgetxattr returns a []byte slice containing the value of
 | 
						|
// an extended attribute attr set for path.
 | 
						|
func lgetxattr(path, attr string) ([]byte, error) {
 | 
						|
	// Start with a 128 length byte array
 | 
						|
	dest := make([]byte, 128)
 | 
						|
	sz, errno := doLgetxattr(path, attr, dest)
 | 
						|
	for errno == unix.ERANGE {
 | 
						|
		// Buffer too small, use zero-sized buffer to get the actual size
 | 
						|
		sz, errno = doLgetxattr(path, attr, []byte{})
 | 
						|
		if errno != nil {
 | 
						|
			return nil, errno
 | 
						|
		}
 | 
						|
 | 
						|
		dest = make([]byte, sz)
 | 
						|
		sz, errno = doLgetxattr(path, attr, dest)
 | 
						|
	}
 | 
						|
	if errno != nil {
 | 
						|
		return nil, errno
 | 
						|
	}
 | 
						|
 | 
						|
	return dest[:sz], nil
 | 
						|
}
 | 
						|
 | 
						|
// doLgetxattr is a wrapper that retries on EINTR
 | 
						|
func doLgetxattr(path, attr string, dest []byte) (int, error) {
 | 
						|
	for {
 | 
						|
		sz, err := unix.Lgetxattr(path, attr, dest)
 | 
						|
		if err != unix.EINTR {
 | 
						|
			return sz, err
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 |