On Tue, Jun 18, 2024 at 09:14:27AM +0200, Stefano Brivio wrote:Now that we have logging functions embedding perror() functionality, we can make _some_ calls more terse by using them. In many places, the strerror() calls are still more convenient because, for example, they are used in flow debugging functions, or because the return code variable of interest is not 'errno'. While at it, convert a few error messages from a scant perror style to proper failure descriptions. Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com> --- conf.c | 31 +++++++++++++++++-------------- fwd.c | 2 +- isolation.c | 28 +++++++++++----------------- log.c | 2 +- netlink.c | 4 ++-- passt.c | 12 ++++-------- pasta.c | 32 ++++++++++++++++---------------- pcap.c | 8 +++----- tap.c | 14 +++++++------- tcp.c | 24 ++++++++---------------- util.c | 12 +++++------- 11 files changed, 75 insertions(+), 94 deletions(-) diff --git a/conf.c b/conf.c index 344eb07..2a6f05c 100644 --- a/conf.c +++ b/conf.c @@ -461,7 +461,7 @@ static void get_dns(struct ctx *c) } if (line_len < 0) - warn("Error reading /etc/resolv.conf: %s", strerror(errno)); + warn_perror("Error reading /etc/resolv.conf"); close(fd); out: @@ -592,8 +592,8 @@ static unsigned int conf_ip4(unsigned int ifi, if (IN4_IS_ADDR_UNSPECIFIED(&ip4->gw)) { int rc = nl_route_get_def(nl_sock, ifi, AF_INET, &ip4->gw); if (rc < 0) { - err("Couldn't discover IPv4 gateway address: %s", - strerror(-rc)); + errno = -rc;I don't love this. Taking a re-entrant bit of code and making it non-reentrant by bouncing information through a global. I mean, it works in this case, but still.. -- David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson