mirror of
https://github.com/lxc/incus.git
synced 2026-02-05 09:46:19 +01:00
internal/netutils: Don't needlessly use format string functions
Signed-off-by: Nathan Chase <ntc477@utexas.edu>
This commit is contained in:
committed by
Stéphane Graber
parent
403ca20bf9
commit
ba322a52a8
@@ -9,6 +9,7 @@ package netutils
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
@@ -77,7 +78,7 @@ func NetnsGetifaddrs(initPID int32, hostInterfaces []net.Interface) (map[string]
|
||||
|
||||
netnsID = C.netns_get_nsid(C.__s32(f.Fd()))
|
||||
if netnsID < 0 {
|
||||
return nil, fmt.Errorf("Failed to retrieve network namespace id")
|
||||
return nil, errors.New("Failed to retrieve network namespace id")
|
||||
}
|
||||
} else {
|
||||
netnsID = -1
|
||||
@@ -85,13 +86,13 @@ func NetnsGetifaddrs(initPID int32, hostInterfaces []net.Interface) (map[string]
|
||||
|
||||
ret := C.netns_getifaddrs(&ifaddrs, netnsID, &netnsidAware)
|
||||
if ret < 0 {
|
||||
return nil, fmt.Errorf("Failed to retrieve network interfaces and addresses")
|
||||
return nil, errors.New("Failed to retrieve network interfaces and addresses")
|
||||
}
|
||||
|
||||
defer C.netns_freeifaddrs(ifaddrs)
|
||||
|
||||
if netnsID >= 0 && !netnsidAware {
|
||||
return nil, fmt.Errorf("Netlink requests are not fully network namespace id aware")
|
||||
return nil, errors.New("Netlink requests are not fully network namespace id aware")
|
||||
}
|
||||
|
||||
// We're using the interface name as key here but we should really
|
||||
@@ -150,12 +151,12 @@ func NetnsGetifaddrs(initPID int32, hostInterfaces []net.Interface) (map[string]
|
||||
|
||||
addrPtr := C.get_addr_ptr(addr.ifa_addr)
|
||||
if addrPtr == nil {
|
||||
return nil, fmt.Errorf("Failed to retrieve valid address pointer")
|
||||
return nil, errors.New("Failed to retrieve valid address pointer")
|
||||
}
|
||||
|
||||
addressStr := C.inet_ntop(C.int(addr.ifa_addr.sa_family), addrPtr, &address[0], C.INET6_ADDRSTRLEN)
|
||||
if addressStr == nil {
|
||||
return nil, fmt.Errorf("Failed to retrieve address string")
|
||||
return nil, errors.New("Failed to retrieve address string")
|
||||
}
|
||||
|
||||
if addNetwork.Addresses == nil {
|
||||
@@ -193,7 +194,7 @@ func NetnsGetifaddrs(initPID int32, hostInterfaces []net.Interface) (map[string]
|
||||
|
||||
hwaddr := C.get_packet_address(addr.ifa_addr, &buf[0], 1024)
|
||||
if hwaddr == nil {
|
||||
return nil, fmt.Errorf("Failed to retrieve hardware address")
|
||||
return nil, errors.New("Failed to retrieve hardware address")
|
||||
}
|
||||
|
||||
addNetwork.Hwaddr = C.GoString(hwaddr)
|
||||
@@ -225,7 +226,7 @@ func AbstractUnixSendFd(sockFD int, sendFD int) error {
|
||||
skFd := C.int(sockFD)
|
||||
ret := C.lxc_abstract_unix_send_fds(skFd, &fd, C.int(1), nil, C.size_t(0))
|
||||
if ret < 0 {
|
||||
return fmt.Errorf("Failed to send file descriptor via abstract unix socket")
|
||||
return errors.New("Failed to send file descriptor via abstract unix socket")
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -239,11 +240,11 @@ func AbstractUnixReceiveFd(sockFD int, flags uint) (*os.File, error) {
|
||||
fds.flags = C.__u32(flags)
|
||||
ret := C.lxc_abstract_unix_recv_fds(skFd, &fds, nil, C.size_t(0))
|
||||
if ret < 0 {
|
||||
return nil, fmt.Errorf("Failed to receive file descriptor via abstract unix socket")
|
||||
return nil, errors.New("Failed to receive file descriptor via abstract unix socket")
|
||||
}
|
||||
|
||||
if fds.fd_count_max != fds.fd_count_ret {
|
||||
return nil, fmt.Errorf("Failed to receive file descriptor via abstract unix socket")
|
||||
return nil, errors.New("Failed to receive file descriptor via abstract unix socket")
|
||||
}
|
||||
|
||||
file := os.NewFile(uintptr(fds.fd[0]), "")
|
||||
@@ -255,7 +256,7 @@ func AbstractUnixReceiveFdData(sockFD int, numFds int, flags uint, iov unsafe.Po
|
||||
fds := C.struct_unix_fds{}
|
||||
|
||||
if numFds >= C.KERNEL_SCM_MAX_FD {
|
||||
return 0, []C.int{-C.EBADF}, fmt.Errorf("Excessive number of file descriptors requested")
|
||||
return 0, []C.int{-C.EBADF}, errors.New("Excessive number of file descriptors requested")
|
||||
}
|
||||
|
||||
fds.fd_count_max = C.__u32(numFds)
|
||||
|
||||
Reference in New Issue
Block a user