mirror of
				https://github.com/opencontainers/runc.git
				synced 2025-10-31 19:13:12 +08:00 
			
		
		
		
	 d8b5c1c810
			
		
	
	d8b5c1c810
	
	
	
		
			
			Use the symlink xattr syscall wrappers Lgetxattr, Llistxattr and Lsetxattr from x/sys/unix (introduced in golang/sys@b90f89a1e7) instead of providing own wrappers. Leave the functionality of system.Lgetxattr intact with respect to the retry with a larger buffer, but switch it to use unix.Lgetxattr. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
		
			
				
	
	
		
			36 lines
		
	
	
		
			890 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
		
			890 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package system
 | |
| 
 | |
| import "golang.org/x/sys/unix"
 | |
| 
 | |
| // Returns a []byte slice if the xattr is set and nil otherwise
 | |
| // Requires path and its attribute as arguments
 | |
| func Lgetxattr(path string, attr string) ([]byte, error) {
 | |
| 	var sz int
 | |
| 	// Start with a 128 length byte array
 | |
| 	dest := make([]byte, 128)
 | |
| 	sz, errno := unix.Lgetxattr(path, attr, dest)
 | |
| 
 | |
| 	switch {
 | |
| 	case errno == unix.ENODATA:
 | |
| 		return nil, errno
 | |
| 	case errno == unix.ENOTSUP:
 | |
| 		return nil, errno
 | |
| 	case errno == unix.ERANGE:
 | |
| 		// 128 byte array might just not be good enough,
 | |
| 		// A dummy buffer is used to get the real size
 | |
| 		// of the xattrs on disk
 | |
| 		sz, errno = unix.Lgetxattr(path, attr, []byte{})
 | |
| 		if errno != nil {
 | |
| 			return nil, errno
 | |
| 		}
 | |
| 		dest = make([]byte, sz)
 | |
| 		sz, errno = unix.Lgetxattr(path, attr, dest)
 | |
| 		if errno != nil {
 | |
| 			return nil, errno
 | |
| 		}
 | |
| 	case errno != nil:
 | |
| 		return nil, errno
 | |
| 	}
 | |
| 	return dest[:sz], nil
 | |
| }
 |